Skip to content

Commit 0952998

Browse files
committed
Add unittest for exercise2-17 and 2-20
1 parent 33dff50 commit 0952998

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

chapter2/exercise2-17.scm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
(define (last-pair items)
1818
(list-ref items (- (length items) 1)))
1919

20-
;;;
20+
(module+ test
21+
(require rackunit)
22+
(require rackunit/text-ui)
2123

22-
(last-pair (list 23 72 149 34)); => 34
24+
(define list-ref-tests
25+
(test-suite
26+
"Tests for list-ref"
27+
(check-equal? (last-pair (list 23 72 149 34)) 34)))
28+
29+
(run-tests list-ref-tests))

chapter2/exercise2-20.scm

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,25 @@
1111
(define (same-parity x . y)
1212
(define (filter-same-parity a items)
1313
(if (null? items)
14-
(list a)
15-
(if (same-parity? a (car items))
16-
(append (list a) (filter-same-parity (car items) (cdr items)))
17-
(filter-same-parity a (cdr items)))))
14+
(list a)
15+
(if (same-parity? a (car items))
16+
(append (list a) (filter-same-parity (car items) (cdr items)))
17+
(filter-same-parity a (cdr items)))))
1818

1919
(if (null? y)
2020
(filter-same-parity x (list))
2121
(filter-same-parity x y))
2222
)
2323

24-
;;;
25-
(same-parity 1 2 3 4 5 6 7); => (1 3 5 7)
26-
(same-parity 2 3 4 5 6 7); => (2 4 6)
24+
(module+ test
25+
(require rackunit)
26+
(require rackunit/text-ui)
27+
28+
(define module-test
29+
(test-suite
30+
"Tests for same-parity"
31+
(check-equal? (same-parity 1 2 3 4 5 6 7) '(1 3 5 7))
32+
(check-equal? (same-parity 2 3 4 5 6 7) '(2 4 6))
33+
))
34+
35+
(run-tests module-test))

0 commit comments

Comments
 (0)