bzr branch
http://gegoxaren.bato24.eu/bzr/vqdr/trunk
1
by Gustav Hartvigsson
* Initial code - far from done |
1 |
using VQDR.Expression; |
2 |
||
3 |
void
|
|
4 |
test_value_token () { |
|
24
by Gustav Hartvigsson
* Fixed valadoc stuff. |
5 |
GLib.Test.add_func ("/VQDR/Expression/Token/Value/sanity", () => { |
1
by Gustav Hartvigsson
* Initial code - far from done |
6 |
var ctx = new Context (); |
7 |
|
|
8 |
if (ctx == null) { |
|
9 |
GLib.Test.message ("Context was null."); |
|
10 |
GLib.Test.fail (); |
|
11 |
GLib.assert_not_reached (); |
|
12 |
} |
|
13 |
|
|
14 |
if (!(ctx.get_type ().is_a (typeof (Context)))) { |
|
15 |
GLib.Test.message ("Context is not the right type."); |
|
16 |
GLib.Test.fail (); |
|
17 |
GLib.assert_not_reached (); |
|
18 |
} |
|
19 |
|
|
20 |
var v1 = new ConstantValueToken (13,37); |
|
21 |
var v2 = new VariableValueToken ("my-val", 13); |
|
22 |
|
|
23 |
Type t1 = v1.get_type (); |
|
24
by Gustav Hartvigsson
* Fixed valadoc stuff. |
24 |
if (!(t1.is_a (typeof (ConstantValueToken)) && |
25 |
t1.is_a (typeof (ValueToken)) && |
|
26 |
t1.is_a (typeof (Token)))) { |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
27 |
GLib.Test.message ("The ConstastValueToken is not the corret type."); |
28 |
GLib.Test.fail (); |
|
29 |
GLib.assert_not_reached (); |
|
30 |
} |
|
31 |
|
|
32 |
Type t2 = v2.get_type (); |
|
24
by Gustav Hartvigsson
* Fixed valadoc stuff. |
33 |
if (!((t2.is_a (typeof (VariableValueToken))) && |
34 |
(t2.is_a (typeof (ValueToken))) && |
|
35 |
(t2.is_a (typeof (Token))))) { |
|
36 |
GLib.Test.message ("The VariableValueToken is not the corret type."); |
|
37 |
GLib.Test.fail (); |
|
38 |
GLib.assert_not_reached (); |
|
39 |
} |
|
40 |
|
|
41 |
}); |
|
42 |
|
|
43 |
GLib.Test.add_func ("/VQDR/Expression/token/Value/Factory", () => { |
|
44 |
var v3 = ValueToken.init_value_token (13L, 37); |
|
45 |
var v4 = ValueToken.init_value_token ("foo", 12); |
|
46 |
Type t4 = v4.get_type (); |
|
47 |
Type t3 = v3.get_type (); |
|
48 |
|
|
49 |
|
|
50 |
if (!(t3.is_a (typeof (ConstantValueToken))) && |
|
51 |
t3.is_a (typeof (ValueToken)) && |
|
52 |
t3.is_a (typeof (Token))) { |
|
53 |
GLib.Test.message ("The ConstastValueToken is not the corret type."); |
|
54 |
GLib.Test.fail (); |
|
55 |
GLib.assert_not_reached (); |
|
56 |
} |
|
57 |
|
|
58 |
|
|
59 |
if (!((t4.is_a (typeof (VariableValueToken))) && |
|
60 |
(t4.is_a (typeof (ValueToken))) && |
|
61 |
(t4.is_a (typeof (Token))))) { |
|
62 |
GLib.Test.message ("The VariableValueToken is not the corret type."); |
|
63 |
GLib.Test.fail (); |
|
64 |
GLib.assert_not_reached (); |
|
65 |
} |
|
66 |
}); |
|
67 |
|
|
68 |
GLib.Test.add_func ("/VQDR/Expression/Token/Value/Constant", () => { |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
69 |
try { |
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
70 |
int64 in_val = 12; |
1
by Gustav Hartvigsson
* Initial code - far from done |
71 |
|
72 |
var ctx = new Context (); |
|
73 |
|
|
74 |
var v1 = new ConstantValueToken (in_val, 1); |
|
75 |
|
|
76 |
var root_t = new RootToken (v1); |
|
77 |
|
|
78 |
root_t.evaluate (ctx); |
|
79 |
|
|
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
80 |
int64 out_val = root_t.result_value.number; |
1
by Gustav Hartvigsson
* Initial code - far from done |
81 |
|
82 |
if (out_val != in_val) { |
|
57
by Gustav Hartvigsson
Made sure that no text rows exeed 80 columns. |
83 |
GLib.Test.message (@"The values do not match: Expected $(in_val), " + |
84 |
" got $(out_val).\n"); |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
85 |
GLib.Test.fail (); |
86 |
} |
|
87 |
} catch (GLib.Error? e) { |
|
57
by Gustav Hartvigsson
Made sure that no text rows exeed 80 columns. |
88 |
GLib.Test.message (@"An error occured: domain: $(e.domain)," + |
89 |
" message: $(e.message)"); |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
90 |
GLib.Test.fail (); |
91 |
} |
|
92 |
}); |
|
93 |
|
|
24
by Gustav Hartvigsson
* Fixed valadoc stuff. |
94 |
GLib.Test.add_func ("/VQDR/Expression/Token/Value/ConstantLoop", () => { |
1
by Gustav Hartvigsson
* Initial code - far from done |
95 |
|
96 |
|
|
97 |
try { |
|
98 |
var ctx = new Context (); |
|
99 |
|
|
100 |
for (int i = 0; i <= 10000; i++ ) { |
|
101 |
var v1 = new ConstantValueToken (i, 1); |
|
102 |
|
|
103 |
var root_t = new RootToken (v1); |
|
104 |
|
|
105 |
root_t.evaluate (ctx); |
|
106 |
|
|
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
107 |
int64 out_val = root_t.result_value.number; |
1
by Gustav Hartvigsson
* Initial code - far from done |
108 |
|
109 |
if (out_val != i) { |
|
110 |
GLib.Test.message ("The values do not match"); |
|
111 |
GLib.Test.fail (); |
|
112 |
} |
|
113 |
} |
|
114 |
} catch (GLib.Error? e) { |
|
115 |
GLib.Test.message ("An error occured: domain: %s, message: %s", e.domain.to_string (), e.message); |
|
116 |
GLib.Test.fail (); |
|
117 |
} |
|
118 |
}); |
|
119 |
|
|
24
by Gustav Hartvigsson
* Fixed valadoc stuff. |
120 |
GLib.Test.add_func ("/VQDR/Expression/Token/Value/Varuable", () => { |
1
by Gustav Hartvigsson
* Initial code - far from done |
121 |
try { |
122 |
var ctx = new Context (); |
|
123 |
ctx.set_value ("a", 0, 0, 13); |
|
124 |
ctx.set_value ("not a", 0, 0, 37); |
|
125 |
|
|
126 |
// Context variable santy check. |
|
31
by Gustav Hartvigsson
Changed over the Variabel class to use FastNumers |
127 |
if ((ctx.get_value ("a").number != 13) || (ctx.get_value ("not a").number != 37)) { |
1
by Gustav Hartvigsson
* Initial code - far from done |
128 |
GLib.Test.message ("The values do not match"); |
129 |
|
|
130 |
GLib.Test.fail (); |
|
131 |
} |
|
132 |
|
|
133 |
var v1 = new VariableValueToken ("a", 1); |
|
134 |
var v2 = new VariableValueToken ("not a", 1); |
|
135 |
|
|
31
by Gustav Hartvigsson
Changed over the Variabel class to use FastNumers |
136 |
print (v1.result_string + "\n"); |
137 |
print (v2.result_string + "\n"); |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
138 |
} catch (GLib.Error? e) { |
139 |
GLib.Test.message ("An error occured: domain: %s, message: %s", e.domain.to_string (), e.message); |
|
140 |
GLib.Test.fail (); |
|
141 |
} |
|
142 |
}); |
|
143 |
|
|
144 |
|
|
145 |
}
|