forked from programming-nu/nu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_return.nu
61 lines (55 loc) · 2.07 KB
/
test_return.nu
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
;; test_return.nu
;; tests for the Nu return operator.
;;
;; Copyright (c) 2007 Tim Burks, Radtastical Inc.
(class TestReturn is NuTestCase
(- testReturnVoid is
(function f (n)
(if (>= n 0) (return))
"negative")
(assert_equal "negative" (f -1))
(assert_equal nil (f 1)))
(- testReturnValue is
(function f (n)
(if (> n 0) (return "positive"))
(if (eq n 0) (return "zero"))
"negative")
(assert_equal "negative" (f -1))
(assert_equal "zero" (f 0))
(assert_equal "positive" (f 1)))
(- testReturnNested is
(function f (n)
(if (> n 0) (return "positive"))
(if (eq n 0) (return "zero"))
"negative")
(function g (n)
(if (eq (f n) "positive") (return "+"))
(if (eq (f n) "zero") (return "0"))
"-")
(assert_equal "-" (g -1))
(assert_equal "0" (g 0))
(assert_equal "+" (g 1)))
(- testReturnFromMethod is
(class ReturnTestClass is NSObject
(- (id) sign:(id) n is
(if (> n 0) (return "positive"))
(if (eq n 0) (return "zero"))
"negative")
(+ (id) sign:(id) n is
(if (> n 0) (return "+"))
(if (eq n 0) (return "0"))
"-"))
(set rtc ((ReturnTestClass alloc) init))
(assert_equal "negative" (rtc sign:-1))
(assert_equal "zero" (rtc sign:0))
(assert_equal "positive" (rtc sign:1))
(assert_equal "-" (ReturnTestClass sign:-1))
(assert_equal "0" (ReturnTestClass sign:0))
(assert_equal "+" (ReturnTestClass sign:1)))
(- fixme_testReturnFromOperator is
(set outer (do ()
(10 times:
(do (i) (10 times:
(do (j) (if (and (eq i 3) (eq j 4))
(return-from outer (+ i j)))))))))
(assert_equal 7 (outer))))