aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojox/collections/tests/SortedList.js
blob: dfb4ffa89d8fc378edfe75fa06af8607bcb106e7 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
if(!dojo._hasResource["dojox.collections.tests.SortedList"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.collections.tests.SortedList"] = true;
dojo.provide("dojox.collections.tests.SortedList");
dojo.require("dojox.collections.SortedList");

tests.register("dojox.collections.tests.SortedList", [
	function testCtor(t){
		var sl=new dojox.collections.SortedList();
		t.assertTrue(sl instanceof dojox.collections.SortedList);
	},
	function testAdd(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		t.assertEqual("bar", sl.item("foo").valueOf());
	},
	function testClear(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.clear();
		t.assertEqual(0, sl.count);
	},
	function testClone(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.add("baz","fab");
		sl.add("buck","shot");
		sl.add("apple","orange");
		var sl2=sl.clone();
		t.assertTrue(sl2.contains("baz"));
	},
	function testContains(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.add("baz","fab");
		sl.add("buck","shot");
		sl.add("apple","orange");
		t.assertTrue(sl.contains("baz"));
		t.assertFalse(sl.contains("faz"));
	},
	function testContainsKey(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.add("baz","fab");
		sl.add("buck","shot");
		sl.add("apple","orange");
		t.assertTrue(sl.containsKey("buck"));
		t.assertFalse(sl.containsKey("faz"));
	},
	function testContainsValue(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.add("baz","fab");
		sl.add("buck","shot");
		sl.add("apple","orange");
		t.assertTrue(sl.containsValue("shot"));
		t.assertFalse(sl.containsValue("faz"));
	},
	function testGetKeyList(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.add("baz","fab");
		sl.add("buck","shot");
		sl.add("apple","orange");
		t.assertEqual("foo,baz,buck,apple",sl.getKeyList().join(','));
	},
	function testGetValueList(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.add("baz","fab");
		sl.add("buck","shot");
		sl.add("apple","orange");
		t.assertEqual("bar,fab,shot,orange",sl.getValueList().join(','));
	},
	function testCopyTo(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.add("baz","fab");
		sl.add("buck","shot");
		sl.add("apple","orange");
		var arr=["bek"];
		sl.copyTo(arr,0);
		t.assertEqual("bar,fab,shot,orange,bek", arr.join(','));
	},
	function testGetByIndex(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.add("baz","fab");
		sl.add("buck","shot");
		sl.add("apple","orange");
		t.assertEqual("shot", sl.getByIndex(2));
	},
	function testGetKey(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.add("baz","fab");
		sl.add("buck","shot");
		sl.add("apple","orange");
		t.assertEqual("apple", sl.getKey(0));
	},
	function testIndexOfKey(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.add("baz","fab");
		sl.add("buck","shot");
		sl.add("apple","orange");
		t.assertEqual(0, sl.indexOfKey("apple"));
	},
	function testIndexOfValue(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.add("baz","fab");
		sl.add("buck","shot");
		sl.add("apple","orange");
		t.assertEqual(3, sl.indexOfValue("bar"));
	},
	function testRemove(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.add("baz","fab");
		sl.add("buck","shot");
		sl.add("apple","orange");
		sl.remove("baz");
		t.assertEqual(3, sl.count);
		t.assertEqual(undefined, sl.item("baz"));
	},
	function testRemoveAt(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.add("baz","fab");
		sl.add("buck","shot");
		sl.add("apple","orange");
		sl.removeAt(2);
		t.assertEqual(undefined, sl.item("buck"));
	},
	function testReplace(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.add("baz","fab");
		sl.add("buck","shot");
		sl.add("apple","orange");
		sl.replace("buck","dollar");
		t.assertEqual(sl.item("buck").valueOf(), "dollar");
	},
	function testSetByIndex(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.add("baz","fab");
		sl.add("buck","shot");
		sl.add("apple","orange");
		sl.setByIndex(0, "bar");
		t.assertEqual("bar", sl.getByIndex(0));
	},
	function testSorting(t){
		var sl=new dojox.collections.SortedList();
		sl.add("foo","bar");
		sl.add("baz","fab");
		sl.add("buck","shot");
		sl.add("apple","orange");

		var a=[];
		sl.forEach(function(item){
			a.push(item);
		});
		t.assertEqual("orange,fab,shot,bar", a.join());
	}
]);

}