-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw2tests.lsp
63 lines (53 loc) · 3.38 KB
/
hw2tests.lsp
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
; Test cases for hw2
(assert (equal (bfs 'A) '(A))) ; Single element case
(assert (equal (bfs '((A (B)) C (D))) '(C A D B)))
(assert (equal (bfs '((W X) (Y Z))) '(W X Y Z)))
(assert (equal (bfs '(A (B C) (D) (E (F G)))) '(A B C D E F G)))
(assert (equal (bfs '(A ((B) C) (D) (E ((F) G)))) '(A C D E B G F)))
(print "All test cases passed for BFS")
(assert (equal (dfs 'A) '(A))) ; Single element case
(assert (equal (dfs '((A (B)) C (D))) '(A B C D)))
(assert (equal (dfs '((W X) (Y Z))) '(W X Y Z)))
(assert (equal (dfs '(A (B C) (D) (E (F G)))) '(A B C D E F G)))
(print "All test cases passed for DFS")
(assert (equal (dfid 'A 0) '(A))) ; Single element case
(assert (equal (dfid '(A) 1) '(A))) ; Single element case
(assert (equal (dfid '((A (B)) C (D)) 3) '(C D C A D C B A)))
(assert (equal (dfid '((W X) (Y Z)) 2) '(Z Y X W)))
(assert (equal (dfid '(A (B C) (D) (E (F G))) 2) '(A E D C B A)))
(assert (equal (dfid '(A (B C) (D) (E (F G))) 3) '(A E D C B A G F E D C B A)))
(print "All test cases passed for DFID")
(assert (equal (final-state '(3 3 T)) NIL))
(assert (equal (final-state '(3 3 NIL)) T))
(assert (equal (final-state '(2 3 NIL)) NIL))
(assert (equal (final-state '(0 1 T)) NIL))
(print "All test cases passed for final-state")
(assert (equal (next-state '(3 3 T) 1 0) NIL)) ; Can't have more O's than X's on one side
(assert (equal (next-state '(2 1 T) 2 0) '((3 2 NIL)))) ; Can have all O's on one side
(assert (equal (next-state '(1 1 NIL) 2 0) NIL)) ; Can't move more X's than there are
(assert (equal (next-state '(3 0 NIL) 2 0) NIL)) ; Can't move into an invalid state (more O's on the other side than X's)
(assert (equal (next-state '(2 2 NIL) 1 1) '((2 2 T)))) ; Valid cases
(assert (equal (next-state '(3 3 T) 0 1) '((0 1 NIL))))
(print "All test cases passed for next-state")
(assert (equal (succ-fn '(3 3 T)) '((0 1 NIL) (1 1 NIL) (0 2 NIL))))
(assert (equal (succ-fn '(3 1 NIL)) '((0 3 T) (2 2 T))))
(assert (equal (succ-fn '(2 2 NIL)) '((2 2 T) (3 1 T))))
(assert (equal (succ-fn '(0 1 T)) '((3 3 NIL))))
(assert (equal (succ-fn '(3 3 t)) '((0 1 NIL) (1 1 NIL) (0 2 NIL))))
(assert (equal (succ-fn '(1 1 t)) '((3 2 NIL) (3 3 NIL))))
(print "All test cases passed for succ-fn")
(assert (equal (on-path '(1 1 T) NIL) NIL))
(assert (equal (on-path '(2 1 NIL) '((3 3 T) (2 1 NIL) (0 1 T))) T))
(assert (equal (on-path '(2 1 NIL) '((3 2 NIL) (2 2 T) (1 0 NIL))) NIL))
(print "All test cases passed for on-path")
(assert (equal (mult-dfs NIL NIL) NIL)) ; No successor states
(assert (equal (mult-dfs '((3 3 NIL)) NIL) '((3 3 NIL)))) ; Final state correct
(assert (equal (mult-dfs '((1 1 T)) '((3 2 NIL))) '((3 3 NIL) (1 1 T) (3 2 NIL)))) ; Valid solution
(print "All test cases passed for mult-dfs")
(assert (equal (mc-dfs '(3 3 T) NIL) '((3 3 NIL) (1 1 T) (3 2 NIL) (0 3 T) (3 1 NIL) (2 2 T) (2 2 NIL) (3 1 T) (0 3 NIL) (3 2 T) (1 1 NIL) (3 3 T)))) ; Just one valid solution, depending on the order of succ-fn
(assert (equal (mc-dfs '(3 3 NIL) NIL) '((3 3 NIL)))) ; Start at final state
(assert (equal (mc-dfs '(0 3 NIL) NIL) '((3 3 NIL) (1 1 T) (3 2 NIL) (0 3 T) (3 1 NIL) (2 2 T) (2 2 NIL) (3 1 T) (0 3 NIL))))
(assert (equal (mc-dfs '(3 0 NIL) NIL) NIL)) ; Impossible state
(assert (equal (mc-dfs '(0 3 NIL) '((3 2 T) (0 2 NIL) (3 3 T))) '((3 3 NIL) (1 1 T) (3 2 NIL) (0 3 T) (3 1 NIL) (2 2 T) (2 2 NIL) (3 1 T) (0 3 NIL) (3 2 T) (0 2 NIL) (3 3 T))))
(print "All test cases passed for mc-dfs")
(print "ALL TEST CASES PASSED")