public
Description: The Nu programming language.
Homepage: http://programming.nu
Clone URL: git://github.com/timburks/nu.git
nu / test / test_return.nu
100644 53 lines (48 sloc) 1.781 kb
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
;; test_return.nu
;; tests for the Nu return operator.
;;
;; Copyright (c) 2007 Tim Burks, Neon Design Technology, 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))))