File tree Expand file tree Collapse file tree 3 files changed +35
-12
lines changed Expand file tree Collapse file tree 3 files changed +35
-12
lines changed Original file line number Diff line number Diff line change
1
+ module Frequencies where
2
+
3
+ import qualified TestData
4
+
5
+ sumInt :: Int -> Int -> Int
6
+ sumInt a b = a + b
7
+
8
+ calculateFrequency :: [Int ] -> Int
9
+ calculateFrequency frequencies = foldl sumInt 0 frequencies
10
+
11
+ main = do
12
+ print $ calculateFrequency TestData. testData
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ module Test where
2
+
3
+ import qualified Frequencies
4
+ import Test.Hspec
5
+ import Test.QuickCheck
6
+
7
+ genPos :: Gen Int
8
+ genPos = abs `fmap` (arbitrary :: Gen Int ) `suchThat` (> 0 )
9
+
10
+ genListOfPos :: Gen [Int ]
11
+ genListOfPos = listOf genPos
12
+
13
+ runTests :: IO ()
14
+ runTests =
15
+ hspec $ do
16
+ describe " Day 1 of Advent of code" $ do
17
+ it " should get the sum of a list of Int" $ do
18
+ Frequencies. calculateFrequency [0 , 1 , 2 ] `shouldBe` 3
19
+
20
+ runPropTests :: IO ()
21
+ runPropTests = do
22
+ quickCheck $
23
+ forAll genListOfPos $ \ pos -> Frequencies. calculateFrequency pos >= 0
You can’t perform that action at this time.
0 commit comments