From 31b6c3da24f60a0d042f5ce3108fce140cf67650 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Fri, 22 May 2015 11:37:23 -0400 Subject: [PATCH] tests: test UnrolledList MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- tests/test_unrolled_list.nit | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/test_unrolled_list.nit diff --git a/tests/test_unrolled_list.nit b/tests/test_unrolled_list.nit new file mode 100644 index 0000000..df5f6a2 --- /dev/null +++ b/tests/test_unrolled_list.nit @@ -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 -- 1.7.9.5