From a9702991100ef8fc485ec47aed3d854c45e19dac Mon Sep 17 00:00:00 2001 From: Jaro Date: Tue, 6 Jun 2023 10:25:19 +0200 Subject: [PATCH] Test unions of lists of rectangles. --- test/Data/Text/ParagraphLayout/RectSpec.hs | 78 +++++++++++++++++++--- 1 file changed, 70 insertions(+), 8 deletions(-) diff --git a/test/Data/Text/ParagraphLayout/RectSpec.hs b/test/Data/Text/ParagraphLayout/RectSpec.hs index 012b854..e5236e2 100644 --- a/test/Data/Text/ParagraphLayout/RectSpec.hs +++ b/test/Data/Text/ParagraphLayout/RectSpec.hs @@ -1,6 +1,7 @@ module Data.Text.ParagraphLayout.RectSpec (spec) where import Data.Int (Int32) +import Data.List.NonEmpty (NonEmpty ((:|))) import Test.Hspec import Data.Text.ParagraphLayout.Internal.Rect @@ -13,14 +14,75 @@ negativeRect = Rect 80 (-75) (-15) (-15) spec :: Spec spec = do - describe "union of two rects (low X, low Y)" $ - llSpec $ union LL positiveRect negativeRect - describe "union of two rects (low X, high Y)" $ - lhSpec $ union LH positiveRect negativeRect - describe "union of two rects (high X, low Y)" $ - hlSpec $ union HL positiveRect negativeRect - describe "union of two rects (high X, high Y)" $ - hhSpec $ union HH positiveRect negativeRect + + describe "union of two rects" $ do + + describe "low X, low Y" $ + llSpec $ union LL positiveRect negativeRect + + describe "low X, high Y" $ + lhSpec $ union LH positiveRect negativeRect + + describe "high X, low Y" $ + hlSpec $ union HL positiveRect negativeRect + + describe "high X, high Y" $ + hhSpec $ union HH positiveRect negativeRect + + describe "union of list" $ do + + describe "when empty" $ + it "should be Nothing" $ do + unionMany LL [] + `shouldBe` (Nothing :: Maybe (Rect Int32)) + + describe "with single item" $ do + + describe "matching LL origin" $ + it "should be identity" $ + unionMany LL [positiveRect] + `shouldBe` Just positiveRect + + describe "matching HH origin" $ + it "should be identity" $ + unionMany HH [negativeRect] + `shouldBe` Just negativeRect + + describe "with single item repeated" $ do + + describe "matching LL origin" $ + it "should be equal to item" $ + unionMany LL (replicate 2 positiveRect) + `shouldBe` Just positiveRect + + describe "matching HH origin" $ + it "should be equal to item" $ + unionMany HH (replicate 7 negativeRect) + `shouldBe` Just negativeRect + + describe "with two items" $ + it "should behave the same as binary function" $ + unionMany LL [positiveRect, negativeRect] + `shouldBe` Just (union LL positiveRect negativeRect) + + describe "union of non-empty list" $ do + + describe "with single item" $ do + + describe "matching LL origin" $ + it "should be identity" $ + unionMany1 LL (positiveRect :| []) + `shouldBe` positiveRect + + describe "matching HH origin" $ + it "should be identity" $ + unionMany1 HH (negativeRect :| []) + `shouldBe` negativeRect + + describe "with two items" $ + it "should behave the same as binary function" $ + unionMany1 LL (positiveRect :| [negativeRect]) + `shouldBe` union LL positiveRect negativeRect llSpec :: Rect Int32 -> SpecWith () llSpec r = do -- 2.30.2