summaryrefslogtreecommitdiff
path: root/frontend/gamma/tests/tests/Clipperz/Set.test.js
Unidiff
Diffstat (limited to 'frontend/gamma/tests/tests/Clipperz/Set.test.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Set.test.js165
1 files changed, 165 insertions, 0 deletions
diff --git a/frontend/gamma/tests/tests/Clipperz/Set.test.js b/frontend/gamma/tests/tests/Clipperz/Set.test.js
new file mode 100644
index 0000000..8122b07
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Set.test.js
@@ -0,0 +1,165 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer to http://www.clipperz.com
12
13* Javascript Crypto Library is free software: you can redistribute
14 it and/or modify it under the terms of the GNU Affero General Public
15 License as published by the Free Software Foundation, either version
16 3 of the License, or (at your option) any later version.
17
18* Javascript Crypto Library is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY; without even the implied
20 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU Affero General Public License for more details.
22
23* You should have received a copy of the GNU Affero General Public
24 License along with Javascript Crypto Library. If not, see
25 <http://www.gnu.org/licenses/>.
26
27*/
28
29var tests = {
30
31 //-------------------------------------------------------------------------
32
33 'set_test': function (someTestArgs) {
34 var deferredResult;
35
36 deferredResult = new Clipperz.Async.Deferred("set_test", someTestArgs);
37 deferredResult.addCallback(function () {
38 var set;
39 varobject1;
40 varobject2;
41 var object3;
42
43 set = new Clipperz.Set();
44
45 object1 = new Object();
46 object2 = new Object();
47 object3 = new Object();
48
49 object1.label = "object 1";
50 object2.label = "object 2";
51 object3.label = "object 3";
52
53 is(set.size(), 0, "A new set should be empty");
54
55 set.add(object1);
56 is(set.size(), 1);
57 is(set.contains(object1), true);
58 is(set.contains(object2), false);
59
60 set.add(object1);
61 is(set.size(), 1, "Adding the same object twice does not change the set content");
62 is(set.contains(object1), true);
63 is(set.contains(object2), false);
64
65 set.add(object2);
66 is(set.size(), 2);
67 is(set.contains(object1), true);
68 is(set.contains(object2), true);
69 is(set.contains(object3), false);
70
71 set.remove(object1);
72 is(set.size(), 1, "Size check after removing an object");
73 is(set.contains(object1), false);
74 is(set.contains(object2), true);
75 is(set.contains(object3), false);
76
77 set.remove(object1);
78 is(set.size(), 1, "Removing twice the same object does not change the set content");
79 is(set.contains(object1), false);
80 is(set.contains(object2), true);
81 is(set.contains(object3), false);
82
83 set.empty();
84 is(set.size(), 0);
85
86 {
87 varitems;
88 varpopulatedSet;
89
90 items = ["item1", "item2", "item3"];
91
92 populatedSet = new Clipperz.Set({'items': items});
93 is(populatedSet.size(), 3);
94 is(populatedSet.contains("item1"), true);
95 is(populatedSet.contains("item4"), false);
96
97 items.splice(0, items.length);
98 is(populatedSet.size(), 3);
99 }
100
101 {
102 varitems;
103 vardeletedItems;
104
105 items = ["item1", "item2", "item3"];
106
107 set = new Clipperz.Set({'items': items});
108 deletedItems = ["item1"];
109 set.remove(deletedItems);
110 is(set.size(), 2, "here I am");
111 is(set.contains("item1"), false);
112 is(set.contains("item2"), true);
113
114 set = new Clipperz.Set({'items': items});
115 deletedItems = ["item1", "item2"];
116 set.remove(deletedItems);
117 is(set.size(), 1);
118 is(set.contains("item1"), false);
119 is(set.contains("item2"), false);
120
121 set = new Clipperz.Set({'items': items});
122 deletedItems = ["item1", "item4"];
123 set.remove(deletedItems);
124 is(set.size(), 2);
125 is(set.contains("item1"), false);
126 is(set.contains("item2"), true);
127 }
128
129 {
130 var items;
131 var poppedItem;
132
133 items = ["item1", "item2", "item3"];
134 set = new Clipperz.Set({'items': items});
135
136 poppedItem = set.popAnItem();
137 ok(poppedItem != null, "test popAnItem - 1");
138 is(set.size(), 2, "test popAnItem - 2");
139
140 poppedItem = set.popAnItem();
141 ok(poppedItem != null, "test popAnItem - 3");
142 is(set.size(), 1, "test popAnItem - 4");
143
144 poppedItem = set.popAnItem();
145 ok(poppedItem != null, "test popAnItem - 5");
146 is(set.size(), 0, "test popAnItem - 6");
147
148 poppedItem = set.popAnItem();
149 ok(poppedItem == null, "test popAnItem - 7");
150 }
151 });
152 deferredResult.callback();
153
154 return deferredResult;
155 },
156
157 //-------------------------------------------------------------------------
158 'syntaxFix': MochiKit.Base.noop
159};
160
161
162
163//#############################################################################
164
165SimpleTest.runDeferredTests("Clipperz.Set", tests, {trace:false});