public
Description: The Nu programming language.
Homepage: http://programming.nu
Clone URL: git://github.com/timburks/nu.git
nu / test / test_numbers.nu
100644 39 lines (34 sloc) 1.052 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
;; test_numbers.nu
;; tests for Nu extensions to NSNumber.
;;
;; Copyright (c) 2007 Tim Burks, Neon Design Technology, Inc.
 
(class TestNumbers is NuTestCase
     
     (- testTimes is
        (set sum 0)
        (10 times:
            (do (i) (set sum (+ sum i))))
        (assert_equal 45 sum))
     
     (- testDownTo is
        (set firstValue nil)
        (set lastValue nil)
        (set sum 0)
        (10 downTo:5 do:
            (do (i)
                (set sum (+ sum i))
                (unless firstValue (set firstValue i))
                (set lastValue i)))
        (assert_equal 45 sum)
        (assert_equal 10 firstValue)
        (assert_equal 5 lastValue))
     
     (- testUpTo is
        (set firstValue nil)
        (set lastValue nil)
        (set sum 0)
        (5 upTo:10 do:
           (do (i)
               (set sum (+ sum i))
               (unless firstValue (set firstValue i))
               (set lastValue i)))
        (assert_equal 45 sum)
        (assert_equal 5 firstValue)
        (assert_equal 10 lastValue)))