bzr branch
http://gegoxaren.bato24.eu/bzr/vqdr/trunk
46
by Gustav Hartvigsson
Added a simple stack type. |
1 |
using Utils; |
2 |
using GLib; |
|
3 |
||
4 |
void stack_test () { |
|
5 |
Test.add_func (UTIL_TEST_STACK_PREFIX + "new", () => { |
|
6 |
var stk = new Stack<int> (); |
|
7 |
if (stk == null) { |
|
8 |
Test.fail (); |
|
9 |
Test.message ("Could not create stack"); |
|
10 |
} |
|
11 |
||
12 |
if (stk.is_empty () == false) { |
|
13 |
Test.fail (); |
|
14 |
Test.message ("The newly created Stack" + |
|
15 |
" has the reports it's not empty."); |
|
16 |
} |
|
50
by Gustav Hartvigsson
Added test for NamedVector |
17 |
|
46
by Gustav Hartvigsson
Added a simple stack type. |
18 |
}); |
19 |
||
20 |
Test.add_func (UTIL_TEST_STACK_PREFIX + "push_pop", () => { |
|
21 |
var stk = new Stack<int> (); |
|
22 |
stk.push (1337); |
|
23 |
if (stk.is_empty ()) { |
|
24 |
Test.fail (); |
|
25 |
Test.message ("Stack reports that it's empty, " + |
|
26 |
"when it shouln't be."); |
|
27 |
} |
|
28 |
||
29 |
stk.pop (); |
|
30 |
|
|
31 |
if (stk.is_empty () == false) { |
|
32 |
Test.fail (); |
|
33 |
Test.message ("Stack reports that it's not empty," + |
|
34 |
" when it's only value has been poped."); |
|
35 |
} |
|
36 |
|
|
37 |
}); |
|
38 |
||
39 |
||
40 |
Test.add_func (UTIL_TEST_STACK_PREFIX + "value", () => { |
|
41 |
var stk = new Stack<int> (); |
|
42 |
|
|
43 |
stk.push (1337); |
|
44 |
||
45 |
if (stk.peek () != 1337) { |
|
46 |
Test.fail (); |
|
47 |
Test.message ("Peeked value did not match exepcted value."); |
|
48 |
} |
|
49 |
||
50 |
if (stk.pop () != 1337) { |
|
51 |
Test.fail (); |
|
52 |
Test.message ("Poped value does not match expected value."); |
|
53 |
} |
|
54 |
|
|
55 |
foreach (var i in new Range (0, 10000) ) { |
|
56 |
stk.push (i); |
|
57 |
} |
|
58 |
|
|
59 |
foreach (var i in new Range (10000, 0)) { |
|
60 |
int got_val = stk.pop (); |
|
61 |
if (i != got_val) { |
|
62 |
Test.fail (); |
|
63 |
Test.message ("Wrong value: Expeted %i, get %i.", |
|
64 |
i, got_val); |
|
65 |
} |
|
66 |
} |
|
67 |
||
68 |
}); |
|
69 |
}
|