2 * Copyright (C) 2008-2012 Robert Ancell.
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License as published by the Free Software
6 * Foundation, either version 2 of the License, or (at your option) any later
7 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
11 private int number_base
= 10;
12 private int wordlen
= 32;
13 private AngleUnit angle_units
= AngleUnit
.DEGREES
;
14 private bool enable_conversions
= false;
15 private bool enable_variables
= false;
17 private int fail_count
= 0;
18 private int pass_count
= 0;
20 private string error_code_to_string (ErrorCode error
)
22 if (error
== ErrorCode
.MP
)
23 return "ErrorCode.MP(\"%s\")".printf (mp_get_error ());
25 return mp_error_code_to_string (error
);
28 private void test (string expression
, string expected
, ErrorCode expected_error
)
30 var equation
= new
TestEquation (expression
, enable_variables
, enable_conversions
);
31 equation
.base = number_base
;
32 equation
.wordlen
= wordlen
;
33 equation
.angle_units
= angle_units
;
36 var result
= equation
.parse (out error
, null);
40 if (error
== expected_error
)
42 /*stdout.printf ("PASS: '%s' -> error %s\n", expression, error_code_to_string (error));*/
45 else if (expected_error
== ErrorCode
.NONE
)
47 stdout
.printf ("*FAIL: '%s' -> error %s, expected result %s\n", expression
, error_code_to_string (error
), expected
);
52 stdout
.printf ("*FAIL: '%s' -> error %s, expected error %s\n", expression
, error_code_to_string (error
), error_code_to_string (expected_error
));
58 var serializer
= new
Serializer (DisplayFormat
.FIXED
, number_base
, 9);
59 var result_str
= serializer
.to_string (result
);
61 if (expected_error
!= ErrorCode
.NONE
)
63 stdout
.printf ("*FAIL: '%s' -> %s, expected error %s\n", expression
, result_str
, error_code_to_string (expected_error
));
66 else if (result_str
!= expected
)
68 stdout
.printf ("*FAIL: '%s' -> '%s', expected '%s'\n", expression
, result_str
, expected
);
73 /*stdout.printf ("PASS: '%s' -> '%s'\n", expression, result_str);*/
79 private class TestEquation
: Equation
81 private bool enable_variables
;
82 private bool enable_conversions
;
84 public TestEquation (string equation
, bool enable_variables
, bool enable_conversions
)
87 this
.enable_variables
= enable_variables
;
88 this
.enable_conversions
= enable_conversions
;
91 public override bool variable_is_defined (string name
)
93 if (!enable_variables
)
96 return name
== "x" || name
== "y";
99 public override Number?
get_variable (string name
)
101 if (!enable_variables
)
105 return new Number
.integer (2);
107 return new Number
.integer (3);
112 public override Number?
convert (Number x
, string x_units
, string z_units
)
114 if (!enable_conversions
)
117 return UnitManager
.get_default ().convert_by_symbol (x
, x_units
, z_units
);
121 private void test_conversions ()
125 angle_units
= AngleUnit
.DEGREES
;
126 enable_conversions
= true;
127 enable_variables
= false;
130 //test ("π radians in degrees", "180", 0);
131 test ("100 gradians in degrees", "90", 0);
134 test ("1 meter in mm", "1000", 0);
135 test ("1m in mm", "1000", 0);
136 test ("1 inch in cm", "2.54", 0);
139 test ("1m² in mm²", "1000000", 0);
142 test ("1m³ in mm³", "1000000000", 0);
145 test ("1 kg in pounds", "2.204622622", 0);
148 test ("1 minute in seconds", "60", 0);
149 test ("1s in ms", "1000", 0);
152 //test ("100˚C in ˚F", "", 0);
153 //test ("0˚C in ˚F", "32", 0);
154 //test ("0˚K in ˚C", "−273.15", 0);
155 test ("100degC in degF", "212", 0);
156 test ("0degC in degF", "32", 0);
157 test ("0 K in degC", "−273.15", 0);
160 private void test_equations ()
164 angle_units
= AngleUnit
.DEGREES
;
165 enable_conversions
= false;
166 enable_variables
= true;
169 test ("2₁₀", "10", 0);
172 test ("16434824₁₀", "76543210", 0);
175 test ("FF", "FF", 0);
176 test ("18364758544493064720₁₀", "FEDCBA9876543210", 0);
179 test ("0₂", "0", 0); test ("0₈", "0", 0); test ("0", "0", 0); test ("0₁₆", "0", 0);
180 test ("1₂", "1", 0); test ("1₈", "1", 0); test ("1", "1", 0); test ("1₁₆", "1", 0);
181 test ("2₂", "", ErrorCode
.INVALID
); test ("2₈", "2", 0); test ("2", "2", 0); test ("2₁₆", "2", 0);
182 test ("3₂", "", ErrorCode
.INVALID
); test ("3₈", "3", 0); test ("3", "3", 0); test ("3₁₆", "3", 0);
183 test ("4₂", "", ErrorCode
.INVALID
); test ("4₈", "4", 0); test ("4", "4", 0); test ("4₁₆", "4", 0);
184 test ("5₂", "", ErrorCode
.INVALID
); test ("5₈", "5", 0); test ("5", "5", 0); test ("5₁₆", "5", 0);
185 test ("6₂", "", ErrorCode
.INVALID
); test ("6₈", "6", 0); test ("6", "6", 0); test ("6₁₆", "6", 0);
186 test ("7₂", "", ErrorCode
.INVALID
); test ("7₈", "7", 0); test ("7", "7", 0); test ("7₁₆", "7", 0);
187 test ("8₂", "", ErrorCode
.INVALID
); test ("8₈", "", ErrorCode
.INVALID
); test ("8", "8", 0); test ("8₁₆", "8", 0);
188 test ("9₂", "", ErrorCode
.INVALID
); test ("9₈", "", ErrorCode
.INVALID
); test ("9", "9", 0); test ("9₁₆", "9", 0);
189 test ("A₂", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("A₈", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("A", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("A₁₆", "10", 0);
190 test ("B₂", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("B₈", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("B", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("B₁₆", "11", 0);
191 test ("C₂", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("C₈", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("C", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("C₁₆", "12", 0);
192 test ("D₂", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("D₈", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("D", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("D₁₆", "13", 0);
193 test ("E₂", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("E₈", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("E", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("E₁₆", "14", 0);
194 test ("F₂", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("F₈", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("F", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("F₁₆", "15", 0);
195 test ("a₂", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("a₈", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("a", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("a₁₆", "10", 0);
196 test ("b₂", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("b₈", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("b", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("b₁₆", "11", 0);
197 test ("c₂", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("c₈", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("c", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("c₁₆", "12", 0);
198 test ("d₂", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("d₈", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("d", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("d₁₆", "13", 0);
199 test ("e₂", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("e₈", "", ErrorCode
.UNKNOWN_VARIABLE
); /* e is a built-in variable */ test ("e₁₆", "14", 0);
200 test ("f₂", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("f₈", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("f", "", ErrorCode
.UNKNOWN_VARIABLE
); test ("f₁₆", "15", 0);
203 test ("−1", "−1", 0);
204 test ("+ 1", "1", 0); // FIXME: Should this be allowed?
205 test ("− 1", "−1", 0); // FIXME: Should this be allowed?
206 test ("++1", "1", ErrorCode
.INVALID
);
207 test ("−−1", "1", 0);
208 test ("255", "255", 0);
209 test ("256", "256", 0);
210 test ("½", "0.5", 0);
211 test ("1½", "1.5", 0);
214 test ("0°30'", "0.5", 0);
215 //test ("0°0.1'", "1", 0); // FIXME: Not yet supported
216 test ("0°0'1\"", "0.000277778", 0);
217 test ("0°0'0.1\"", "0.000027778", 0);
218 test ("1.00", "1", 0);
219 test ("1.01", "1.01", 0);
221 test ("١٢٣٤٥٦٧٨٩٠", "1234567890", 0);
222 test ("۱۲۳۴۵۶۷۸۹۰", "1234567890", 0);
225 //test ("2A", "2000000000000000", 0);
226 test ("2T", "2000000000000", 0);
227 test ("2G", "2000000000", 0);
228 test ("2M", "2000000", 0);
229 test ("2k", "2000", 0);
230 test ("2c", "0.02", 0);
231 test ("2d", "0.2", 0);
232 test ("2c", "0.02", 0);
233 test ("2m", "0.002", 0);
234 test ("2u", "0.000002", 0);
235 test ("2µ", "0.000002", 0);
236 test ("2n", "0.000000002", 0);
237 //test ("2p", "0.000000000002", 0); // FIXME: Need to print out significant figures, not decimal places
238 //test ("2f", "0.000000000000002", 0); // FIXME: Need to print out significant figures, not decimal places
239 //test ("2A3", "2300000000000000", 0);
240 test ("2T3", "2300000000000", 0);
241 test ("2G3", "2300000000", 0);
242 test ("2M3", "2300000", 0);
243 test ("2k3", "2300", 0);
244 test ("2c3", "0.023", 0);
245 test ("2d3", "0.23", 0);
246 test ("2c3", "0.023", 0);
247 test ("2m3", "0.0023", 0);
248 test ("2u3", "0.0000023", 0);
249 test ("2µ3", "0.0000023", 0);
250 //test ("2n3", "0.0000000023", 0); // FIXME: Need to print out significant figures, not decimal places
251 //test ("2p3", "0.0000000000023", 0); // FIXME: Need to print out significant figures, not decimal places
252 //test ("2f3", "0.0000000000000023", 0); // FIXME: Need to print out significant figures, not decimal places
255 test ("2×10^3", "2000", 0);
256 test ("2×10^−3", "0.002", 0);
260 test ("z", "", ErrorCode
.UNKNOWN_VARIABLE
);
262 test ("y2", "", ErrorCode
.INVALID
);
263 test ("y 2", "", ErrorCode
.INVALID
);
264 test ("2z", "", ErrorCode
.UNKNOWN_VARIABLE
);
265 test ("z2", "", ErrorCode
.UNKNOWN_VARIABLE
);
266 test ("z 2", "", ErrorCode
.UNKNOWN_VARIABLE
);
267 test ("z(2)", "", ErrorCode
.UNKNOWN_VARIABLE
);
269 test ("2y²", "18", 0);
270 test ("x×y", "6", 0);
273 test ("2xy", "12", 0);
274 test ("x²y", "12", 0);
275 test ("xy²", "18", 0);
276 test ("(xy)²", "36", 0);
277 test ("2x²y", "24", 0);
278 test ("2xy²", "36", 0);
279 test ("2x²y²", "72", 0);
280 test ("x²yx²y", "144", 0);
281 test ("x³+2x²−5", "11", 0);
282 test ("2(x+3y)", "22", 0);
283 test ("x(x+3y)", "22", 0);
284 test ("(x+3y)(2x-4y)", "−88", 0);
285 test ("2x²+2xy−12y²", "−88", 0);
287 test ("π", "3.141592654", 0);
288 test ("e", "2.718281828", 0);
290 test ("z=99", "99", 0);
291 test ("longname=99", "99", 0);
292 //test ("e=99", "", ErrorCode.BUILTIN_VARIABLE);
294 test ("0+0", "0", 0);
295 test ("1+1", "2", 0);
296 test ("1+4", "5", 0);
297 test ("4+1", "5", 0);
298 test ("40000+0.001", "40000.001", 0);
299 test ("0.001+40000", "40000.001", 0);
300 test ("2-3", "−1", 0);
301 test ("2−3", "−1", 0);
302 test ("3−2", "1", 0);
303 test ("40000−0.001", "39999.999", 0);
304 test ("0.001−40000", "−39999.999", 0);
305 test ("2*3", "6", 0);
306 test ("2×3", "6", 0);
307 test ("−2×3", "−6", 0);
308 test ("2×−3", "−6", 0);
309 test ("−2×−3", "6", 0);
310 test ("6/3", "2", 0);
311 test ("6÷3", "2", 0);
312 test ("1÷2", "0.5", 0);
313 test ("−6÷3", "−2", 0);
314 test ("6÷−3", "−2", 0);
315 test ("−6÷−3", "2", 0);
316 test ("(−3)÷(−6)", "0.5", 0);
317 test ("2÷2", "1", 0);
318 test ("1203÷1", "1203", 0);
319 test ("−0÷32352.689", "0", 0);
320 test ("1÷4", "0.25", 0);
321 test ("1÷3", "0.333333333", 0);
322 test ("2÷3", "0.666666667", 0);
323 test ("1÷0", "", ErrorCode
.MP
);
324 test ("0÷0", "", ErrorCode
.MP
);
327 test ("1000000000000000−1000000000000000", "0", 0);
328 test ("1000000000000000÷1000000000000000", "1", 0);
329 test ("1000000000000000×0.000000000000001", "1", 0);
331 /* Order of operations */
332 test ("1−0.9−0.1", "0", 0);
333 test ("1+2×3", "7", 0);
334 test ("1+(2×3)", "7", 0);
335 test ("(1+2)×3", "9", 0);
336 test ("(1+2×3)", "7", 0);
337 test ("2(1+1)", "4", 0);
338 test ("4÷2(1+1)", "4", 0);
341 test ("100%", "1", 0);
342 test ("1%", "0.01", 0);
343 test ("100+1%", "101", 0);
344 test ("100−1%", "99", 0);
345 test ("100×1%", "1", 0);
346 test ("100÷1%", "10000", 0);
351 test ("5!", "120", 0);
352 test ("69!", "171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000", 0);
353 test ("0.1!", "", ErrorCode
.MP
);
354 test ("−1!", "−1", 0);
355 test ("(−1)!", "", ErrorCode
.MP
);
356 test ("−(1!)", "−1", 0);
361 test ("2¹⁰", "1024", 0);
362 test ("(1+2)²", "9", 0);
363 test ("(x)²", "4", 0);
364 test ("|1−3|²", "4", 0);
365 test ("|x|²", "4", 0);
366 test ("0^0", "1", 0);
367 test ("0^0.5", "0", 0);
368 test ("2^0", "1", 0);
369 test ("2^1", "2", 0);
370 test ("2^2", "4", 0);
371 test ("2⁻¹", "0.5", 0);
372 test ("2⁻", "", ErrorCode
.MP
);
373 test ("2^−1", "0.5", 0);
374 test ("2^(−1)", "0.5", 0);
375 test ("x⁻¹", "0.5", 0);
376 test ("−10^2", "−100", 0);
377 test ("(−10)^2", "100", 0);
378 test ("−(10^2)", "−100", 0);
379 test ("2^100", "1267650600228229401496703205376", 0);
380 test ("4^3^2", "262144", 0);
381 test ("4^(3^2)", "262144", 0);
382 test ("(4^3)^2", "4096", 0);
384 test ("√4−2", "0", 0);
386 test ("∜16", "2", 0);
387 test ("₃√8", "2", 0);
388 test ("₁₀√1024", "2", 0);
389 test ("√(2+2)", "2", 0);
390 test ("2√4", "4", 0);
391 test ("2×√4", "4", 0);
392 test ("Sqrt (4)", "2", 0);
393 test ("Sqrt (2)", "1.414213562", 0);
394 test ("4^0.5", "2", 0);
395 test ("2^0.5", "1.414213562", 0);
396 test ("₃√−8", "−2", 0);
397 test ("(−8)^(1÷3)", "−2", 0);
399 test ("0 mod 7", "0", 0);
400 test ("6 mod 7", "6", 0);
401 test ("7 mod 7", "0", 0);
402 test ("8 mod 7", "1", 0);
403 test ("−1 mod 7", "6", 0);
405 test ("sgn 0", "0", 0);
406 test ("sgn 3", "1", 0);
407 test ("sgn −3", "−1", 0);
408 test ("⌊3⌋", "3", 0);
409 test ("⌈3⌉", "3", 0);
410 test ("[3]", "3", 0);
411 test ("⌊−3⌋", "−3", 0);
412 test ("⌈−3⌉", "−3", 0);
413 test ("[−3]", "−3", 0);
414 test ("⌊3.2⌋", "3", 0);
415 test ("⌈3.2⌉", "4", 0);
416 test ("[3.2]", "3", 0);
417 test ("⌊−3.2⌋", "−4", 0);
418 test ("⌈−3.2⌉", "−3", 0);
419 test ("[−3.2]", "−3", 0);
420 test ("⌊3.5⌋", "3", 0);
421 test ("⌈3.5⌉", "4", 0);
422 test ("[3.5]", "4", 0);
423 test ("⌊−3.5⌋", "−4", 0);
424 test ("⌈−3.5⌉", "−3", 0);
425 test ("[−3.5]", "−4", 0);
426 test ("⌊3.7⌋", "3", 0);
427 test ("⌈3.7⌉", "4", 0);
428 test ("[3.7]", "4", 0);
429 test ("⌊−3.7⌋", "−4", 0);
430 test ("⌈−3.7⌉", "−3", 0);
431 test ("[−3.7]", "−4", 0);
432 test ("{3.2}", "0.2", 0);
433 test ("{−3.2}", "0.8", 0);
435 test ("|1|", "1", 0);
436 test ("|−1|", "1", 0);
437 test ("|3−5|", "2", 0);
438 test ("|x|", "2", 0);
439 test ("abs 1", "1", 0);
440 test ("abs (−1)", "1", 0);
442 test ("log 0", "", ErrorCode
.MP
);
443 test ("log 1", "0", 0);
444 test ("log 2", "0.301029996", 0);
445 test ("log 10", "1", 0);
446 test ("log₁₀ 10", "1", 0);
447 test ("log₂ 2", "1", 0);
448 test ("2 log 2", "0.602059991", 0);
450 test ("ln 0", "", ErrorCode
.MP
);
451 test ("ln 1", "0", 0);
452 test ("ln 2", "0.693147181", 0);
453 test ("ln e", "1", 0);
454 test ("2 ln 2", "1.386294361", 0);
456 angle_units
= AngleUnit
.DEGREES
;
457 test ("sin 0", "0", 0);
458 test ("sin 45 − 1÷√2", "0", 0);
459 test ("sin 20 + sin(−20)", "0", 0);
460 test ("sin 90", "1", 0);
461 test ("sin 180", "0", 0);
462 test ("2 sin 90", "2", 0);
463 test ("sin²45", "0.5", 0);
465 test ("cos 0", "1", 0);
466 test ("cos 45 − 1÷√2", "0", 0);
467 test ("cos 20 − cos (−20)", "0", 0);
468 test ("cos 90", "0", 0);
469 test ("cos 180", "−1", 0);
470 test ("2 cos 0", "2", 0);
471 test ("cos²45", "0.5", 0);
473 test ("tan 0", "0", 0);
474 test ("tan 10 − sin 10÷cos 10", "0", 0);
475 test ("tan 90", "", ErrorCode
.MP
);
476 test ("tan 10", "0.176326981", 0);
477 test ("tan²10", "0.031091204", 0);
479 test ("cos⁻¹ 0", "90", 0);
480 test ("cos⁻¹ 1", "0", 0);
481 test ("cos⁻¹ (−1)", "180", 0);
482 test ("cos⁻¹ (1÷√2)", "45", 0);
483 test ("acos 0", "90", 0);
484 test ("acos 1", "0", 0);
486 test ("sin⁻¹ 0", "0", 0);
487 test ("sin⁻¹ 1", "90", 0);
488 test ("sin⁻¹ (−1)", "−90", 0);
489 test ("sin⁻¹ (1÷√2)", "45", 0);
490 test ("asin 0", "0", 0);
491 test ("asin 1", "90", 0);
493 test ("cosh 0", "1", 0);
494 test ("cosh 10 − (e^10 + e^−10)÷2", "0", 0);
496 test ("sinh 0", "0", 0);
497 test ("sinh 10 − (e^10 − e^−10)÷2", "0", 0);
498 test ("sinh (−10) + sinh 10", "0", 0);
500 test ("cosh² (−5) − sinh² (−5)", "1", 0);
501 test ("tanh 0", "0", 0);
502 test ("tanh 10 − sinh 10 ÷ cosh 10", "0", 0);
504 test ("atanh 0", "0", 0);
505 test ("atanh (1÷10) − 0.5 ln(11÷9)", "0", 0);
507 angle_units
= AngleUnit
.DEGREES
;
508 test ("sin 90", "1", 0);
510 angle_units
= AngleUnit
.RADIANS
;
511 test ("sin (π÷2)", "1", 0); // FIXME: Shouldn't need brackets
513 angle_units
= AngleUnit
.GRADIANS
;
514 test ("sin 100", "1", 0);
516 /* Complex numbers */
517 angle_units
= AngleUnit
.DEGREES
;
519 test ("−i", "−i", 0);
520 test ("2i", "2i", 0);
521 test ("1+i", "1+i", 0);
522 test ("i+1", "1+i", 0);
523 test ("1−i", "1−i", 0);
524 test ("i−1", "−1+i", 0);
525 test ("i×i", "−1", 0);
526 test ("i÷i", "1", 0);
527 test ("1÷i", "−i", 0);
528 test ("|i|", "1", 0);
529 test ("|3+4i|", "5", 0);
530 test ("arg 0", "", ErrorCode
.MP
);
531 test ("arg 1", "0", 0);
532 test ("arg (1+i)", "45", 0);
533 test ("arg i", "90", 0);
534 test ("arg (−1+i)", "135", 0);
535 test ("arg −1", "180", 0);
536 test ("arg (1+−i)", "−45", 0);
537 test ("arg −i", "−90", 0);
538 test ("arg (−1−i)", "−135", 0);
539 test ("i⁻¹", "−i", 0);
540 test ("√−1", "i", 0);
541 test ("(−1)^0.5", "i", 0);
542 test ("√−4", "2i", 0);
543 test ("e^iπ", "−1", 0);
544 test ("log (−10) − (1 + πi÷ln(10))", "0", 0);
545 test ("ln (−e) − (1 + πi)", "0", 0);
546 test ("sin(iπ÷4) − i×sinh(π÷4)", "0", 0);
547 test ("cos(iπ÷4) − cosh(π÷4)", "0", 0);
550 test ("0 and 0", "0", 0);
551 test ("1 and 0", "0", 0);
552 test ("0 and 1", "0", 0);
553 test ("1 and 1", "1", 0);
554 test ("3 and 5", "1", 0);
556 test ("0 or 0", "0", 0);
557 test ("1 or 0", "1", 0);
558 test ("0 or 1", "1", 0);
559 test ("1 or 1", "1", 0);
560 test ("3 or 5", "7", 0);
562 test ("0 xor 0", "0", 0);
563 test ("1 xor 0", "1", 0);
564 test ("0 xor 1", "1", 0);
565 test ("1 xor 1", "0", 0);
566 test ("3 xor 5", "6", 0);
569 test ("ones 1", "FFFFFFFE", 0);
570 test ("ones 7FFFFFFF", "80000000", 0);
571 test ("twos 1", "FFFFFFFF", 0);
572 test ("twos 7FFFFFFF", "80000001", 0);
573 test ("~7A₁₆", "FFFFFF85", 0);
577 test ("1100∧1010", "1000", 0);
578 test ("1100∨1010", "1110", 0);
579 test ("1100⊻1010", "110", 0);
580 test ("1100⊕1010", "110", 0);
581 //test ("1100⊼1010", "0111", 0);
582 //test ("1100⊽1010", "0001", 0);
584 //test ("¬01₂", "10₂", 0);
585 //test ("¬¬10₂", "10₂", 0);
588 public int main (string args
[])
590 Intl
.setlocale (LocaleCategory
.ALL
, "C");
596 stdout
.printf ("Passed all %i tests\n", pass_count
);
598 stdout
.printf ("Failed %i/%d tests\n", fail_count
, pass_count
+ fail_count
);