-
Notifications
You must be signed in to change notification settings - Fork 0
/
KarelTests.hs
122 lines (110 loc) · 3.62 KB
/
KarelTests.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
-- | A module that contains several doctests for testing your interpreter.
-- Note that if you want the tests to pass, you'll need to reverse engineer
-- the error messages.
--
-- If you add your own tests, make sure to do that in the HW5 file, since you
-- will not submit this file.
module KarelTests where
import Prelude hiding (Either(..))
import KarelSyntax
import KarelState
import KarelSemantics
import KarelExamples
-- | Basic tests for move, turn, pick, and put.
--
-- >>> prog ([],Move) emptyWorld (originBot 0)
-- OK: ((0,1),North,0)
--
-- >>> prog ([],Block [Turn Right,Move]) emptyWorld (originBot 0)
-- OK: ((1,0),East,0)
--
-- >>> prog ([],Block [PutBeeper,PutBeeper]) emptyWorld (originBot 5)
-- OK: ((0,0),North,3)
--
-- >>> prog ([],Block [PutBeeper,PickBeeper]) emptyWorld (originBot 5)
-- OK: ((0,0),North,5)
--
-- >>> prog ([],Block [PutBeeper,Move,Turn Back,Move,PickBeeper]) emptyWorld (originBot 5)
-- OK: ((0,0),South,5)
--
-- >>> prog ([],Move) wallWorld (originBot 0)
-- Error: Blocked at: (0,1)
--
-- >>> prog ([],Block [PutBeeper,PutBeeper]) emptyWorld (originBot 1)
-- Error: No beeper to put.
--
-- >>> prog ([],PickBeeper) emptyWorld (originBot 5)
-- Error: No beeper to pick at: (0,0)
--
-- >>> prog ([],Block [PutBeeper,Move,PickBeeper]) emptyWorld (originBot 5)
-- Error: No beeper to pick at: (0,1)
-- | Conditional tests.
--
-- >>> prog ([],If Beeper (Turn Left) (Turn Right)) emptyWorld (originBot 0)
-- OK: ((0,0),East,0)
--
-- >>> prog ([],If (Not Beeper) (Turn Left) (Turn Right)) emptyWorld (originBot 0)
-- OK: ((0,0),West,0)
--
-- >>> prog ([],Block [PutBeeper,If Beeper (Turn Left) (Turn Right)]) emptyWorld (originBot 3)
-- OK: ((0,0),West,2)
--
-- >>> prog ([],Block [PutBeeper,PickBeeper,If Beeper (Turn Left) (Turn Right)]) emptyWorld (originBot 3)
-- OK: ((0,0),East,3)
--
-- >>> prog ([],If (Facing North) (Turn Left) (Turn Right)) emptyWorld (originBot 0)
-- OK: ((0,0),West,0)
--
-- >>> prog ([],If (Facing South) (Turn Left) (Turn Right)) emptyWorld (originBot 0)
-- OK: ((0,0),East,0)
--
-- >>> prog ([],If (Not Empty) PutBeeper Move) emptyWorld (originBot 3)
-- OK: ((0,0),North,2)
--
-- >>> prog ([],If (Not Empty) PutBeeper Move) emptyWorld (originBot 0)
-- OK: ((0,1),North,0)
--
-- >>> prog ([],If (Clear Front) Move Shutdown) emptyWorld (originBot 0)
-- OK: ((0,1),North,0)
--
-- >>> prog ([],If (Clear Front) Move Shutdown) wallWorld (originBot 0)
-- Done: ((0,0),North,0)
-- | Test macros.
--
-- >>> prog ([("A",Turn Right),("B",Turn Left)],Call "A") emptyWorld (originBot 0)
-- OK: ((0,0),East,0)
--
-- >>> prog ([("A",Turn Right),("B",Turn Left)],Call "B") emptyWorld (originBot 0)
-- OK: ((0,0),West,0)
--
-- >>> prog ([("A",Turn Right),("B",Turn Left)],Call "C") emptyWorld (originBot 0)
-- Error: Undefined macro: C
-- | Test looping constructs.
--
-- >>> prog ([],Iterate 8 Move) demoWorld demoBot
-- OK: ((9,1),East,1)
--
-- >>> prog ([],Iterate 9 Move) demoWorld demoBot
-- Error: Blocked at: (10,1)
--
-- >>> prog ([],While (Clear Front) Move) demoWorld demoBot
-- OK: ((9,1),East,1)
--
-- >>> prog ([],Block [Iterate 7 Move, While Beeper PickBeeper]) demoWorld demoBot
-- OK: ((8,1),East,5)
-- | Larger tests.
--
-- >>> prog (fetcher 4) demoWorld demoBot
-- Done: ((1,1),East,5)
--
-- >>> prog (fetcher 9) demoWorld demoBot
-- Done: ((1,1),East,10)
--
-- >>> prog (fetcher 10) demoWorld demoBot
-- Done: ((9,1),East,9)
--
-- >>> prog ([],rectangle 8 3) demoWorld demoBot
-- OK: ((1,1),North,1)
--
-- >>> prog ([],rectangle 3 8) demoWorld demoBot
-- Error: Blocked at: (1,5)