Skip to content

Commit 2d91d3d

Browse files
committed
Fix failed unit tests
1 parent 01ffab0 commit 2d91d3d

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

chapter3/exercise3-69.rkt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,33 @@
1616
(define (square x)
1717
(* x x))
1818

19-
(define (pythagorean)
19+
(define (pythagorean triple-stream)
2020
(stream-filter (lambda (triple)
2121
(= (+ (square (car triple))
2222
(square (cadr triple)))
2323
(square (caddr triple))))
24-
(triples integers integers integers)))
24+
triple-stream))
2525
(module+ test
2626
(require rackunit)
2727

2828
(test-case "Test for triples"
2929
(define s1 (list-to-stream '(1 2 3)))
3030
(define s2 (list-to-stream '(1 2 3)))
3131
(define s3 (list-to-stream '(1 2 3)))
32-
(check-equal? (stream-to-list (triples s1 s2 s3) 10) '((1 1 1) (1 1 2) (2 2 2) (1 2 2) (2 2 3)))
33-
)
34-
(test-case "Test for pythagorean"
35-
(check-equal? (stream-to-list (pythagorean) 2) '((3 4 5) (6 8 10)))
36-
)
37-
)
32+
(check-equal? (stream-to-list (triples s1 s2 s3) 20) '((1 1 1)
33+
(1 1 2)
34+
(2 2 2)
35+
(1 2 2)
36+
(2 2 3)
37+
(1 1 3)
38+
(3 3 3)
39+
(1 2 3)
40+
(2 3 3)
41+
(1 3 3)))
42+
(test-case "Test for pythagorean"
43+
(define s1 (stream-enumerate-interval 1 10))
44+
(define s2 (stream-enumerate-interval 1 10))
45+
(define s3 (stream-enumerate-interval 1 10))
46+
(check-equal? (stream-to-list (pythagorean (triples s1 s2 s3)) 2) '((3 4 5) (6 8 10)))
47+
)
48+
))

chapter3/infinite-stream.rkt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@
3232
(define (interleave s1 s2)
3333
(if (stream-null? s1)
3434
s2
35-
(if (stream-null? s2)
36-
the-empty-stream
37-
(cons-stream (stream-car s1)
38-
(interleave s2 (stream-cdr s1))))))
35+
(cons-stream (stream-car s1)
36+
(interleave s2 (stream-cdr s1)))))
3937

4038
(define (pairs s t)
4139
(if (or (stream-null? s) (stream-null? t))

0 commit comments

Comments
 (0)