This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.42.test.scm
58 lines (53 loc) · 1.88 KB
/
2.42.test.scm
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
(use-modules (srfi srfi-64))
(load "2.42.scm")
(test-begin "adjoin-position")
(test-equal '(1) (adjoin-position 1 1 '()))
(test-equal '(1 2) (adjoin-position 2 2 '(1)))
(test-equal '(1 2 3) (adjoin-position 3 3 '(1 2)))
(test-end "adjoin-position")
(test-begin "index")
(define test-list (enumerate-interval 1 10))
(define (test-at i) (test-equal i (index i test-list)))
(map test-at test-list)
(test-end "index")
;(test-begin "safe?")
(let* ((safe-board '(2 4 6 8 3 1 7 5))
(all-indexes (enumerate-interval 1 8))
(horizontally-unsafe-board '(1 1 1 1 1 1 1 1))
(descending-diagonally-unsafe-board all-indexes)
(ascending-diagonally-unsafe-board (reverse all-indexes))
(test-safe-board (lambda (index)
(test-assert (safe? index safe-board))
)
)
(test-hor-board (lambda (index)
(test-expect-fail 1)
(test-assert (safe? index horizontally-unsafe-board))
)
)
(test-diag-board (lambda (index)
(test-expect-fail 2)
(test-assert (safe? index
descending-diagonally-unsafe-board
)
)
(test-assert (safe? index
ascending-diagonally-unsafe-board
)
)
)
)
)
(map test-safe-board all-indexes)
(map test-hor-board all-indexes)
(map test-diag-board all-indexes)
)
;(test-end "safe?")
(test-begin "queens")
(test-equal '((2 4 1 3) (3 1 4 2)) (queens 4))
(test-equal '((1 3 5 2 4) (4 2 5 3 1) (3 5 2 4 1) (5 2 4 1 3)
(2 5 3 1 4)
)
(queens 5)
)
(test-end "queens")