Skip to content

Commit

Permalink
Solve 'Will you make it?' kata
Browse files Browse the repository at this point in the history
  • Loading branch information
borisskert committed Oct 3, 2024
1 parent 747652d commit 8df5d6c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Trip.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Trip (zeroFuel) where

-- https://www.codewars.com/kata/5861d28f124b35723e00005e/train/haskell

zeroFuel :: Int -> Int -> Int -> Bool
zeroFuel distanceToPump mpg fuelLeft = distanceToPump `div` fuelLeft <= mpg
17 changes: 17 additions & 0 deletions test/TripSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module TripSpec where

import Test.Hspec
import Test.HUnit (assertBool)
import Trip (zeroFuel)

spec :: Spec
spec = do
describe "Fixed Tests" $ do
it "zeroFuel 50 25 2" $ do
assertBool "2 gallons is enough fuel to drive 50 miles at 25 miles per gallon" $ zeroFuel 50 25 2
it "zeroFuel 60 30 3" $ do
assertBool "3 gallons is enough fuel to drive 60 miles at 30 miles per gallon" $ zeroFuel 60 30 3
it "zeroFuel 70 25 1" $ do
assertBool "1 gallon is not enough fuel to drive 70 miles at 25 miles per gallon" $ not $ zeroFuel 70 25 1
it "zeroFuel 100 25 3" $ do
assertBool "3 gallons is not enough fuel to drive 100 miles at 25 miles per gallon" $ not $ zeroFuel 100 25 3

0 comments on commit 8df5d6c

Please sign in to comment.