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