tests: test UnrolledList
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 22 May 2015 15:37:23 +0000 (11:37 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 25 May 2015 17:37:07 +0000 (13:37 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

tests/test_unrolled_list.nit [new file with mode: 0644]

diff --git a/tests/test_unrolled_list.nit b/tests/test_unrolled_list.nit
new file mode 100644 (file)
index 0000000..df5f6a2
--- /dev/null
@@ -0,0 +1,65 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import more_collections
+
+var ul = new UnrolledList[Object]
+var ll = new List[Object]
+
+for i in 1000.times do
+       var val = 100.rand+1
+
+       var act = 3.rand
+       #print "+"+act.to_s
+       if act == 0 then
+               ll.add val
+               ul.add val
+       else if act == 1 then
+               ll.unshift val
+               ul.unshift val
+       else if act == 2 then
+               var index = ll.length.rand
+               ll.insert(val, index)
+               ul.insert(val, index)
+       else abort
+
+       #assert ll == ul
+end
+
+for i in 200.times do
+       var act = 3.rand
+       #print "-"+act.to_s
+       if act == 0 then
+               var o = ll.pop
+               var c = ul.pop
+               assert o == c
+       else if act == 1 then
+               var o = ll.shift
+               var c = ul.shift
+               assert o == c
+       else if act == 2 then
+               var index = ll.length.rand
+               ll.remove_at(index)
+               ul.remove_at(index)
+       else abort
+
+       #assert ll == ul
+end
+
+while ul.not_empty do
+       var c = ul.shift
+       var o = ll.shift
+       assert c == o else print "{c} vs {o}"
+end
+assert ll.is_empty