bzr branch
http://gegoxaren.bato24.eu/bzr/vqdr/trunk
|
11
by Gustav Hartvigsson
* FastNumber: |
1 |
using GLib; |
2 |
||
3 |
using VQDR.Common.Utils; |
|
4 |
using VQDR.Common; |
|
5 |
using VQDR.Expression; |
|
6 |
||
7 |
void fast_number_test () { |
|
8 |
Test.add_func ("/Common/Utils/FastNumber/add", () => { |
|
|
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
9 |
var f1 = FastNumber (1337); |
10 |
var f2 = FastNumber (1333); |
|
|
11
by Gustav Hartvigsson
* FastNumber: |
11 |
var f3 = f1.add (f2); |
12 |
if (f3.number != 2670) { |
|
13 |
Test.fail (); |
|
14 |
Test.message ("The added numbers do not match the expected value"); |
|
15 |
} |
|
16 |
}); |
|
17 |
Test.add_func ("/Common/Utils/FastNumber/subtract", () => { |
|
|
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
18 |
var f1 = FastNumber (1337); |
19 |
var f2 = FastNumber (1333); |
|
|
11
by Gustav Hartvigsson
* FastNumber: |
20 |
var f3 = f1.subtract (f2); |
21 |
if (f3.number != 4) { |
|
22 |
Test.fail (); |
|
23 |
Test.message ("The subtracted numbers do not match the expected value"); |
|
24 |
} |
|
25 |
}); |
|
26 |
Test.add_func ("/Common/Utils/FastNumber/divide", () => { |
|
|
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
27 |
var f1 = FastNumber (1338); |
28 |
var f2 = FastNumber (2); |
|
29 |
FastNumber f3 = {0}; |
|
30 |
try { |
|
31 |
f3 = f1.divide (f2); |
|
32 |
Utils.print_ln ("f3.number: %i", f3.number); |
|
33 |
} catch (Error e) { |
|
34 |
Utils.print_ln ("Error: %s\n", e.message); |
|
35 |
} |
|
36 |
if (f3.number != 669) { |
|
37 |
Test.fail (); |
|
38 |
Test.message ("The added numbers do not match the expected value"); |
|
39 |
} |
|
40 |
}); |
|
41 |
|
|
42 |
Test.add_func ("/Common/Utils/FastNumber/divide2", () => { |
|
43 |
var f1 = FastNumber (4444); |
|
44 |
var f2 = FastNumber (1111); |
|
45 |
FastNumber f3 = {0}; |
|
46 |
try { |
|
47 |
f3 = f1.divide (f2); |
|
48 |
Utils.print_ln ("f3.number: %i", f3.number); |
|
49 |
} catch (Error e) { |
|
50 |
Utils.print_ln ("Error: %s\n", e.message); |
|
51 |
} |
|
52 |
if (f3.number != 4) { |
|
53 |
Test.fail (); |
|
54 |
Test.message ("The added numbers do not match the expected value"); |
|
55 |
} |
|
56 |
}); |
|
57 |
|
|
|
11
by Gustav Hartvigsson
* FastNumber: |
58 |
Test.add_func ("/Common/Utils/FastNumber/multiply", () => { |
|
20
by Gustav Hartvigsson
* fixed the parsing of string in FastNumber.parse_raw_number () |
59 |
var expected_val = 4444; |
60 |
var f1 = FastNumber (1111); |
|
61 |
var f2 = FastNumber (4); |
|
62 |
var f3 = f1.multiply (f2); |
|
63 |
if (f3.number != expected_val) { |
|
64 |
Test.fail (); |
|
65 |
Test.message ("The multiplied numbers does not match the exected value."); |
|
66 |
Test.message (@"expected $expected_val, got $f3.number"); |
|
67 |
} |
|
68 |
}); |
|
69 |
|
|
70 |
Test.add_func ("/Common/Utils/FastNumber/parse_raw_number1", () => { |
|
71 |
var expected_val = 1000; |
|
72 |
var val = FastNumber.parse_raw_number ("1"); |
|
73 |
|
|
74 |
if (expected_val != val) { |
|
75 |
Test.fail (); |
|
76 |
Test.message ("The raw numbers does not match the exected value."); |
|
77 |
Test.message (@"expected $expected_val, got $val"); |
|
78 |
} |
|
79 |
|
|
80 |
for (int i = 2; i <= 25; i = i + 3) { |
|
81 |
val = FastNumber.parse_raw_number (i.to_string ()); |
|
82 |
|
|
83 |
if ((expected_val * i) != val) { |
|
84 |
Test.fail (); |
|
85 |
Test.message ("The raw numbers does not match the exected value."); |
|
86 |
Test.message (@"expected $expected_val, got $val"); |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
}); |
|
91 |
|
|
|
21
by Gustav Hartvigsson
added more testes for the parser. |
92 |
/* |
93 |
* All decimls that have to be converted to float must be
|
|
94 |
* divicable by two. in these tests, or we will get rounding errors
|
|
95 |
* when converting to floating point preresentation.
|
|
96 |
*/
|
|
97 |
|
|
|
20
by Gustav Hartvigsson
* fixed the parsing of string in FastNumber.parse_raw_number () |
98 |
Test.add_func ("/Common/Utils/FastNumber/parse_raw_number2", () => { |
99 |
var expected_val = 1128; |
|
100 |
var val = FastNumber.parse_raw_number ("1.128"); |
|
101 |
|
|
102 |
if (expected_val != val) { |
|
103 |
Test.fail (); |
|
104 |
Test.message ("The raw numbers does not match the exected value."); |
|
105 |
Test.message (@"expected $expected_val, got $val"); |
|
106 |
} |
|
107 |
|
|
108 |
expected_val = 5128; |
|
109 |
val = FastNumber.parse_raw_number ("5.128"); |
|
110 |
|
|
111 |
if (expected_val != val) { |
|
112 |
Test.fail (); |
|
113 |
Test.message ("The raw numbers does not match the exected value."); |
|
114 |
Test.message (@"expected $expected_val, got $val"); |
|
115 |
} |
|
116 |
|
|
117 |
expected_val = 7128; |
|
118 |
val = FastNumber.parse_raw_number ("7.128"); |
|
119 |
|
|
120 |
if (expected_val != val) { |
|
121 |
Test.fail (); |
|
122 |
Test.message ("The raw numbers does not match the exected value."); |
|
123 |
Test.message (@"expected $expected_val, got $val"); |
|
124 |
} |
|
125 |
|
|
126 |
}); |
|
127 |
|
|
128 |
Test.add_func ("/Common/Utils/parse_raw_number3", () => { |
|
129 |
var expected_val = 15128; |
|
130 |
var val = FastNumber.parse_raw_number ("15.128"); |
|
131 |
|
|
132 |
if (expected_val != val) { |
|
133 |
Test.fail (); |
|
134 |
Test.message ("The raw numbers does not match the exected value."); |
|
135 |
Test.message (@"expected $expected_val, got $val"); |
|
136 |
} |
|
137 |
}); |
|
138 |
|
|
139 |
Test.add_func ("/Common/Utils/parse_raw_number4", () => { |
|
140 |
var expected_val = 20128; |
|
141 |
var val = FastNumber.parse_raw_number ("20.128"); |
|
142 |
|
|
143 |
if (expected_val != val) { |
|
144 |
Test.fail (); |
|
145 |
Test.message ("The raw numbers does not match the exected value."); |
|
146 |
Test.message (@"expected $expected_val, got $val"); |
|
147 |
} |
|
148 |
}); |
|
149 |
|
|
|
21
by Gustav Hartvigsson
added more testes for the parser. |
150 |
Test.add_func ("/Common/Utils/parse_raw_number5", () => { |
151 |
var expected_val = 222128; |
|
152 |
var val = FastNumber.parse_raw_number ("222.128"); |
|
153 |
|
|
154 |
if (expected_val != val) { |
|
155 |
Test.fail (); |
|
156 |
Test.message ("The raw numbers does not match the exected value."); |
|
157 |
Test.message (@"expected $expected_val, got $val"); |
|
158 |
} |
|
159 |
}); |
|
160 |
|
|
161 |
Test.add_func ("/Common/Utils/parse_raw_number6", () => { |
|
162 |
var expected_val = 128; |
|
163 |
var val = FastNumber.parse_raw_number ("0.128"); |
|
164 |
|
|
165 |
if (expected_val != val) { |
|
166 |
Test.fail (); |
|
167 |
Test.message ("The raw numbers does not match the exected value."); |
|
168 |
Test.message (@"expected $expected_val, got $val"); |
|
169 |
} |
|
170 |
}); |
|
171 |
|
|
172 |
Test.add_func ("/Common/Utils/parse_raw_number7", () => { |
|
173 |
var expected_val = 160; |
|
174 |
var val = FastNumber.parse_raw_number ("0.16"); |
|
175 |
|
|
176 |
if (expected_val != val) { |
|
177 |
Test.fail (); |
|
178 |
Test.message ("The raw numbers does not match the exected value."); |
|
179 |
Test.message (@"expected $expected_val, got $val"); |
|
180 |
} |
|
181 |
}); |
|
182 |
|
|
183 |
Test.add_func ("/Common/Utils/parse_raw_number8", () => { |
|
184 |
var expected_val = 800; |
|
185 |
var val = FastNumber.parse_raw_number ("0.8"); |
|
186 |
|
|
187 |
if (expected_val != val) { |
|
188 |
Test.fail (); |
|
189 |
Test.message ("The raw numbers does not match the exected value."); |
|
190 |
Test.message (@"expected $expected_val, got $val"); |
|
191 |
} |
|
192 |
}); |
|
193 |
|
|
|
20
by Gustav Hartvigsson
* fixed the parsing of string in FastNumber.parse_raw_number () |
194 |
Test.add_func ("/Common/Utils/FastNumber/float", () => { |
195 |
var expected_val = 10.128; |
|
196 |
var f1 = FastNumber.from_float (expected_val); |
|
197 |
var flt = f1.float_rep; |
|
198 |
if (expected_val != flt) { |
|
199 |
Test.fail (); |
|
200 |
var raw = f1.raw_number; |
|
201 |
Test.message ("The float was not the correct value."); |
|
202 |
Test.message (@"Expected $expected_val, get $flt, Internal value: $raw "); |
|
203 |
} |
|
|
11
by Gustav Hartvigsson
* FastNumber: |
204 |
}); |
205 |
}
|