-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2_79.test.rkt
32 lines (24 loc) · 1.06 KB
/
2_79.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
#lang racket
(require rackunit rackunit/text-ui)
(require (only-in "../solutions/2_78.rkt" install-scheme-number-package install-rational-package install-complex-package))
(require (only-in "../solutions/dispatch-table.rkt" apply-generic get put))
(require (only-in "../solutions/2_79.rkt" install-equ?-package))
(install-scheme-number-package)
(install-rational-package)
(install-complex-package)
(install-equ?-package)
(define (make-rational n d)
((get 'make 'rational) n d))
(define (make-complex-from-real-imag x y)
((get 'make-from-real-imag 'complex) x y))
(define (equ? x y) (apply-generic 'equ? x y))
(define tests
(test-suite
"Test for exercise 2_79"
(check-true (equ? 1 1))
(check-false (equ? 1 2))
(check-true (equ? (make-rational 1 2) (make-rational 2 4)))
(check-false (equ? (make-rational 3 2) (make-rational 2 4)))
(check-true (equ? (make-complex-from-real-imag 2 10) (make-complex-from-real-imag 2 10)))
(check-false (equ? (make-complex-from-real-imag 2 11) (make-complex-from-real-imag 2 10)))))
(run-tests tests 'verbose)