-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain-test-default.rkt
33 lines (27 loc) · 1.03 KB
/
main-test-default.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
#lang racket
;; run with raco test
(module+ test
(require "main.rkt" rackunit)
;; renamed procedures
(check-equal? (+ 1 1) 2)
(check-equal? (add 1 1) 2)
(check-equal? (subtract 1 1) 0)
(check-equal? (gt? 1 0) #t)
(check-equal? (gte? 1 1) #t)
(check-equal? (&& 1 2) 2)
;; (check-equal? (&& 1 2 3) 3) ;; not supported
(check-equal? (|| 1 2) 1)
;; (check-equal? (|| 1 2 3) 1) ;; not supported
;; lambda shorthand
(check-equal? ((e : #f) 0) #f)
(check-equal? ((e : #t) 0) #t)
(check-equal? ((x y : + x y) 1 2) 3)
;; function composition
("FOO" ~> string-downcase ~> check-equal? "foo")
("FOO" ~> string-ref (1 ~> subtract 1) ~> char-downcase ~> check-equal? #\f)
('(1 2 3) ~~> map (lambda (x) (+ x 1)) ~> check-equal? '(2 3 4))
;; function composition and lambda shorthand combined
("FOO" ~> (x : string-downcase x) ~> check-equal? "foo")
(((x y : x ~> add y) 1 2) ~> check-equal? 3)
((sort '(3 2 1) (a b : a ~> lt? b)) ~> check-equal? '(1 2 3))
((sort '(1 2 3) (a b : a ~> gt? b)) ~> check-equal? '(3 2 1)))