Skip to content

Commit 4a6abfc

Browse files
committed
Solve 'Will there be enough space?' kata
1 parent f36a524 commit 4a6abfc

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Bus.hs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Bus (enough) where
2+
3+
-- https://www.codewars.com/kata/5875b200d520904a04000003/train/haskell
4+
5+
enough :: Int -> Int -> Int -> Int
6+
enough cap on wait
7+
| diff < 0 = abs diff
8+
| otherwise = 0
9+
where
10+
diff = cap - on - wait

test/BusSpec.hs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module BusSpec where
2+
3+
import Test.Hspec
4+
import Bus (enough)
5+
6+
spec :: Spec
7+
spec = do
8+
describe "Fixed Tests" $ do
9+
mapM_ (\(c@(Case cap on wait), ans) -> it (show c) $ enough cap on wait `shouldBe` ans)
10+
[ (Case 10 5 5, 0)
11+
, (Case 100 60 50, 10)
12+
, (Case 20 5 5, 0)
13+
]
14+
15+
data Case = Case Int Int Int
16+
17+
instance Show Case where
18+
show (Case cap on wait) =
19+
"cap: " ++ show cap ++ ", " ++
20+
"on: " ++ show on ++ ", " ++
21+
"wait: " ++ show wait

0 commit comments

Comments
 (0)