Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 85 lines (75 sloc) 2.84 kB
506b8fa @timburks First public version.
authored
1 ;; test_dictionary.nu
2 ;; tests for Nu dictionary extensions.
3 ;;
29db4cd @timburks Company name changed.
authored
4 ;; Copyright (c) 2007 Tim Burks, Radtastical Inc.
506b8fa @timburks First public version.
authored
5
6 (class TestDictionary is NuTestCase
7
045f219 @timburks Replace "cmethod" and "imethod" with "+" and "-".
authored
8 (- (id) testSet is
9 (set d (NSMutableDictionary dictionary))
10 (d set:(one:1
11 "two" 2
12 three:"three"))
13 (assert_equal 3 (d count))
14 (assert_equal 2 (d valueForKey:"two"))
15 (assert_equal "three" (d valueForKey:"three")))
506b8fa @timburks First public version.
authored
16
045f219 @timburks Replace "cmethod" and "imethod" with "+" and "-".
authored
17 (- (id) testCreate is
18 (set d (NSMutableDictionary dictionaryWithList:(one:1
19 "two" 2
20 three:"three")))
21 (assert_equal 3 (d count))
22 (assert_equal 2 (d valueForKey:"two"))
23 (assert_equal "three" (d valueForKey:"three")))
9f07038 @timburks Automatic key accessors for dictionaries, better testing for falsehood.
authored
24
045f219 @timburks Replace "cmethod" and "imethod" with "+" and "-".
authored
25 (- (id) testAutomaticAccessor is
26 (set d (dict "one" 1 two:2))
27 (assert_equal 1 (d "one"))
28 (assert_equal 2 (d "two")))
7989745 @timburks A pair of useful extensions to NSDictionary.
authored
29
045f219 @timburks Replace "cmethod" and "imethod" with "+" and "-".
authored
30 (- (id) testEach is
31 (set d (dict one:1 two:2 three:3 four:4 five:5 six:6))
32 ;; test each: through everything
33 (set count 0)
34 (d each:
35 (do (k v)
36 (assert_equal (d objectForKey:k) v)
37 (set count (+ count 1))))
38 (assert_equal (d count) count)
39 ;; test each: with break
40 (set count 0)
41 (d each:
42 (do (k v)
43 (if (eq count 3) (break))
44 (set count (+ count 1))))
45 (assert_equal 3 count)
46 ;; test each: with continue
47 (set count 0)
48 (d each:
49 (do (k v)
50 (if (eq v 3) (continue))
51 (set count (+ count 1))))
52 (assert_equal (- (d count) 1) count))
a8bd2e9 @andrewschleifer Add "map" to NSDictionary
andrewschleifer authored
53
aa3f218 @andrewschleifer Fix some trivial whitespace
andrewschleifer authored
54 (- (id) testMap is
a8bd2e9 @andrewschleifer Add "map" to NSDictionary
andrewschleifer authored
55 (set d (dict one:1 two:2 three:3 four:4))
56 (set o (d map:(do (k v) (+ 1 v))))
57 (assert_equal (d count) (o count))
58 (d each:
59 (do (k v)
60 (assert_equal (+ 1 v) (o k)))))
7989745 @timburks A pair of useful extensions to NSDictionary.
authored
61
045f219 @timburks Replace "cmethod" and "imethod" with "+" and "-".
authored
62 (- (id) testLookupWithDefault is
63 (set d (dict "one" 1 two:2))
64 (assert_equal 1 (d objectForKey:"one" withDefault:3))
65 (assert_equal 3 (d objectForKey:"three" withDefault:3)))
76c4953 @timburks new tricks for setting NSMutableDictionary entries.
authored
66
045f219 @timburks Replace "cmethod" and "imethod" with "+" and "-".
authored
67 (- (id) testShorthand is
68 (set d (dict a:12 b:23 c:34))
69 (assert_equal 12 (d "a"))
70 (set x "a")
71 (assert_equal 12 (d x))
72 (assert_equal 12 (d a:))
73 (d a:78 d:89 e:90)
74 (assert_equal 5 (d count))
75 (assert_equal 78 (d a:))
76 (assert_equal 89 (d d:))
77 (assert_equal 90 (d e:))
78 (assert_equal 11 (d a:11 b:22 a:))
79 (assert_equal 22 (d b:))
80 ;; make sure that we properly evaluate key and value arguments
81 (d (+ "a" "a") (+ "b" "b") (+ "c" "c") (+ "d" "d"))
82 (assert_equal "bb" (d (+ "a" "a")))
83 (assert_equal "dd" (d (+ "c" "" "c")))))
506b8fa @timburks First public version.
authored
84
Something went wrong with that request. Please try again.