Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / test_unrolled_list.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import more_collections
16
17 var ul = new UnrolledList[Object]
18 var ll = new List[Object]
19
20 for i in 1000.times do
21 var val = 100.rand+1
22
23 var act = 3.rand
24 #print "+"+act.to_s
25 if act == 0 then
26 ll.add val
27 ul.add val
28 else if act == 1 then
29 ll.unshift val
30 ul.unshift val
31 else if act == 2 then
32 var index = ll.length.rand
33 ll.insert(val, index)
34 ul.insert(val, index)
35 else abort
36
37 #assert ll == ul
38 end
39
40 for i in 200.times do
41 var act = 3.rand
42 #print "-"+act.to_s
43 if act == 0 then
44 var o = ll.pop
45 var c = ul.pop
46 assert o == c
47 else if act == 1 then
48 var o = ll.shift
49 var c = ul.shift
50 assert o == c
51 else if act == 2 then
52 var index = ll.length.rand
53 ll.remove_at(index)
54 ul.remove_at(index)
55 else abort
56
57 #assert ll == ul
58 end
59
60 while ul.not_empty do
61 var c = ul.shift
62 var o = ll.shift
63 assert c == o else print "{c} vs {o}"
64 end
65 assert ll.is_empty