-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2_29.test.rkt
37 lines (28 loc) · 1.18 KB
/
2_29.test.rkt
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
#lang racket
(require rackunit/text-ui)
(require rackunit "custom-checks.rkt")
(require rackunit "../solutions/2_29.rkt")
(define tests
(test-suite
"Test for exercise 2_29"
(test-case
"Balanced submobile"
(define left-branch (make-branch 9 5))
(define right-left-subbranch (make-branch 2 6))
(define right-right-subbranch (make-branch 4 3))
(define right-submobile (make-mobile right-left-subbranch right-right-subbranch))
(define right-branch (make-mobile 5 right-submobile))
(define mobile (make-mobile left-branch right-branch))
(check-equal? (total-weight mobile) (+ 5 6 3))
(check-true (balanced? mobile)))
(test-case
"Not Balanced"
(define left-branch (make-branch 9 5))
(define right-left-subbranch (make-branch 3 6))
(define right-right-subbranch (make-branch 4 3))
(define right-submobile (make-mobile right-left-subbranch right-right-subbranch))
(define right-branch (make-mobile 5 right-submobile))
(define mobile (make-mobile left-branch right-branch))
(check-equal? (total-weight mobile) (+ 5 6 3))
(check-false (balanced? mobile)))))
(run-tests tests 'verbose)