-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReloadCountdown.hs
63 lines (43 loc) · 1.39 KB
/
ReloadCountdown.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
module Main where
import Test.HUnit
stoppedIsTrueAtInitialState =
True ~?= stopped (startCountdown 0)
startCountdown seconds = seconds
decrease seconds amount
| amount > seconds = 0
| otherwise = remaining
where
remaining = seconds - amount
stopped seconds
| seconds == 0 = True
| otherwise = False
gun seconds
| seconds == 0 = "loaded"
| otherwise = "unloaded"
canFire gun
| gun == "loaded" = True
| otherwise = False
fire gun = "unloaded"
makeNewGun = gun (startCountdown 0)
stoppedIsFalseIfTheCountdownHasBeenStarted =
False ~?= stopped (startCountdown 10)
stoppedIsFalseIfTheCountdownHasBeenInitializeBy10AndDecreasedBy5 =
False ~?= stopped (decrease (startCountdown 10) 5)
stoppedIsTrueIfTheCountdownHasBeenInitializeBy5AndDecreasedBy6 =
True ~?= stopped (decrease (startCountdown 5) 6)
weCanFireIfWeGotAGun =
True ~?= canFire makeNewGun
weCantFireIfTheGunIsLoaded =
False ~?= canFire (fire makeNewGun)
weCantFireIfTheGunIsLoading =
False ~?= canFire (gun ( decrease (startCountdown 10) 5))
tests = TestList [
stoppedIsTrueAtInitialState,
stoppedIsFalseIfTheCountdownHasBeenStarted,
stoppedIsFalseIfTheCountdownHasBeenInitializeBy10AndDecreasedBy5,
stoppedIsTrueIfTheCountdownHasBeenInitializeBy5AndDecreasedBy6,
weCanFireIfWeGotAGun,
weCantFireIfTheGunIsLoaded,
weCantFireIfTheGunIsLoading
]
main = runTestTT tests