File tree 3 files changed +42
-0
lines changed
3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ module DuckDuckGoose (duckDuckGoose , Player (.. )) where
2
+
3
+ import Preloaded (Player (name ))
4
+
5
+ -- https://www.codewars.com/kata/582e0e592029ea10530009ce/train/haskell
6
+
7
+ duckDuckGoose :: [Player ] -> Int -> String
8
+ duckDuckGoose players goose = name . (!! index) $ players
9
+ where
10
+ count = length players
11
+ index = (`mod` count) . subtract 1 $ goose
Original file line number Diff line number Diff line change @@ -39,3 +39,5 @@ data Circle = Circle
39
39
{ center :: Point
40
40
, radius :: Double
41
41
} deriving (Show , Eq )
42
+
43
+ newtype Player = Player { name :: String } deriving (Show , Eq )
Original file line number Diff line number Diff line change
1
+ module DuckDuckGooseSpec where
2
+
3
+ import Test.Hspec
4
+ import Test.HUnit
5
+ import DuckDuckGoose (duckDuckGoose )
6
+ import Preloaded
7
+
8
+ spec :: Spec
9
+ spec = do
10
+ describe " Fixed Tests" $ do
11
+ it " should find the correct goose" $ do
12
+ let players = Player . (: " " ) <$> " abcdcefghz"
13
+ runTest players 1 " a"
14
+ runTest players 3 " c"
15
+ runTest players 10 " z"
16
+ runTest players 20 " z"
17
+ runTest players 30 " z"
18
+ runTest players 18 " g"
19
+ runTest players 28 " g"
20
+ runTest players 12 " b"
21
+ runTest players 2 " b"
22
+ runTest players 7 " f"
23
+
24
+ runTest :: [Player ] -> Int -> String -> Expectation
25
+ runTest players goose expected =
26
+ assertEqual (showInput players goose) expected $ duckDuckGoose players goose
27
+
28
+ showInput :: [Player ] -> Int -> String
29
+ showInput players goose = unwords [" duckDuckGoose" , show players, show goose]
You can’t perform that action at this time.
0 commit comments