Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 58 lines (47 sloc) 1.935 kB
47e02bf @timburks comparison operators now use compare:
authored
1 ;; test_comparison.nu
2 ;; tests for Nu comparison operators.
3 ;;
29db4cd @timburks Company name changed.
authored
4 ;; Copyright (c) 2008 Tim Burks, Radtastical Inc.
47e02bf @timburks comparison operators now use compare:
authored
5
6 (class TestComparison is NuTestCase
7
8 (- testLessThan is
9 (assert_equal t (< 1 2 3))
10 (assert_equal t (< "a" "b" "c"))
11 (assert_equal nil (< 1 2 3 3))
12 (assert_equal nil (< "b" "a")))
13
14 (- testGreaterThan is
15 (assert_equal t (> 3 2 1))
16 (assert_equal t (> "c" "b" "a"))
17 (assert_equal nil (> 3 2 1 1))
18 (assert_equal nil (> "a" "b")))
19
20 (- testLessThanOrEqual is
21 (assert_equal t (<= 1 2 2 3))
22 (assert_equal t (<= "a" "b" "b" "c"))
23 (assert_equal nil (<= 1 2 3 2))
24 (assert_equal nil (<= "b" "a")))
25
26 (- testGreaterThanOrEqual is
27 (assert_equal t (>= 3 2 2 1))
28 (assert_equal t (>= "c" "b" "b" "a"))
29 (assert_equal nil (>= 3 2 1 2))
30 (assert_equal nil (>= "a" "b")))
31
aa31bfb @timburks operator cleanup
authored
32 (- testCustomComparison is
33
34 (class NumericString is NSObject
35 (+ stringWithString:s is ((self alloc) initWithString:s))
36 (- initWithString:s is
37 (self init)
38 (set @string s)
39 self)
40 (- stringValue is @string)
41 (- description is @string)
42 (- (int) compare:(id) other is
43 ((@string intValue) compare:((other stringValue) intValue))))
44
45 (set x (NumericString stringWithString:"123"))
46 (set y (NumericString stringWithString:"45"))
47 (set z (NumericString stringWithString:"12"))
48
49 (set a ((array x y z) sort))
50
51 (assert_equal "12" ((a 0) stringValue))
52 (assert_equal "45" ((a 1) stringValue))
53 (assert_equal "123" ((a 2) stringValue))
54
55 (assert_equal nil (<= x y))
56 (assert_equal nil (< x y))
57 (assert_equal t (>= x y))
58 (assert_equal t (> x y))))
Something went wrong with that request. Please try again.