| 1 | dojo.provide("dojox.collections.tests.SortedList"); |
| 2 | dojo.require("dojox.collections.SortedList"); |
| 3 | |
| 4 | tests.register("dojox.collections.tests.SortedList", [ |
| 5 | function testCtor(t){ |
| 6 | var sl=new dojox.collections.SortedList(); |
| 7 | t.assertTrue(sl instanceof dojox.collections.SortedList); |
| 8 | }, |
| 9 | function testAdd(t){ |
| 10 | var sl=new dojox.collections.SortedList(); |
| 11 | sl.add("foo","bar"); |
| 12 | t.assertEqual("bar", sl.item("foo").valueOf()); |
| 13 | }, |
| 14 | function testClear(t){ |
| 15 | var sl=new dojox.collections.SortedList(); |
| 16 | sl.add("foo","bar"); |
| 17 | sl.clear(); |
| 18 | t.assertEqual(0, sl.count); |
| 19 | }, |
| 20 | function testClone(t){ |
| 21 | var sl=new dojox.collections.SortedList(); |
| 22 | sl.add("foo","bar"); |
| 23 | sl.add("baz","fab"); |
| 24 | sl.add("buck","shot"); |
| 25 | sl.add("apple","orange"); |
| 26 | var sl2=sl.clone(); |
| 27 | t.assertTrue(sl2.contains("baz")); |
| 28 | }, |
| 29 | function testContains(t){ |
| 30 | var sl=new dojox.collections.SortedList(); |
| 31 | sl.add("foo","bar"); |
| 32 | sl.add("baz","fab"); |
| 33 | sl.add("buck","shot"); |
| 34 | sl.add("apple","orange"); |
| 35 | t.assertTrue(sl.contains("baz")); |
| 36 | t.assertFalse(sl.contains("faz")); |
| 37 | }, |
| 38 | function testContainsKey(t){ |
| 39 | var sl=new dojox.collections.SortedList(); |
| 40 | sl.add("foo","bar"); |
| 41 | sl.add("baz","fab"); |
| 42 | sl.add("buck","shot"); |
| 43 | sl.add("apple","orange"); |
| 44 | t.assertTrue(sl.containsKey("buck")); |
| 45 | t.assertFalse(sl.containsKey("faz")); |
| 46 | }, |
| 47 | function testContainsValue(t){ |
| 48 | var sl=new dojox.collections.SortedList(); |
| 49 | sl.add("foo","bar"); |
| 50 | sl.add("baz","fab"); |
| 51 | sl.add("buck","shot"); |
| 52 | sl.add("apple","orange"); |
| 53 | t.assertTrue(sl.containsValue("shot")); |
| 54 | t.assertFalse(sl.containsValue("faz")); |
| 55 | }, |
| 56 | function testGetKeyList(t){ |
| 57 | var sl=new dojox.collections.SortedList(); |
| 58 | sl.add("foo","bar"); |
| 59 | sl.add("baz","fab"); |
| 60 | sl.add("buck","shot"); |
| 61 | sl.add("apple","orange"); |
| 62 | t.assertEqual("foo,baz,buck,apple",sl.getKeyList().join(',')); |
| 63 | }, |
| 64 | function testGetValueList(t){ |
| 65 | var sl=new dojox.collections.SortedList(); |
| 66 | sl.add("foo","bar"); |
| 67 | sl.add("baz","fab"); |
| 68 | sl.add("buck","shot"); |
| 69 | sl.add("apple","orange"); |
| 70 | t.assertEqual("bar,fab,shot,orange",sl.getValueList().join(',')); |
| 71 | }, |
| 72 | function testCopyTo(t){ |
| 73 | var sl=new dojox.collections.SortedList(); |
| 74 | sl.add("foo","bar"); |
| 75 | sl.add("baz","fab"); |
| 76 | sl.add("buck","shot"); |
| 77 | sl.add("apple","orange"); |
| 78 | var arr=["bek"]; |
| 79 | sl.copyTo(arr,0); |
| 80 | t.assertEqual("bar,fab,shot,orange,bek", arr.join(',')); |
| 81 | }, |
| 82 | function testGetByIndex(t){ |
| 83 | var sl=new dojox.collections.SortedList(); |
| 84 | sl.add("foo","bar"); |
| 85 | sl.add("baz","fab"); |
| 86 | sl.add("buck","shot"); |
| 87 | sl.add("apple","orange"); |
| 88 | t.assertEqual("shot", sl.getByIndex(2)); |
| 89 | }, |
| 90 | function testGetKey(t){ |
| 91 | var sl=new dojox.collections.SortedList(); |
| 92 | sl.add("foo","bar"); |
| 93 | sl.add("baz","fab"); |
| 94 | sl.add("buck","shot"); |
| 95 | sl.add("apple","orange"); |
| 96 | t.assertEqual("apple", sl.getKey(0)); |
| 97 | }, |
| 98 | function testIndexOfKey(t){ |
| 99 | var sl=new dojox.collections.SortedList(); |
| 100 | sl.add("foo","bar"); |
| 101 | sl.add("baz","fab"); |
| 102 | sl.add("buck","shot"); |
| 103 | sl.add("apple","orange"); |
| 104 | t.assertEqual(0, sl.indexOfKey("apple")); |
| 105 | }, |
| 106 | function testIndexOfValue(t){ |
| 107 | var sl=new dojox.collections.SortedList(); |
| 108 | sl.add("foo","bar"); |
| 109 | sl.add("baz","fab"); |
| 110 | sl.add("buck","shot"); |
| 111 | sl.add("apple","orange"); |
| 112 | t.assertEqual(3, sl.indexOfValue("bar")); |
| 113 | }, |
| 114 | function testRemove(t){ |
| 115 | var sl=new dojox.collections.SortedList(); |
| 116 | sl.add("foo","bar"); |
| 117 | sl.add("baz","fab"); |
| 118 | sl.add("buck","shot"); |
| 119 | sl.add("apple","orange"); |
| 120 | sl.remove("baz"); |
| 121 | t.assertEqual(3, sl.count); |
| 122 | t.assertEqual(undefined, sl.item("baz")); |
| 123 | }, |
| 124 | function testRemoveAt(t){ |
| 125 | var sl=new dojox.collections.SortedList(); |
| 126 | sl.add("foo","bar"); |
| 127 | sl.add("baz","fab"); |
| 128 | sl.add("buck","shot"); |
| 129 | sl.add("apple","orange"); |
| 130 | sl.removeAt(2); |
| 131 | t.assertEqual(undefined, sl.item("buck")); |
| 132 | }, |
| 133 | function testReplace(t){ |
| 134 | var sl=new dojox.collections.SortedList(); |
| 135 | sl.add("foo","bar"); |
| 136 | sl.add("baz","fab"); |
| 137 | sl.add("buck","shot"); |
| 138 | sl.add("apple","orange"); |
| 139 | sl.replace("buck","dollar"); |
| 140 | t.assertEqual(sl.item("buck").valueOf(), "dollar"); |
| 141 | }, |
| 142 | function testSetByIndex(t){ |
| 143 | var sl=new dojox.collections.SortedList(); |
| 144 | sl.add("foo","bar"); |
| 145 | sl.add("baz","fab"); |
| 146 | sl.add("buck","shot"); |
| 147 | sl.add("apple","orange"); |
| 148 | sl.setByIndex(0, "bar"); |
| 149 | t.assertEqual("bar", sl.getByIndex(0)); |
| 150 | }, |
| 151 | function testSorting(t){ |
| 152 | var sl=new dojox.collections.SortedList(); |
| 153 | sl.add("foo","bar"); |
| 154 | sl.add("baz","fab"); |
| 155 | sl.add("buck","shot"); |
| 156 | sl.add("apple","orange"); |
| 157 | |
| 158 | var a=[]; |
| 159 | sl.forEach(function(item){ |
| 160 | a.push(item); |
| 161 | }); |
| 162 | t.assertEqual("orange,fab,shot,bar", a.join()); |
| 163 | } |
| 164 | ]); |