|
| 1 | +{-# OPTIONS_GHC -fno-warn-type-defaults #-} |
| 2 | + |
| 3 | +import Test.Hspec (Spec, describe, it, shouldBe) |
| 4 | +import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith) |
| 5 | + |
| 6 | +import Squares (difference, squareOfSum, sumOfSquares) |
| 7 | + |
| 8 | +main :: IO () |
| 9 | +main = hspecWith defaultConfig {configFastFail = True} specs |
| 10 | + |
| 11 | +specs :: Spec |
| 12 | +specs = do |
| 13 | + |
| 14 | + describe "squareOfSum" $ do |
| 15 | + it "square of sum 1" $ squareOfSum 1 `shouldBe` 1 |
| 16 | + it "square of sum 5" $ squareOfSum 5 `shouldBe` 225 |
| 17 | + it "square of sum 100" $ squareOfSum 100 `shouldBe` 25502500 |
| 18 | + |
| 19 | + describe "sumOfSquares" $ do |
| 20 | + it "sum of squares 1" $ sumOfSquares 1 `shouldBe` 1 |
| 21 | + it "sum of squares 5" $ sumOfSquares 5 `shouldBe` 55 |
| 22 | + it "sum of squares 100" $ sumOfSquares 100 `shouldBe` 338350 |
| 23 | + |
| 24 | + describe "differenceOfSquares" $ do |
| 25 | + it "difference of squares 1" $ difference 1 `shouldBe` 0 |
| 26 | + it "difference of squares 5" $ difference 5 `shouldBe` 170 |
| 27 | + it "difference of squares 100" $ difference 100 `shouldBe` 25164150 |
| 28 | + |
| 29 | + -- Track-specific tests. |
| 30 | + |
| 31 | + describe "Integral tests" $ do |
| 32 | + |
| 33 | + describe "squareOfSum" $ do |
| 34 | + |
| 35 | + it "squareOfSum (6 :: Int)" $ |
| 36 | + squareOfSum (6 :: Int) |
| 37 | + `shouldBe` (441 :: Int) |
| 38 | + |
| 39 | + it "squareOfSum (7 :: Integer)" $ |
| 40 | + squareOfSum (7 :: Integer) |
| 41 | + `shouldBe` (784 :: Integer) |
| 42 | + |
| 43 | + describe "sumOfSquares" $ do |
| 44 | + |
| 45 | + it "sumOfSquares (8 :: Int)" $ |
| 46 | + sumOfSquares (8 :: Int) |
| 47 | + `shouldBe` (204 :: Int) |
| 48 | + |
| 49 | + it "sumOfSquares (9 :: Integer)" $ |
| 50 | + sumOfSquares (9 :: Integer) |
| 51 | + `shouldBe` (285 :: Integer) |
| 52 | + |
| 53 | + describe "difference" $ do |
| 54 | + |
| 55 | + it "difference (11 :: Int)" $ |
| 56 | + difference (11 :: Int) |
| 57 | + `shouldBe` (3850 :: Int) |
| 58 | + |
| 59 | + it "difference (12 :: Integer)" $ |
| 60 | + difference (12 :: Integer) |
| 61 | + `shouldBe` (5434 :: Integer) |
| 62 | + |
| 63 | + {- |
| 64 | + describe "huge difference" $ |
| 65 | + it "difference (1234567890 :: Integer)" $ |
| 66 | + difference (1234567890 :: Integer) |
| 67 | + `shouldBe` (580764307309260838625720836817589660 :: Integer) |
| 68 | + -} |
0 commit comments