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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/* testtreemap.vala
*
* Copyright (C) 2008 Maciej Piechotka
* Copyright (C) 2009 Didier Villevalois, Julien Peeters
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Julien Peeters <contact@julienpeeters.fr>
*/
using Gee;
public class TreeMapTests : MapTests {
public TreeMapTests () {
base ("TreeMap");
add_test ("[TreeMap] selected functions", test_selected_functions);
add_test ("[TreeMap] GObject properties", test_gobject_properties);
add_test ("[TreeMap] key ordering", test_key_ordering);
}
public override void set_up () {
test_map = new TreeMap<string,string> ();
}
public override void tear_down () {
test_map = null;
}
public void test_selected_functions () {
var test_tree_map = test_map as TreeMap<string,string>;
// Check the map exists
assert (test_tree_map != null);
// Check the selected compare and equal functions
assert (test_tree_map.key_compare_func == (CompareFunc) strcmp);
assert (test_tree_map.value_equal_func == str_equal);
}
public new void test_gobject_properties () {
var test_tree_map = test_map as TreeMap<string,string>;
// Check the list exists
assert (test_tree_map != null);
Value value;
value = Value (typeof (CompareFunc));
test_tree_map.get_property ("key-compare-func", ref value);
assert (value.get_pointer () == (void*) test_tree_map.key_compare_func);
value.unset ();
value = Value (typeof (EqualFunc));
test_tree_map.get_property ("value-equal-func", ref value);
assert (value.get_pointer () == (void*) test_tree_map.value_equal_func);
value.unset ();
}
public void test_key_ordering () {
var test_tree_map = test_map as TreeMap<string,string>;
// Check the map exists
assert (test_tree_map != null);
test_tree_map.set ("one", "one");
test_tree_map.set ("two", "two");
test_tree_map.set ("three", "three");
test_tree_map.set ("four", "four");
test_tree_map.set ("five", "five");
test_tree_map.set ("six", "six");
test_tree_map.set ("seven", "seven");
test_tree_map.set ("eight", "eight");
test_tree_map.set ("nine", "nine");
test_tree_map.set ("ten", "ten");
test_tree_map.set ("eleven", "eleven");
test_tree_map.set ("twelve", "twelve");
Iterator<string> iterator = test_tree_map.keys.iterator ();
assert (iterator.next ());
assert (iterator.get () == "eight");
assert (iterator.next ());
assert (iterator.get () == "eleven");
assert (iterator.next ());
assert (iterator.get () == "five");
assert (iterator.next ());
assert (iterator.get () == "four");
assert (iterator.next ());
assert (iterator.get () == "nine");
assert (iterator.next ());
assert (iterator.get () == "one");
assert (iterator.next ());
assert (iterator.get () == "seven");
assert (iterator.next ());
assert (iterator.get () == "six");
assert (iterator.next ());
assert (iterator.get () == "ten");
assert (iterator.next ());
assert (iterator.get () == "three");
assert (iterator.next ());
assert (iterator.get () == "twelve");
assert (iterator.next ());
assert (iterator.get () == "two");
assert (iterator.next () == false);
}
}
|