First NIT release and new clean mercurial repository
[nit.git] / tests / test_list.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2004-2008 Jean Privat <jean@pryen.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 do
18 var l = new List[Int]
19 l.push(1)
20 printn(l.shift)
21 l.push(2)
22 l.push(3)
23 printn(l.shift)
24 printn(l.shift)
25 l.push(4)
26 printn(l.shift)
27
28 l = new List[Int].from([1,2,3,4])
29
30 var i = l.iterator
31 while i.is_ok do
32 printn(i.item)
33 i.next
34 end
35
36 l.unshift(0)
37 l.unshift(-1)
38 printn(l.shift)
39 printn(l.first)
40 printn(l.last)
41 printn(l.shift)
42 printn(l.pop)
43 printn(l.shift)
44 printn(l.pop)
45 printn(l.shift)
46 end
47
48 print("\npart2")
49
50 do
51 var l = new List[Int].from([1,2,3,4,5,6])
52 print(l)
53 print(l.has(3))
54 print(not l.has(9))
55 print(l.has_key(3))
56 print(not l.has_key(-3))
57 print(not l.has_key(30))
58 print(l[1] == 2)
59 print(l.first == 1)
60 print(l.last == 6)
61 print(l.length == 6)
62 l[2] = -3
63 l.first = -1
64 l.last = -6
65 l.remove(4)
66 print(l)
67 end
68