|
| 1 | +module DuplicatesSpec where |
| 2 | + |
| 3 | +import Duplicates (countDuplicates) |
| 4 | +import Test.HUnit |
| 5 | +import Test.Hspec |
| 6 | + |
| 7 | +spec :: Spec |
| 8 | +spec = do |
| 9 | + describe "Fixed Tests" $ do |
| 10 | + it "Returns 0 if there are no duplicates" $ do |
| 11 | + runTest |
| 12 | + ["John", "Beth", "Beth", "Bill"] |
| 13 | + [37, 23, 30, 46] |
| 14 | + [183, 170, 165, 175] |
| 15 | + 0 |
| 16 | + it "Counts duplicates of one entry" $ do |
| 17 | + runTest |
| 18 | + ["John", "Beth", "Beth", "Beth", "Bill"] |
| 19 | + [37, 23, 23, 23, 46] |
| 20 | + [183, 170, 170, 170, 175] |
| 21 | + 2 |
| 22 | + it "Counts duplicates from multiple entries" $ do |
| 23 | + runTest |
| 24 | + ["Jack", "Ben", "Jack", "Ben", "Jack", "Jack"] |
| 25 | + [25, 25, 34, 25, 25, 34] |
| 26 | + [180, 180, 200, 180, 180, 200] |
| 27 | + 3 |
| 28 | + |
| 29 | +runTest :: [String] -> [Int] -> [Int] -> Int -> Expectation |
| 30 | +runTest name age height expected = assertEqual msg expected actual |
| 31 | + where |
| 32 | + actual = countDuplicates name age height |
| 33 | + msg = "Test Failed\n " ++ showInput (name, age, height) |
| 34 | + |
| 35 | +showInput :: ([String], [Int], [Int]) -> String |
| 36 | +showInput (n, a, h) = unwords ["countDuplicates", show n, show a, show h] |
0 commit comments