1 use fend_core::{evaluate, Context};
2
3 #[track_caller]
test_serialization_roundtrip(context: &mut Context)4 fn test_serialization_roundtrip(context: &mut Context) {
5 let mut v = vec![];
6 context.serialize_variables(&mut v).unwrap();
7 let ctx_debug_repr = format!("{context:#?}");
8 match context.deserialize_variables(&mut v.as_slice()) {
9 Ok(()) => (),
10 Err(s) => {
11 eprintln!("Data: {:?}", &v);
12 eprintln!("Context: {ctx_debug_repr}");
13 panic!("Failed to deserialize: {s}");
14 }
15 }
16 }
17
18 #[track_caller]
test_eval_simple(input: &str, expected: &str)19 fn test_eval_simple(input: &str, expected: &str) {
20 let mut context = Context::new();
21 context.set_exchange_rate_handler_v1(fend_core::test_utils::dummy_currency_handler);
22 assert_eq!(
23 evaluate(input, &mut context).unwrap().get_main_result(),
24 expected
25 );
26 if let Ok(res) = evaluate(expected, &mut context) {
27 assert_ne!(res.get_main_result(), expected);
28 }
29 test_serialization_roundtrip(&mut context);
30 }
31
32 #[track_caller]
test_eval(input: &str, expected: &str)33 fn test_eval(input: &str, expected: &str) {
34 let mut context = Context::new();
35 context.set_exchange_rate_handler_v1(fend_core::test_utils::dummy_currency_handler);
36 assert_eq!(
37 evaluate(input, &mut context).unwrap().get_main_result(),
38 expected
39 );
40 // try parsing the output again, and make sure it matches
41 assert_eq!(
42 evaluate(expected, &mut context).unwrap().get_main_result(),
43 expected
44 );
45 test_serialization_roundtrip(&mut context);
46 }
47
48 #[track_caller]
expect_error(input: &str, error_message: Option<&str>)49 fn expect_error(input: &str, error_message: Option<&str>) {
50 let mut context = Context::new();
51 if let Some(error_message) = error_message {
52 assert_eq!(
53 evaluate(input, &mut context),
54 Err(error_message.to_string())
55 );
56 } else {
57 assert!(evaluate(input, &mut context).is_err());
58 }
59 }
60
61 #[test]
two()62 fn two() {
63 test_eval("2", "2");
64 }
65
66 #[test]
nine()67 fn nine() {
68 test_eval("9", "9");
69 }
70
71 #[test]
ten()72 fn ten() {
73 test_eval("10", "10");
74 }
75
76 #[test]
large_integer()77 fn large_integer() {
78 test_eval("39456720983475234523452345", "39456720983475234523452345");
79 }
80
81 #[test]
ten_whitespace_after()82 fn ten_whitespace_after() {
83 test_eval("10 ", "10");
84 }
85
86 #[test]
ten_whitespace_before()87 fn ten_whitespace_before() {
88 test_eval(" 10", "10");
89 }
90
91 #[test]
ten_whitespace_both()92 fn ten_whitespace_both() {
93 test_eval(" 10\n\r\n", "10");
94 }
95
96 #[test]
blank_input()97 fn blank_input() {
98 test_eval("", "");
99 }
100
101 #[test]
version()102 fn version() {
103 let mut ctx = Context::new();
104 let result = evaluate("version", &mut ctx).unwrap();
105 for c in result.get_main_result().chars() {
106 assert!(c.is_ascii_digit() || c == '.');
107 }
108 }
109
110 #[test]
pi()111 fn pi() {
112 test_eval("pi", "approx. 3.1415926535");
113 }
114
115 #[test]
pi_times_two()116 fn pi_times_two() {
117 test_eval("pi * 2", "approx. 6.2831853071");
118 }
119
120 #[test]
two_pi()121 fn two_pi() {
122 test_eval("2 pi", "approx. 6.2831853071");
123 }
124
125 #[test]
pi_to_fraction()126 fn pi_to_fraction() {
127 let mut ctx = Context::new();
128 assert!(evaluate("pi to fraction", &mut ctx)
129 .unwrap()
130 .get_main_result()
131 .starts_with("approx."));
132 }
133
134 const DIVISION_BY_ZERO_ERROR: &str = "division by zero";
135 #[test]
one_over_zero()136 fn one_over_zero() {
137 expect_error("1/0", Some(DIVISION_BY_ZERO_ERROR));
138 }
139
140 #[test]
zero_over_zero()141 fn zero_over_zero() {
142 expect_error("0/0", Some(DIVISION_BY_ZERO_ERROR));
143 }
144
145 #[test]
minus_one_over_zero()146 fn minus_one_over_zero() {
147 expect_error("-1/0", Some(DIVISION_BY_ZERO_ERROR));
148 }
149
150 #[test]
three_pi_over_zero_pi()151 fn three_pi_over_zero_pi() {
152 expect_error("(3pi) / (0pi)", Some(DIVISION_BY_ZERO_ERROR));
153 }
154
155 #[test]
minus_one_over_zero_indirect()156 fn minus_one_over_zero_indirect() {
157 expect_error("-1/(2-2)", Some(DIVISION_BY_ZERO_ERROR));
158 }
159
160 #[test]
two_zeroes()161 fn two_zeroes() {
162 test_eval("00", "0");
163 }
164
165 #[test]
six_zeroes()166 fn six_zeroes() {
167 test_eval("000000", "0");
168 }
169
170 #[test]
multiple_zeroes_with_decimal_point()171 fn multiple_zeroes_with_decimal_point() {
172 test_eval("000000.01", "0.01");
173 }
174
175 #[test]
leading_zeroes_and_decimal_point()176 fn leading_zeroes_and_decimal_point() {
177 test_eval("0000001.01", "1.01");
178 }
179
180 #[test]
binary_leading_zeroes()181 fn binary_leading_zeroes() {
182 test_eval("0b01", "0b1");
183 }
184
185 #[test]
hex_leading_zeroes()186 fn hex_leading_zeroes() {
187 test_eval("0x0000_00ff", "0xff");
188 }
189
190 #[test]
explicit_base_10_leading_zeroes()191 fn explicit_base_10_leading_zeroes() {
192 test_eval("10#04", "10#4");
193 }
194
195 #[test]
leading_zeroes_after_decimal_point()196 fn leading_zeroes_after_decimal_point() {
197 test_eval("1.001", "1.001");
198 }
199
200 #[test]
leading_zeroes_in_exponent()201 fn leading_zeroes_in_exponent() {
202 test_eval("1e01", "10");
203 }
204
205 #[test]
leading_zeroes_in_negative_exponent()206 fn leading_zeroes_in_negative_exponent() {
207 test_eval("1e-01", "0.1");
208 }
209
210 #[test]
upper_case_exponent()211 fn upper_case_exponent() {
212 test_eval("1E3", "1000");
213 }
214
215 #[test]
upper_case_big_exponent()216 fn upper_case_big_exponent() {
217 test_eval("1E10", "10000000000");
218 }
219
220 #[test]
upper_case_neg_exponent()221 fn upper_case_neg_exponent() {
222 test_eval("1E-3", "0.001");
223 }
224
225 #[test]
upper_case_binary_exponent()226 fn upper_case_binary_exponent() {
227 test_eval("0b10E100 to decimal", "32");
228 }
229
230 #[test]
no_recurring_digits()231 fn no_recurring_digits() {
232 expect_error("0.()", None);
233 }
234
235 #[test]
to_float_1()236 fn to_float_1() {
237 test_eval_simple("0.(3) to float", "0.(3)");
238 }
239
240 #[test]
to_float_2()241 fn to_float_2() {
242 test_eval_simple("0.(33) to float", "0.(3)");
243 }
244
245 #[test]
to_float_3()246 fn to_float_3() {
247 test_eval_simple("0.(34) to float", "0.(34)");
248 }
249
250 #[test]
to_float_4()251 fn to_float_4() {
252 test_eval_simple("0.(12345) to float", "0.(12345)");
253 }
254
255 #[test]
to_float_5()256 fn to_float_5() {
257 test_eval("0.(0) to float", "0");
258 }
259
260 #[test]
to_float_6()261 fn to_float_6() {
262 test_eval("0.123(00) to float", "0.123");
263 }
264
265 #[test]
to_float_7()266 fn to_float_7() {
267 test_eval_simple("0.0(34) to float", "0.0(34)");
268 }
269
270 #[test]
to_float_8()271 fn to_float_8() {
272 test_eval_simple("0.00(34) to float", "0.00(34)");
273 }
274
275 #[test]
to_float_9()276 fn to_float_9() {
277 test_eval_simple("0.0000(34) to float", "0.0000(34)");
278 }
279
280 #[test]
to_float_10()281 fn to_float_10() {
282 test_eval_simple("0.123434(34) to float", "0.12(34)");
283 }
284
285 #[test]
to_float_11()286 fn to_float_11() {
287 test_eval_simple("0.123434(34)i to float", "0.12(34)i");
288 }
289
290 #[test]
to_float_12()291 fn to_float_12() {
292 test_eval_simple("0.(3) + 0.123434(34)i to float", "0.(3) + 0.12(34)i");
293 }
294
295 #[test]
to_float_13()296 fn to_float_13() {
297 test_eval_simple("6#0.(1) to float", "6#0.(1)");
298 }
299
300 #[test]
to_float_14()301 fn to_float_14() {
302 test_eval("6#0.(1) to float in base 10", "0.2");
303 }
304
305 #[test]
two_times_two()306 fn two_times_two() {
307 test_eval("2*2", "4");
308 }
309
310 #[test]
two_times_two_whitespace()311 fn two_times_two_whitespace() {
312 test_eval("\n2\n*\n2\n", "4");
313 }
314
315 #[test]
large_multiplication()316 fn large_multiplication() {
317 test_eval(
318 "315427679023453451289740 * 927346502937456234523452",
319 "292510755072077978255166497050046859223676982480",
320 );
321 }
322
323 #[test]
pi_times_pi()324 fn pi_times_pi() {
325 test_eval("pi * pi", "approx. 9.869604401");
326 }
327
328 #[test]
four_pi_plus_one()329 fn four_pi_plus_one() {
330 test_eval("4pi + 1", "approx. 13.5663706143");
331 }
332
333 #[test]
implicit_lambda_1()334 fn implicit_lambda_1() {
335 test_eval("-sin (-pi/2)", "1");
336 }
337
338 #[test]
implicit_lambda_2()339 fn implicit_lambda_2() {
340 test_eval("+sin (-pi/2)", "-1");
341 }
342
343 #[test]
implicit_lambda_3()344 fn implicit_lambda_3() {
345 test_eval("/sin (-pi/2)", "-1");
346 }
347
348 #[test]
implicit_lambda_4()349 fn implicit_lambda_4() {
350 test_eval("cos! 0", "1");
351 }
352
353 #[test]
implicit_lambda_5()354 fn implicit_lambda_5() {
355 test_eval("sqrt! 16", "24");
356 }
357
358 #[test]
implicit_lambda_6()359 fn implicit_lambda_6() {
360 test_eval("///sqrt! 16", "approx. 0.0416666666");
361 }
362
363 #[test]
implicit_lambda_7()364 fn implicit_lambda_7() {
365 test_eval("(x: sin^2 x + cos^2 x) 1", "approx. 1");
366 }
367
368 #[test]
implicit_lambda_8()369 fn implicit_lambda_8() {
370 test_eval("cos^2 pi", "1");
371 }
372
373 #[test]
implicit_lambda_9()374 fn implicit_lambda_9() {
375 test_eval("sin pi/cos pi", "0");
376 }
377
378 #[test]
implicit_lambda_10()379 fn implicit_lambda_10() {
380 test_eval("sin + 1) pi", "1");
381 }
382
383 #[test]
implicit_lambda_11()384 fn implicit_lambda_11() {
385 test_eval("3sin pi", "0");
386 }
387
388 #[test]
implicit_lambda_12()389 fn implicit_lambda_12() {
390 test_eval("(-sqrt) 4", "-2");
391 }
392
393 #[test]
394 #[ignore]
implicit_lambda_13()395 fn implicit_lambda_13() {
396 test_eval("-sqrt 4", "-2");
397 }
398
399 #[test]
inverse_sin()400 fn inverse_sin() {
401 test_eval("sin^-1", "asin");
402 }
403
404 #[test]
inverse_sin_point_five()405 fn inverse_sin_point_five() {
406 test_eval("sin^-1 0.5", "approx. 0.5235987755");
407 }
408
409 #[test]
inverse_sin_nested()410 fn inverse_sin_nested() {
411 test_eval("sin^-1 (sin 0.5", "approx. 0.5");
412 }
413
414 #[test]
inverse_sin_nested_2()415 fn inverse_sin_nested_2() {
416 test_eval("(sin^-1)^-1", "sin");
417 }
418
419 #[test]
inverse_cos()420 fn inverse_cos() {
421 test_eval("cos^-1", "acos");
422 }
423
424 #[test]
inverse_tan()425 fn inverse_tan() {
426 test_eval("tan^-1", "atan");
427 }
428
429 #[test]
inverse_asin()430 fn inverse_asin() {
431 test_eval("asin^-1", "sin");
432 }
433
434 #[test]
inverse_acos()435 fn inverse_acos() {
436 test_eval("acos^-1", "cos");
437 }
438
439 #[test]
inverse_atan()440 fn inverse_atan() {
441 test_eval("atan^-1", "tan");
442 }
443
444 #[test]
inverse_sinh()445 fn inverse_sinh() {
446 test_eval("sinh^-1", "asinh");
447 }
448
449 #[test]
inverse_cosh()450 fn inverse_cosh() {
451 test_eval("cosh^-1", "acosh");
452 }
453
454 #[test]
inverse_tanh()455 fn inverse_tanh() {
456 test_eval("tanh^-1", "atanh");
457 }
458
459 #[test]
inverse_asinh()460 fn inverse_asinh() {
461 test_eval("asinh^-1", "sinh");
462 }
463
464 #[test]
inverse_acosh()465 fn inverse_acosh() {
466 test_eval("acosh^-1", "cosh");
467 }
468
469 #[test]
inverse_atanh()470 fn inverse_atanh() {
471 test_eval("atanh^-1", "tanh");
472 }
473
474 #[test]
two_plus_two()475 fn two_plus_two() {
476 test_eval("2+2", "4");
477 }
478
479 #[test]
two_plus_two_whitespace()480 fn two_plus_two_whitespace() {
481 test_eval("\n2\n+\n2\n", "4");
482 }
483
484 #[test]
plus_two()485 fn plus_two() {
486 test_eval("+2", "2");
487 }
488
489 #[test]
unary_pluses_two()490 fn unary_pluses_two() {
491 test_eval("++++2", "2");
492 }
493
494 #[test]
large_simple_addition()495 fn large_simple_addition() {
496 test_eval(
497 "315427679023453451289740 + 927346502937456234523452",
498 "1242774181960909685813192",
499 );
500 }
501
502 #[test]
minus_zero()503 fn minus_zero() {
504 test_eval("-0", "0");
505 }
506
507 #[test]
two_minus_two()508 fn two_minus_two() {
509 test_eval("2-2", "0");
510 }
511
512 #[test]
three_minus_two()513 fn three_minus_two() {
514 test_eval("3-2", "1");
515 }
516
517 #[test]
two_minus_three()518 fn two_minus_three() {
519 test_eval("2-3", "-1");
520 }
521
522 #[test]
minus_two()523 fn minus_two() {
524 test_eval("-2", "-2");
525 }
526
527 #[test]
minus_minus_two()528 fn minus_minus_two() {
529 test_eval("--2", "2");
530 }
531
532 #[test]
minus_minus_minus_two()533 fn minus_minus_minus_two() {
534 test_eval("---2", "-2");
535 }
536
537 #[test]
minus_minus_minus_two_parens()538 fn minus_minus_minus_two_parens() {
539 test_eval("-(--2)", "-2");
540 }
541
542 #[test]
two_minus_64()543 fn two_minus_64() {
544 test_eval("\n2\n-\n64\n", "-62");
545 }
546
547 #[test]
large_simple_subtraction()548 fn large_simple_subtraction() {
549 test_eval(
550 "315427679023453451289740 - 927346502937456234523452",
551 "-611918823914002783233712",
552 );
553 }
554
555 #[test]
three_pi_minus_two_pi()556 fn three_pi_minus_two_pi() {
557 test_eval("3pi - 2pi", "approx. 3.1415926535");
558 }
559
560 #[test]
four_pi_plus_one_over_pi()561 fn four_pi_plus_one_over_pi() {
562 test_eval("4pi-1)/pi", "approx. 3.6816901138");
563 }
564
565 #[test]
large_simple_subtraction_2()566 fn large_simple_subtraction_2() {
567 test_eval(
568 "36893488123704996004 - 18446744065119617025",
569 "18446744058585378979",
570 );
571 }
572
573 #[test]
sqrt_half()574 fn sqrt_half() {
575 test_eval("sqrt (1/2)", "approx. 0.7071067814");
576 }
577
578 #[test]
sqrt_0()579 fn sqrt_0() {
580 test_eval("sqrt 0", "0");
581 }
582
583 #[test]
sqrt_1()584 fn sqrt_1() {
585 test_eval("sqrt 1", "1");
586 }
587
588 #[test]
sqrt_2()589 fn sqrt_2() {
590 test_eval("sqrt 2", "approx. 1.4142135619");
591 }
592
593 #[test]
sqrt_pi()594 fn sqrt_pi() {
595 test_eval("sqrt pi", "approx. 1.7724538509");
596 }
597
598 #[test]
sqrt_4()599 fn sqrt_4() {
600 test_eval("sqrt 4", "2");
601 }
602
603 #[test]
sqrt_9()604 fn sqrt_9() {
605 test_eval("sqrt 9", "3");
606 }
607
608 #[test]
sqrt_16()609 fn sqrt_16() {
610 test_eval("sqrt 16", "4");
611 }
612
613 #[test]
sqrt_25()614 fn sqrt_25() {
615 test_eval("sqrt 25", "5");
616 }
617
618 #[test]
sqrt_36()619 fn sqrt_36() {
620 test_eval("sqrt 36", "6");
621 }
622
623 #[test]
sqrt_49()624 fn sqrt_49() {
625 test_eval("sqrt 49", "7");
626 }
627
628 #[test]
sqrt_64()629 fn sqrt_64() {
630 test_eval("sqrt 64", "8");
631 }
632
633 #[test]
sqrt_81()634 fn sqrt_81() {
635 test_eval("sqrt 81", "9");
636 }
637
638 #[test]
sqrt_100()639 fn sqrt_100() {
640 test_eval("sqrt 100", "10");
641 }
642
643 #[test]
sqrt_10000()644 fn sqrt_10000() {
645 test_eval("sqrt 10000", "100");
646 }
647
648 #[test]
sqrt_1000000()649 fn sqrt_1000000() {
650 test_eval("sqrt 1000000", "1000");
651 }
652
653 #[test]
sqrt_quarter()654 fn sqrt_quarter() {
655 test_eval("sqrt 0.25", "0.5");
656 }
657
658 #[test]
sqrt_sixteenth()659 fn sqrt_sixteenth() {
660 test_eval("sqrt 0.0625", "0.25");
661 }
662
663 #[test]
cbrt_0()664 fn cbrt_0() {
665 test_eval("cbrt 0", "0");
666 }
667
668 #[test]
cbrt_1()669 fn cbrt_1() {
670 test_eval("cbrt 1", "1");
671 }
672
673 #[test]
cbrt_8()674 fn cbrt_8() {
675 test_eval("cbrt 8", "2");
676 }
677
678 #[test]
cbrt_27()679 fn cbrt_27() {
680 test_eval("cbrt 27", "3");
681 }
682
683 #[test]
cbrt_64()684 fn cbrt_64() {
685 test_eval("cbrt 64", "4");
686 }
687
688 #[test]
cbrt_eighth()689 fn cbrt_eighth() {
690 test_eval("cbrt (1/8)", "0.5");
691 }
692
693 #[test]
cbrt_1_over_125()694 fn cbrt_1_over_125() {
695 test_eval("cbrt (125/8)", "2.5");
696 }
697
698 #[test]
sqrt_kg_squared_1()699 fn sqrt_kg_squared_1() {
700 test_eval("sqrt(kg^2)", "1 kg");
701 }
702
703 #[test]
sqrt_kg_squared_2()704 fn sqrt_kg_squared_2() {
705 test_eval("(sqrt kg)^2", "1 kg");
706 }
707
708 #[test]
lightyear_to_parsecs()709 fn lightyear_to_parsecs() {
710 test_eval("1 lightyear to parsecs", "approx. 0.3066013937 parsecs");
711 }
712
713 #[test]
order_of_operations_1()714 fn order_of_operations_1() {
715 test_eval("2+2*3", "8");
716 }
717
718 #[test]
order_of_operations_2()719 fn order_of_operations_2() {
720 test_eval("2*2+3", "7");
721 }
722
723 #[test]
order_of_operations_3()724 fn order_of_operations_3() {
725 test_eval("2+2+3", "7");
726 }
727
728 #[test]
order_of_operations_4()729 fn order_of_operations_4() {
730 test_eval("2+2-3", "1");
731 }
732
733 #[test]
order_of_operations_5()734 fn order_of_operations_5() {
735 test_eval("2-2+3", "3");
736 }
737
738 #[test]
order_of_operations_6()739 fn order_of_operations_6() {
740 test_eval("2-2-3", "-3");
741 }
742
743 #[test]
order_of_operations_7()744 fn order_of_operations_7() {
745 test_eval("2*2*3", "12");
746 }
747
748 #[test]
order_of_operations_8()749 fn order_of_operations_8() {
750 test_eval("2*2*-3", "-12");
751 }
752
753 #[test]
order_of_operations_9()754 fn order_of_operations_9() {
755 test_eval("2*-2*3", "-12");
756 }
757
758 #[test]
order_of_operations_10()759 fn order_of_operations_10() {
760 test_eval("-2*2*3", "-12");
761 }
762
763 #[test]
order_of_operations_11()764 fn order_of_operations_11() {
765 test_eval("-2*-2*3", "12");
766 }
767
768 #[test]
order_of_operations_12()769 fn order_of_operations_12() {
770 test_eval("-2*2*-3", "12");
771 }
772
773 #[test]
order_of_operations_13()774 fn order_of_operations_13() {
775 test_eval("2*-2*-3", "12");
776 }
777
778 #[test]
order_of_operations_14()779 fn order_of_operations_14() {
780 test_eval("-2*-2*-3", "-12");
781 }
782
783 #[test]
order_of_operations_15()784 fn order_of_operations_15() {
785 test_eval("-2*-2*-3/2", "-6");
786 }
787
788 #[test]
order_of_operations_16()789 fn order_of_operations_16() {
790 test_eval("-2*-2*-3/-2", "6");
791 }
792
793 #[test]
order_of_operations_17()794 fn order_of_operations_17() {
795 test_eval("-3 -1/2", "-3.5");
796 }
797
798 #[test]
yobibyte()799 fn yobibyte() {
800 test_eval("1 YiB to bytes", "1208925819614629174706176 bytes");
801 }
802
803 #[test]
div_1_over_1()804 fn div_1_over_1() {
805 test_eval("1/1", "1");
806 }
807
808 #[test]
div_1_over_2()809 fn div_1_over_2() {
810 test_eval("1/2", "0.5");
811 }
812
813 #[test]
div_1_over_4()814 fn div_1_over_4() {
815 test_eval("1/4", "0.25");
816 }
817
818 #[test]
div_1_over_8()819 fn div_1_over_8() {
820 test_eval("1/8", "0.125");
821 }
822
823 #[test]
div_1_over_16()824 fn div_1_over_16() {
825 test_eval("1/16", "0.0625");
826 }
827
828 #[test]
div_1_over_32()829 fn div_1_over_32() {
830 test_eval("1/32", "0.03125");
831 }
832
833 #[test]
div_1_over_64()834 fn div_1_over_64() {
835 test_eval("1/64", "0.015625");
836 }
837
838 #[test]
div_2_over_64()839 fn div_2_over_64() {
840 test_eval("2/64", "0.03125");
841 }
842
843 #[test]
div_4_over_64()844 fn div_4_over_64() {
845 test_eval("4/64", "0.0625");
846 }
847
848 #[test]
div_8_over_64()849 fn div_8_over_64() {
850 test_eval("8/64", "0.125");
851 }
852
853 #[test]
div_16_over_64()854 fn div_16_over_64() {
855 test_eval("16/64", "0.25");
856 }
857
858 #[test]
div_32_over_64()859 fn div_32_over_64() {
860 test_eval("32/64", "0.5");
861 }
862
863 #[test]
div_64_over_64()864 fn div_64_over_64() {
865 test_eval("64/64", "1");
866 }
867
868 #[test]
div_2_over_1()869 fn div_2_over_1() {
870 test_eval("2/1", "2");
871 }
872
873 #[test]
div_27_over_3()874 fn div_27_over_3() {
875 test_eval("27/3", "9");
876 }
877
878 #[test]
div_100_over_4()879 fn div_100_over_4() {
880 test_eval("100/4", "25");
881 }
882
883 #[test]
div_100_over_5()884 fn div_100_over_5() {
885 test_eval("100/5", "20");
886 }
887
888 #[test]
div_large_1()889 fn div_large_1() {
890 test_eval("18446744073709551616/2", "9223372036854775808");
891 }
892
893 #[test]
div_large_2()894 fn div_large_2() {
895 test_eval(
896 "184467440737095516160000000000000/2",
897 "92233720368547758080000000000000",
898 );
899 }
900
901 #[test]
div_exact_pi()902 fn div_exact_pi() {
903 test_eval("(3pi) / (2pi)", "1.5");
904 }
905
906 #[test]
zero_point_zero()907 fn zero_point_zero() {
908 test_eval("0.0", "0");
909 }
910
911 #[test]
zero_point_multiple_zeroes()912 fn zero_point_multiple_zeroes() {
913 test_eval("0.000000", "0");
914 }
915
916 #[test]
zero_point_zero_one()917 fn zero_point_zero_one() {
918 test_eval("0.01", "0.01");
919 }
920
921 #[test]
zero_point_zero_one_zeroes()922 fn zero_point_zero_one_zeroes() {
923 test_eval("0.01000", "0.01");
924 }
925
926 #[test]
zero_point_two_five()927 fn zero_point_two_five() {
928 test_eval("0.25", "0.25");
929 }
930
931 #[test]
one_point()932 fn one_point() {
933 expect_error("1.", None);
934 }
935
936 #[test]
point_one()937 fn point_one() {
938 test_eval(".1", "0.1");
939 }
940
941 #[test]
point_one_e_minus_one()942 fn point_one_e_minus_one() {
943 test_eval(".1e-1", "0.01");
944 }
945
946 #[test]
leading_zeroes_with_dp()947 fn leading_zeroes_with_dp() {
948 test_eval("001.01000", "1.01");
949 }
950
951 #[test]
very_long_decimal()952 fn very_long_decimal() {
953 test_eval(
954 "0.251974862348971623412341534273261435",
955 "0.251974862348971623412341534273261435",
956 );
957 }
958
959 #[test]
one_point_zeroes_1_as_1_dp()960 fn one_point_zeroes_1_as_1_dp() {
961 test_eval("1.00000001 as 1 dp", "approx. 1");
962 }
963
964 #[test]
one_point_zeroes_1_as_2_dp()965 fn one_point_zeroes_1_as_2_dp() {
966 test_eval("1.00000001 as 2 dp", "approx. 1");
967 }
968
969 #[test]
one_point_zeroes_1_as_3_dp()970 fn one_point_zeroes_1_as_3_dp() {
971 test_eval("1.00000001 as 3 dp", "approx. 1");
972 }
973
974 #[test]
one_point_zeroes_1_as_4_dp()975 fn one_point_zeroes_1_as_4_dp() {
976 test_eval("1.00000001 as 4 dp", "approx. 1");
977 }
978
979 #[test]
one_point_zeroes_1_as_10_dp()980 fn one_point_zeroes_1_as_10_dp() {
981 test_eval("1.00000001 as 10 dp", "1.00000001");
982 }
983
984 #[test]
one_point_zeroes_1_as_30_dp()985 fn one_point_zeroes_1_as_30_dp() {
986 test_eval("1.00000001 as 30 dp", "1.00000001");
987 }
988
989 #[test]
one_point_zeroes_1_as_1000_dp()990 fn one_point_zeroes_1_as_1000_dp() {
991 test_eval("1.00000001 as 1000 dp", "1.00000001");
992 }
993
994 #[test]
one_point_zeroes_1_as_0_dp()995 fn one_point_zeroes_1_as_0_dp() {
996 test_eval("1.00000001 as 0 dp", "approx. 1");
997 }
998
999 #[test]
point_1_zero_recurring()1000 fn point_1_zero_recurring() {
1001 test_eval(".1(0)", "0.1");
1002 }
1003
1004 #[test]
recurring_product_whitespace_1()1005 fn recurring_product_whitespace_1() {
1006 test_eval(".1( 0)", "0");
1007 }
1008
1009 #[test]
recurring_product_whitespace_2()1010 fn recurring_product_whitespace_2() {
1011 test_eval(".1 ( 0)", "0");
1012 }
1013
1014 #[test]
point_1_zero_recurring_whitespace_error()1015 fn point_1_zero_recurring_whitespace_error() {
1016 expect_error(".1(0 )", None);
1017 }
1018
1019 #[test]
point_1_zero_recurring_letters_error()1020 fn point_1_zero_recurring_letters_error() {
1021 expect_error(".1(0a)", None);
1022 }
1023
1024 #[test]
recurring_product_with_e()1025 fn recurring_product_with_e() {
1026 test_eval("2.0(e)", "approx. 5.4365636569");
1027 }
1028
1029 #[test]
recurring_product_with_function()1030 fn recurring_product_with_function() {
1031 test_eval("2.0(ln 5)", "approx. 3.2188758248");
1032 }
1033
1034 #[test]
integer_product_whitespace_1()1035 fn integer_product_whitespace_1() {
1036 test_eval("2 (5)", "10");
1037 }
1038
1039 #[test]
integer_product_whitespace_2()1040 fn integer_product_whitespace_2() {
1041 test_eval("2( 5)", "10");
1042 }
1043
1044 #[test]
large_division()1045 fn large_division() {
1046 test_eval(
1047 "60153992292001127921539815855494266880 / 9223372036854775808",
1048 "6521908912666391110",
1049 );
1050 }
1051
1052 #[test]
parentheses_1()1053 fn parentheses_1() {
1054 test_eval("(1)", "1");
1055 }
1056
1057 #[test]
parentheses_2()1058 fn parentheses_2() {
1059 test_eval("(0.0)", "0");
1060 }
1061
1062 #[test]
parentheses_3()1063 fn parentheses_3() {
1064 test_eval("(1+-2)", "-1");
1065 }
1066
1067 #[test]
parentheses_4()1068 fn parentheses_4() {
1069 test_eval("1+2*3", "7");
1070 }
1071
1072 #[test]
parentheses_5()1073 fn parentheses_5() {
1074 test_eval("(1+2)*3", "9");
1075 }
1076
1077 #[test]
parentheses_6()1078 fn parentheses_6() {
1079 test_eval("((1+2))*3", "9");
1080 }
1081
1082 #[test]
parentheses_7()1083 fn parentheses_7() {
1084 test_eval("((1)+2)*3", "9");
1085 }
1086
1087 #[test]
parentheses_8()1088 fn parentheses_8() {
1089 test_eval("(1+(2))*3", "9");
1090 }
1091
1092 #[test]
parentheses_9()1093 fn parentheses_9() {
1094 test_eval("(1+(2)*3)", "7");
1095 }
1096
1097 #[test]
parentheses_10()1098 fn parentheses_10() {
1099 test_eval("1+(2*3)", "7");
1100 }
1101
1102 #[test]
parentheses_11()1103 fn parentheses_11() {
1104 test_eval("1+((2 )*3)", "7");
1105 }
1106
1107 #[test]
parentheses_12()1108 fn parentheses_12() {
1109 test_eval(" 1 + ( (\r\n2 ) * 3 ) ", "7");
1110 }
1111
1112 #[test]
parentheses_13()1113 fn parentheses_13() {
1114 test_eval("2*(1+3", "8");
1115 }
1116
1117 #[test]
parentheses_14()1118 fn parentheses_14() {
1119 test_eval("4+5+6)*(1+2", "45");
1120 }
1121
1122 #[test]
parentheses_15()1123 fn parentheses_15() {
1124 test_eval("4+5+6))*(1+2", "45");
1125 }
1126
1127 #[test]
powers_1()1128 fn powers_1() {
1129 test_eval("1^1", "1");
1130 }
1131
1132 #[test]
powers_2()1133 fn powers_2() {
1134 test_eval("1**1", "1");
1135 }
1136
1137 #[test]
powers_3()1138 fn powers_3() {
1139 test_eval("1**1.0", "1");
1140 }
1141
1142 #[test]
powers_4()1143 fn powers_4() {
1144 test_eval("1.0**1", "1");
1145 }
1146
1147 #[test]
powers_5()1148 fn powers_5() {
1149 test_eval("2^4", "16");
1150 }
1151
1152 #[test]
powers_6()1153 fn powers_6() {
1154 test_eval("4^2", "16");
1155 }
1156
1157 #[test]
powers_7()1158 fn powers_7() {
1159 test_eval("4^3", "64");
1160 }
1161
1162 #[test]
powers_8()1163 fn powers_8() {
1164 test_eval("4^(3^1)", "64");
1165 }
1166
1167 #[test]
powers_9()1168 fn powers_9() {
1169 test_eval("4^3^1", "64");
1170 }
1171
1172 #[test]
powers_10()1173 fn powers_10() {
1174 test_eval("(4^3)^1", "64");
1175 }
1176
1177 #[test]
powers_11()1178 fn powers_11() {
1179 test_eval("(2^3)^4", "4096");
1180 }
1181
1182 #[test]
powers_12()1183 fn powers_12() {
1184 test_eval("2^3^2", "512");
1185 }
1186
1187 #[test]
powers_13()1188 fn powers_13() {
1189 test_eval("(2^3)^2", "64");
1190 }
1191
1192 #[test]
powers_14()1193 fn powers_14() {
1194 test_eval("4^0.5", "2");
1195 }
1196
1197 #[test]
powers_15()1198 fn powers_15() {
1199 test_eval("4^(1/2)", "2");
1200 }
1201
1202 #[test]
powers_16()1203 fn powers_16() {
1204 test_eval("4^(1/4)", "approx. 1.4142135619");
1205 }
1206
1207 #[test]
powers_17()1208 fn powers_17() {
1209 test_eval("(2/3)^(4/5)", "approx. 0.7229811807");
1210 }
1211
1212 #[test]
powers_18()1213 fn powers_18() {
1214 test_eval(
1215 "5.2*10^15*300^(3/2)",
1216 "approx. 27019992598076723515.9873962402",
1217 );
1218 }
1219
1220 #[test]
pi_to_the_power_of_ten()1221 fn pi_to_the_power_of_ten() {
1222 test_eval("pi^10", "approx. 93648.047476083");
1223 }
1224
1225 #[test]
zero_to_the_power_of_zero()1226 fn zero_to_the_power_of_zero() {
1227 expect_error("0^0", None);
1228 }
1229
1230 #[test]
zero_to_the_power_of_one()1231 fn zero_to_the_power_of_one() {
1232 test_eval("0^1", "0");
1233 }
1234
1235 #[test]
one_to_the_power_of_zero()1236 fn one_to_the_power_of_zero() {
1237 test_eval("1^0", "1");
1238 }
1239
1240 #[test]
one_to_the_power_of_huge_exponent()1241 fn one_to_the_power_of_huge_exponent() {
1242 test_eval("1^1e1000", "1");
1243 }
1244
1245 #[test]
exponent_too_large()1246 fn exponent_too_large() {
1247 expect_error("2^1e1000", None);
1248 }
1249
1250 #[test]
i_powers()1251 fn i_powers() {
1252 for (i, result) in (0..=100).zip(["1", "i", "-1", "-i"].iter().cycle()) {
1253 test_eval(&format!("i^{}", i), result);
1254 }
1255 }
1256
1257 #[test]
four_to_the_power_of_i()1258 fn four_to_the_power_of_i() {
1259 test_eval("4^i", "approx. 0.1834569747 + 0.9830277404i");
1260 }
1261
1262 #[test]
i_to_the_power_of_i()1263 fn i_to_the_power_of_i() {
1264 test_eval("i^i", "approx. 0.2078795763");
1265 }
1266
1267 #[test]
unit_to_approx_power()1268 fn unit_to_approx_power() {
1269 test_eval("kg^(approx. 1)", "approx. 1 kg");
1270 }
1271
1272 #[test]
negative_decimal()1273 fn negative_decimal() {
1274 test_eval("-0.125", "-0.125");
1275 }
1276
1277 #[test]
two_pow_one_pow_two()1278 fn two_pow_one_pow_two() {
1279 test_eval("2^1^2", "2");
1280 }
1281
1282 #[test]
two_pow_one_parens_one_pow_two()1283 fn two_pow_one_parens_one_pow_two() {
1284 test_eval("2^(1^2)", "2");
1285 }
1286
1287 #[test]
two_pow_parens_one()1288 fn two_pow_parens_one() {
1289 test_eval("2^(1)", "2");
1290 }
1291
1292 #[test]
negative_power_1()1293 fn negative_power_1() {
1294 test_eval("2 * (-2^3)", "-16");
1295 }
1296
1297 #[test]
negative_power_2()1298 fn negative_power_2() {
1299 test_eval("2 * -2^3", "-16");
1300 }
1301
1302 #[test]
negative_power_3()1303 fn negative_power_3() {
1304 test_eval("2^-3 * 4", "0.5");
1305 }
1306
1307 #[test]
negative_power_4()1308 fn negative_power_4() {
1309 test_eval("2^3 * 4", "32");
1310 }
1311
1312 #[test]
negative_power_5()1313 fn negative_power_5() {
1314 test_eval("-2^-3", "-0.125");
1315 }
1316
1317 #[test]
negative_product()1318 fn negative_product() {
1319 test_eval("2 * -3 * 4", "-24");
1320 }
1321
1322 #[test]
negative_power_6()1323 fn negative_power_6() {
1324 test_eval("4^-1^2", "0.25");
1325 }
1326
1327 #[test]
negative_power_7()1328 fn negative_power_7() {
1329 test_eval(
1330 "2^-3^4",
1331 "0.000000000000000000000000413590306276513837435704346034981426782906055450439453125",
1332 );
1333 }
1334
1335 #[test]
i()1336 fn i() {
1337 test_eval("i", "i");
1338 }
1339
1340 #[test]
three_i()1341 fn three_i() {
1342 test_eval("3i", "3i");
1343 }
1344
1345 #[test]
three_i_plus_four()1346 fn three_i_plus_four() {
1347 test_eval("3i+4", "4 + 3i");
1348 }
1349
1350 #[test]
three_i_plus_four_plus_i()1351 fn three_i_plus_four_plus_i() {
1352 test_eval("(3i+4) + i", "4 + 4i");
1353 }
1354
1355 #[test]
three_i_plus_four_plus_i_2()1356 fn three_i_plus_four_plus_i_2() {
1357 test_eval("3i+(4 + i)", "4 + 4i");
1358 }
1359
1360 #[test]
minus_three_i()1361 fn minus_three_i() {
1362 test_eval("-3i", "-3i");
1363 }
1364
1365 #[test]
i_over_i()1366 fn i_over_i() {
1367 test_eval("i/i", "1");
1368 }
1369
1370 #[test]
i_times_i()1371 fn i_times_i() {
1372 test_eval("i*i", "-1");
1373 }
1374
1375 #[test]
i_times_i_times_i()1376 fn i_times_i_times_i() {
1377 test_eval("i*i*i", "-i");
1378 }
1379
1380 #[test]
i_times_i_times_i_times_i()1381 fn i_times_i_times_i_times_i() {
1382 test_eval("i*i*i*i", "1");
1383 }
1384
1385 #[test]
minus_three_plus_i()1386 fn minus_three_plus_i() {
1387 test_eval("-3+i", "-3 + i");
1388 }
1389
1390 #[test]
i_plus_i()1391 fn i_plus_i() {
1392 test_eval("1+i", "1 + i");
1393 }
1394
1395 #[test]
i_minus_i()1396 fn i_minus_i() {
1397 test_eval("1-i", "1 - i");
1398 }
1399
1400 #[test]
minus_one_plus_i()1401 fn minus_one_plus_i() {
1402 test_eval("-1 + i", "-1 + i");
1403 }
1404
1405 #[test]
minus_one_minus_i()1406 fn minus_one_minus_i() {
1407 test_eval("-1 - i", "-1 - i");
1408 }
1409
1410 #[test]
minus_one_minus_two_i()1411 fn minus_one_minus_two_i() {
1412 test_eval("-1 - 2i", "-1 - 2i");
1413 }
1414
1415 #[test]
minus_one_minus_half_i()1416 fn minus_one_minus_half_i() {
1417 test_eval("-1 - 0.5i", "-1 - 0.5i");
1418 }
1419
1420 #[test]
minus_one_minus_half_i_plus_half_i()1421 fn minus_one_minus_half_i_plus_half_i() {
1422 test_eval("-1 - 0.5i + 1.5i", "-1 + i");
1423 }
1424
1425 #[test]
minus_i()1426 fn minus_i() {
1427 test_eval("-i", "-i");
1428 }
1429
1430 #[test]
plus_i()1431 fn plus_i() {
1432 test_eval("+i", "i");
1433 }
1434
1435 #[test]
two_i()1436 fn two_i() {
1437 test_eval("2i", "2i");
1438 }
1439
1440 #[test]
i_over_3()1441 fn i_over_3() {
1442 test_eval("i/3", "i/3");
1443 }
1444
1445 #[test]
two_i_over_three()1446 fn two_i_over_three() {
1447 test_eval("2i/3", "2i/3");
1448 }
1449
1450 #[test]
two_i_over_minus_three_minus_one()1451 fn two_i_over_minus_three_minus_one() {
1452 test_eval("2i/-3-1", "-1 - 2i/3");
1453 }
1454
1455 #[test]
i_is_not_a_binary_digit()1456 fn i_is_not_a_binary_digit() {
1457 expect_error("2#i", None);
1458 }
1459
1460 #[test]
digit_separators_1()1461 fn digit_separators_1() {
1462 test_eval("1_1", "11");
1463 }
1464
1465 #[test]
digit_separators_2()1466 fn digit_separators_2() {
1467 test_eval("11_1", "111");
1468 }
1469
1470 #[test]
digit_separators_3()1471 fn digit_separators_3() {
1472 test_eval("1_1_1", "111");
1473 }
1474
1475 #[test]
digit_separators_4()1476 fn digit_separators_4() {
1477 test_eval("123_456_789_123", "123456789123");
1478 }
1479
1480 #[test]
digit_separators_5()1481 fn digit_separators_5() {
1482 test_eval("1_2_3_4_5_6", "123456");
1483 }
1484
1485 #[test]
digit_separators_6()1486 fn digit_separators_6() {
1487 test_eval("1.1_1", "1.11");
1488 }
1489
1490 #[test]
digit_separators_7()1491 fn digit_separators_7() {
1492 test_eval("1_1.1_1", "11.11");
1493 }
1494
1495 #[test]
digit_separators_8()1496 fn digit_separators_8() {
1497 expect_error("_1", None);
1498 }
1499
1500 #[test]
digit_separators_9()1501 fn digit_separators_9() {
1502 expect_error("1_", None);
1503 }
1504
1505 #[test]
digit_separators_10()1506 fn digit_separators_10() {
1507 expect_error("1__1", None);
1508 }
1509
1510 #[test]
digit_separators_11()1511 fn digit_separators_11() {
1512 expect_error("_", None);
1513 }
1514
1515 #[test]
digit_separators_12()1516 fn digit_separators_12() {
1517 expect_error("1_.1", None);
1518 }
1519
1520 #[test]
digit_separators_13()1521 fn digit_separators_13() {
1522 expect_error("1._1", None);
1523 }
1524
1525 #[test]
digit_separators_14()1526 fn digit_separators_14() {
1527 expect_error("1.1_", None);
1528 }
1529
1530 #[test]
digit_separators_15()1531 fn digit_separators_15() {
1532 test_eval("1,1", "11");
1533 }
1534
1535 #[test]
digit_separators_16()1536 fn digit_separators_16() {
1537 test_eval("11,1", "111");
1538 }
1539
1540 #[test]
digit_separators_17()1541 fn digit_separators_17() {
1542 test_eval("1,1,1", "111");
1543 }
1544
1545 #[test]
digit_separators_18()1546 fn digit_separators_18() {
1547 test_eval("123,456,789,123", "123456789123");
1548 }
1549
1550 #[test]
digit_separators_19()1551 fn digit_separators_19() {
1552 test_eval("1,2,3,4,5,6", "123456");
1553 }
1554
1555 #[test]
digit_separators_20()1556 fn digit_separators_20() {
1557 test_eval("1.1,1", "1.11");
1558 }
1559
1560 #[test]
digit_separators_21()1561 fn digit_separators_21() {
1562 test_eval("1,1.1,1", "11.11");
1563 }
1564
1565 #[test]
digit_separators_22()1566 fn digit_separators_22() {
1567 expect_error(",1", None);
1568 }
1569
1570 #[test]
digit_separators_23()1571 fn digit_separators_23() {
1572 expect_error("1,", None);
1573 }
1574
1575 #[test]
digit_separators_24()1576 fn digit_separators_24() {
1577 expect_error("1,,1", None);
1578 }
1579
1580 #[test]
digit_separators_25()1581 fn digit_separators_25() {
1582 expect_error(",", None);
1583 }
1584
1585 #[test]
digit_separators_26()1586 fn digit_separators_26() {
1587 expect_error("1,.1", None);
1588 }
1589
1590 #[test]
digit_separators_27()1591 fn digit_separators_27() {
1592 expect_error("1.,1", None);
1593 }
1594
1595 #[test]
digit_separators_28()1596 fn digit_separators_28() {
1597 expect_error("1.1,", None);
1598 }
1599
1600 #[test]
different_base_1()1601 fn different_base_1() {
1602 test_eval("0x10", "0x10");
1603 }
1604
1605 #[test]
different_base_2()1606 fn different_base_2() {
1607 test_eval("0o10", "0o10");
1608 }
1609
1610 #[test]
different_base_3()1611 fn different_base_3() {
1612 test_eval("0b10", "0b10");
1613 }
1614
1615 #[test]
different_base_4()1616 fn different_base_4() {
1617 test_eval("0x10 - 1", "0xf");
1618 }
1619
1620 #[test]
different_base_5()1621 fn different_base_5() {
1622 test_eval("0x0 + sqrt 16", "0x4");
1623 }
1624
1625 #[test]
different_base_6()1626 fn different_base_6() {
1627 test_eval("16#0 + sqrt 16", "16#4");
1628 }
1629
1630 #[test]
different_base_7()1631 fn different_base_7() {
1632 test_eval("0 + 6#100", "36");
1633 }
1634
1635 #[test]
different_base_8()1636 fn different_base_8() {
1637 test_eval("0 + 36#z", "35");
1638 }
1639
1640 #[test]
different_base_9()1641 fn different_base_9() {
1642 test_eval("16#dead_beef", "16#deadbeef");
1643 }
1644
1645 #[test]
different_base_10()1646 fn different_base_10() {
1647 test_eval("16#DEAD_BEEF", "16#deadbeef");
1648 }
1649
1650 #[test]
different_base_potential_dice_overlap()1651 fn different_base_potential_dice_overlap() {
1652 test_eval("16#D3AD_BEEF", "16#d3adbeef");
1653 }
1654
1655 #[test]
different_base_11()1656 fn different_base_11() {
1657 expect_error("#", None);
1658 }
1659
1660 #[test]
different_base_12()1661 fn different_base_12() {
1662 expect_error("0#0", None);
1663 }
1664
1665 #[test]
different_base_13()1666 fn different_base_13() {
1667 expect_error("1#0", None);
1668 }
1669
1670 #[test]
different_base_14()1671 fn different_base_14() {
1672 expect_error("2_2#0", None);
1673 }
1674
1675 #[test]
different_base_15()1676 fn different_base_15() {
1677 expect_error("22 #0", None);
1678 }
1679
1680 #[test]
different_base_16()1681 fn different_base_16() {
1682 expect_error("22# 0", None);
1683 }
1684
1685 #[test]
different_base_17()1686 fn different_base_17() {
1687 test_eval("36#i i", "36#i i");
1688 }
1689
1690 #[test]
different_base_18()1691 fn different_base_18() {
1692 test_eval("16#1 i", "16#1 i");
1693 }
1694
1695 #[test]
different_base_19()1696 fn different_base_19() {
1697 test_eval("16#f i", "16#f i");
1698 }
1699
1700 #[test]
different_base_20()1701 fn different_base_20() {
1702 test_eval("0 + 36#ii", "666");
1703 }
1704
1705 #[test]
different_base_21()1706 fn different_base_21() {
1707 expect_error("18#i/i", None);
1708 }
1709
1710 #[test]
different_base_22()1711 fn different_base_22() {
1712 test_eval("19#i/i", "-19#i i");
1713 }
1714
1715 // verified using a ruby program
1716 #[test]
different_base_23()1717 fn different_base_23() {
1718 test_eval(
1719 "0+36#0123456789abcdefghijklmnopqrstuvwxyz",
1720 "86846823611197163108337531226495015298096208677436155",
1721 );
1722 }
1723
1724 #[test]
different_base_24()1725 fn different_base_24() {
1726 test_eval(
1727 "36#0 + 86846823611197163108337531226495015298096208677436155",
1728 "36#123456789abcdefghijklmnopqrstuvwxyz",
1729 );
1730 }
1731
1732 #[test]
different_base_25()1733 fn different_base_25() {
1734 test_eval("18#100/65537 i", "18#100i/18#b44h");
1735 }
1736
1737 #[test]
different_base_26()1738 fn different_base_26() {
1739 test_eval("19#100/65537 i", "19#100 i/19#9aa6");
1740 }
1741
1742 #[test]
different_base_27()1743 fn different_base_27() {
1744 expect_error("5 to base 1.5", None);
1745 }
1746
1747 #[test]
different_base_28()1748 fn different_base_28() {
1749 expect_error("5 to base pi", None);
1750 }
1751
1752 #[test]
different_base_29()1753 fn different_base_29() {
1754 expect_error("5 to base (0pi)", None);
1755 }
1756
1757 #[test]
different_base_30()1758 fn different_base_30() {
1759 expect_error("5 to base 1", None);
1760 }
1761
1762 #[test]
different_base_31()1763 fn different_base_31() {
1764 expect_error("5 to base (-5)", None);
1765 }
1766
1767 #[test]
different_base_32()1768 fn different_base_32() {
1769 expect_error("5 to base 1000000000", None);
1770 }
1771
1772 #[test]
different_base_33()1773 fn different_base_33() {
1774 expect_error("5 to base 100", None);
1775 }
1776
1777 #[test]
different_base_34()1778 fn different_base_34() {
1779 expect_error("5 to base i", None);
1780 }
1781
1782 #[test]
different_base_35()1783 fn different_base_35() {
1784 expect_error("5 to base kg", None);
1785 }
1786
1787 #[test]
different_base_36()1788 fn different_base_36() {
1789 expect_error("6#3e9", None);
1790 }
1791
1792 #[test]
different_base_37()1793 fn different_base_37() {
1794 expect_error("6#3e39", None);
1795 }
1796
1797 #[test]
different_base_38()1798 fn different_base_38() {
1799 test_eval("9#5i", "9#5i");
1800 }
1801
1802 #[test]
three_electroncharge()1803 fn three_electroncharge() {
1804 test_eval(
1805 "3 electron_charge",
1806 "0.0000000000000000004806529902 coulomb",
1807 );
1808 }
1809
1810 #[test]
e_to_1()1811 fn e_to_1() {
1812 test_eval("e to 1", "approx. 2.7182818284");
1813 }
1814
1815 #[test]
e_in_binary()1816 fn e_in_binary() {
1817 test_eval("e in binary", "approx. 10.1011011111");
1818 }
1819
1820 #[test]
base_conversion_1()1821 fn base_conversion_1() {
1822 test_eval("16 to base 2", "10000");
1823 }
1824
1825 #[test]
base_conversion_2()1826 fn base_conversion_2() {
1827 test_eval("0x10ffff to decimal", "1114111");
1828 }
1829
1830 #[test]
base_conversion_3()1831 fn base_conversion_3() {
1832 test_eval("0o400 to decimal", "256");
1833 }
1834
1835 #[test]
base_conversion_4()1836 fn base_conversion_4() {
1837 test_eval("100 to base 6", "244");
1838 }
1839
1840 #[test]
base_conversion_5()1841 fn base_conversion_5() {
1842 test_eval("65536 to hex", "10000");
1843 }
1844
1845 #[test]
base_conversion_6()1846 fn base_conversion_6() {
1847 test_eval("65536 to octal", "200000");
1848 }
1849
1850 #[test]
exponents_1()1851 fn exponents_1() {
1852 test_eval("1e10", "10000000000");
1853 }
1854
1855 #[test]
exponents_2()1856 fn exponents_2() {
1857 test_eval("1.5e10", "15000000000");
1858 }
1859
1860 #[test]
exponents_3()1861 fn exponents_3() {
1862 test_eval("0b1e10", "0b100");
1863 }
1864
1865 #[test]
exponents_4()1866 fn exponents_4() {
1867 test_eval("0b1e+10", "0b100");
1868 }
1869
1870 #[test]
exponents_5()1871 fn exponents_5() {
1872 test_eval("0 + 0b1e100", "16");
1873 }
1874
1875 #[test]
exponents_6()1876 fn exponents_6() {
1877 test_eval("0 + 0b1e1000", "256");
1878 }
1879
1880 #[test]
exponents_7()1881 fn exponents_7() {
1882 test_eval("0 + 0b1e10000", "65536");
1883 }
1884
1885 #[test]
exponents_8()1886 fn exponents_8() {
1887 test_eval("0 + 0b1e100000", "4294967296");
1888 }
1889
1890 #[test]
exponents_9()1891 fn exponents_9() {
1892 test_eval("16#1e10", "16#1e10");
1893 }
1894
1895 #[test]
exponents_10()1896 fn exponents_10() {
1897 test_eval("10#1e10", "10#10000000000");
1898 }
1899
1900 #[test]
exponents_11()1901 fn exponents_11() {
1902 expect_error("11#1e10", None);
1903 }
1904
1905 #[test]
binary_exponent()1906 fn binary_exponent() {
1907 test_eval(
1908 "0 + 0b1e10000000",
1909 "340282366920938463463374607431768211456",
1910 );
1911 }
1912
1913 #[test]
exponents_12()1914 fn exponents_12() {
1915 test_eval("1.5e-1", "0.15");
1916 }
1917
1918 #[test]
exponents_13()1919 fn exponents_13() {
1920 test_eval("1.5e0", "1.5");
1921 }
1922
1923 #[test]
exponents_14()1924 fn exponents_14() {
1925 test_eval("1.5e-0", "1.5");
1926 }
1927
1928 #[test]
exponents_15()1929 fn exponents_15() {
1930 test_eval("1.5e+0", "1.5");
1931 }
1932
1933 #[test]
exponents_16()1934 fn exponents_16() {
1935 test_eval("1.5e1", "15");
1936 }
1937
1938 #[test]
exponents_17()1939 fn exponents_17() {
1940 test_eval("1.5e+1", "15");
1941 }
1942
1943 #[test]
exponents_18()1944 fn exponents_18() {
1945 expect_error("1e- 1", None);
1946 }
1947
1948 #[test]
exponents_19()1949 fn exponents_19() {
1950 test_eval("0 + 0b1e-110", "0.015625");
1951 }
1952
1953 #[test]
exponents_20()1954 fn exponents_20() {
1955 test_eval("e", "approx. 2.7182818284");
1956 }
1957
1958 #[test]
exponents_21()1959 fn exponents_21() {
1960 test_eval("2 e", "approx. 5.4365636569");
1961 }
1962
1963 #[test]
exponents_22()1964 fn exponents_22() {
1965 test_eval("2e", "approx. 5.4365636569");
1966 }
1967
1968 #[test]
exponents_23()1969 fn exponents_23() {
1970 test_eval("2e/2", "approx. 2.7182818284");
1971 }
1972
1973 #[test]
exponents_24()1974 fn exponents_24() {
1975 test_eval("2e / 2", "approx. 2.7182818284");
1976 }
1977
1978 #[test]
exponents_25()1979 fn exponents_25() {
1980 expect_error("2e+", None);
1981 }
1982
1983 #[test]
exponents_26()1984 fn exponents_26() {
1985 expect_error("2e-", None);
1986 }
1987
1988 #[test]
exponents_27()1989 fn exponents_27() {
1990 expect_error("2ehello", None);
1991 }
1992
1993 #[test]
exponents_28()1994 fn exponents_28() {
1995 test_eval("e^10", "approx. 22026.4657948067");
1996 }
1997
1998 #[test]
one_kg()1999 fn one_kg() {
2000 test_eval("1kg", "1 kg");
2001 }
2002
2003 #[test]
one_g()2004 fn one_g() {
2005 test_eval("1g", "1 g");
2006 }
2007
2008 #[test]
one_kg_plus_one_g()2009 fn one_kg_plus_one_g() {
2010 test_eval("1kg + 1g", "1.001 kg");
2011 }
2012
2013 #[test]
one_kg_plus_100_g()2014 fn one_kg_plus_100_g() {
2015 test_eval("1kg + 100g", "1.1 kg");
2016 }
2017
2018 #[test]
zero_g_plus_1_kg_plus_100_g()2019 fn zero_g_plus_1_kg_plus_100_g() {
2020 test_eval("0g + 1kg + 100g", "1100 g");
2021 }
2022
2023 #[test]
zero_g_plus_1_kg()2024 fn zero_g_plus_1_kg() {
2025 test_eval("0g + 1kg", "1000 g");
2026 }
2027
2028 #[test]
one_over_half_kg()2029 fn one_over_half_kg() {
2030 test_eval("1/0.5 kg", "2 kg");
2031 }
2032
2033 #[test]
one_over_one_over_half_kg()2034 fn one_over_one_over_half_kg() {
2035 test_eval("1/(1/0.5 kg)", "0.5 kg^-1");
2036 }
2037
2038 #[test]
cbrt_kg()2039 fn cbrt_kg() {
2040 test_eval("cbrt (1kg)", "1 kg^(1/3)");
2041 }
2042
2043 #[test]
one_kg_plug_i_g()2044 fn one_kg_plug_i_g() {
2045 test_eval("1 kg + i g", "(1 + 0.001i) kg");
2046 }
2047
2048 #[test]
abs_2()2049 fn abs_2() {
2050 test_eval("abs 2", "2");
2051 }
2052
2053 #[test]
five_meters()2054 fn five_meters() {
2055 test_eval("5 m", "5 m");
2056 }
2057
2058 #[test]
parentheses_multiplication()2059 fn parentheses_multiplication() {
2060 test_eval("(4)(6)", "24");
2061 }
2062
2063 #[test]
parentheses_multiplication_2()2064 fn parentheses_multiplication_2() {
2065 test_eval("5(6)", "30");
2066 }
2067
2068 #[test]
multiply_number_without_parentheses()2069 fn multiply_number_without_parentheses() {
2070 expect_error("(5)6", None);
2071 }
2072
2073 #[test]
simple_adjacent_numbers()2074 fn simple_adjacent_numbers() {
2075 expect_error("7165928\t761528765", None);
2076 }
2077
2078 #[test]
three_feet_six_inches()2079 fn three_feet_six_inches() {
2080 test_eval("3’6”", "3.5’");
2081 }
2082
2083 #[test]
five_feet_twelve_inches()2084 fn five_feet_twelve_inches() {
2085 test_eval("5 feet 12 inch", "6 feet");
2086 }
2087
2088 #[test]
three_feet_six_inches_ascii()2089 fn three_feet_six_inches_ascii() {
2090 test_eval("3'6\"", "3.5'");
2091 }
2092
2093 #[test]
three_meters_15_cm()2094 fn three_meters_15_cm() {
2095 test_eval("3 m 15 cm", "3.15 m");
2096 }
2097
2098 #[test]
five_percent()2099 fn five_percent() {
2100 test_eval("5%", "0.05");
2101 }
2102
2103 #[test]
five_percent_to_percent()2104 fn five_percent_to_percent() {
2105 test_eval_simple("5% to %", "5%");
2106 }
2107
2108 #[test]
five_percent_plus_point_one()2109 fn five_percent_plus_point_one() {
2110 test_eval("5% + 0.1", "0.15");
2111 }
2112
2113 #[test]
five_percent_plus_one()2114 fn five_percent_plus_one() {
2115 test_eval("5% + 1", "1.05");
2116 }
2117
2118 #[test]
point_one_plus_five_percent()2119 fn point_one_plus_five_percent() {
2120 test_eval("0.1 + 5%", "0.15");
2121 }
2122
2123 #[test]
one_plus_five_percent()2124 fn one_plus_five_percent() {
2125 test_eval("1 + 5%", "1.05");
2126 }
2127
2128 #[test]
five_percent_times_five_percent()2129 fn five_percent_times_five_percent() {
2130 test_eval("5% * 5%", "0.0025");
2131 }
2132
2133 #[test]
five_percent_times_kg()2134 fn five_percent_times_kg() {
2135 test_eval("5% * 8 kg", "0.4 kg");
2136 }
2137
2138 #[test]
five_percent_times_100()2139 fn five_percent_times_100() {
2140 test_eval("5% * 100", "5");
2141 }
2142
2143 #[test]
five_percent_of_100()2144 fn five_percent_of_100() {
2145 test_eval("5% of 100", "5");
2146 }
2147
2148 #[test]
five_percent_of_200()2149 fn five_percent_of_200() {
2150 test_eval("2 + 5% of 200", "12");
2151 }
2152
2153 #[test]
five_percent_of_200_2()2154 fn five_percent_of_200_2() {
2155 test_eval("(2 + 5)% of 200", "14");
2156 }
2157
2158 #[test]
units_1()2159 fn units_1() {
2160 test_eval("0m + 1kph * 1 hr", "1000 m");
2161 }
2162
2163 #[test]
units_2()2164 fn units_2() {
2165 test_eval("0GiB + 1GB", "0.931322574615478515625 GiB");
2166 }
2167
2168 #[test]
units_3()2169 fn units_3() {
2170 test_eval("0m/s + 1 km/hr", "approx. 0.2777777777 m / s");
2171 }
2172
2173 #[test]
units_4()2174 fn units_4() {
2175 test_eval("0m/s + i km/hr", "5i/18 m / s");
2176 }
2177
2178 #[test]
units_5()2179 fn units_5() {
2180 test_eval("0m/s + i kilometers per hour", "5i/18 m / s");
2181 }
2182
2183 #[test]
units_6()2184 fn units_6() {
2185 test_eval("0m/s + (1 + i) km/hr", "(5/18 + 5i/18) m / s");
2186 }
2187
2188 #[test]
units_9()2189 fn units_9() {
2190 test_eval("365.25 light days to ly", "1 ly");
2191 }
2192
2193 #[test]
units_10()2194 fn units_10() {
2195 test_eval("365.25 light days as ly", "1 ly");
2196 }
2197
2198 #[test]
units_11()2199 fn units_11() {
2200 test_eval("1 light year", "1 light_year");
2201 }
2202
2203 #[test]
units_12()2204 fn units_12() {
2205 expect_error("1 2 m", None);
2206 }
2207
2208 #[test]
units_13()2209 fn units_13() {
2210 test_eval("5pi", "approx. 15.7079632679");
2211 }
2212
2213 #[test]
units_14()2214 fn units_14() {
2215 test_eval("5 pi/2", "approx. 7.8539816339");
2216 }
2217
2218 #[test]
units_15()2219 fn units_15() {
2220 test_eval("5 i/2", "2.5i");
2221 }
2222
2223 #[test]
units_22()2224 fn units_22() {
2225 test_eval("1psi as kPa as 5dp", "approx. 6.89475 kPa");
2226 }
2227
2228 #[test]
units_23()2229 fn units_23() {
2230 test_eval("1NM to m", "1852 m");
2231 }
2232
2233 #[test]
units_24()2234 fn units_24() {
2235 test_eval("1NM + 1cm as m", "1852.01 m");
2236 }
2237
2238 #[test]
units_25()2239 fn units_25() {
2240 test_eval("1 m / (s kg cd)", "1 m s^-1 kg^-1 cd^-1");
2241 }
2242
2243 #[test]
units_26()2244 fn units_26() {
2245 test_eval("1 watt hour / lb", "1 watt hour / lb");
2246 }
2247
2248 #[test]
units_27()2249 fn units_27() {
2250 test_eval("4 watt hours / lb", "4 watt hours / lb");
2251 }
2252
2253 #[test]
units_28()2254 fn units_28() {
2255 test_eval("1 second second", "1 second^2");
2256 }
2257
2258 #[test]
units_29()2259 fn units_29() {
2260 test_eval("2 second seconds", "2 seconds^2");
2261 }
2262
2263 #[test]
units_30()2264 fn units_30() {
2265 test_eval("1 lb^-1", "1 lb^-1");
2266 }
2267
2268 #[test]
units_31()2269 fn units_31() {
2270 test_eval("2 lb^-1", "2 lb^-1");
2271 }
2272
2273 #[test]
units_32()2274 fn units_32() {
2275 test_eval("2 lb^-1 kg^-1", "0.90718474 lb^-2");
2276 }
2277
2278 #[test]
units_33()2279 fn units_33() {
2280 test_eval("1 lb^-1 kg^-1", "0.45359237 lb^-2");
2281 }
2282
2283 #[test]
units_34()2284 fn units_34() {
2285 test_eval("0.5 light year", "0.5 light_years");
2286 }
2287
2288 #[test]
units_35()2289 fn units_35() {
2290 test_eval("1 lightyear / second", "1 lightyear / second");
2291 }
2292
2293 #[test]
units_36()2294 fn units_36() {
2295 test_eval("2 lightyears / second", "2 lightyears / second");
2296 }
2297
2298 #[test]
units_37()2299 fn units_37() {
2300 test_eval(
2301 "2 lightyears second^-1 lb^-1",
2302 "2 lightyears second^-1 lb^-1",
2303 );
2304 }
2305
2306 #[test]
units_38()2307 fn units_38() {
2308 test_eval("1 feet", "1 foot");
2309 }
2310
2311 #[test]
units_39()2312 fn units_39() {
2313 test_eval("5 foot", "5 feet");
2314 }
2315
2316 #[test]
units_40()2317 fn units_40() {
2318 test_eval("5 foot 2 inches", "approx. 5.1666666666 feet");
2319 }
2320
2321 #[test]
units_41()2322 fn units_41() {
2323 test_eval("5 foot 1 inch 1 inch", "approx. 5.1666666666 feet");
2324 }
2325
2326 #[test]
plain_adjacent_numbers()2327 fn plain_adjacent_numbers() {
2328 expect_error("1 2", None);
2329 }
2330
2331 #[test]
multiple_plain_adjacent_numbers()2332 fn multiple_plain_adjacent_numbers() {
2333 expect_error("1 2 3 4 5", None);
2334 }
2335
2336 #[test]
implicit_sum_missing_unit()2337 fn implicit_sum_missing_unit() {
2338 expect_error("1 inch 5", None);
2339 }
2340
2341 #[test]
implicit_sum_incompatible_unit()2342 fn implicit_sum_incompatible_unit() {
2343 expect_error("1 inch 5 kg", None);
2344 }
2345
2346 #[test]
too_many_args()2347 fn too_many_args() {
2348 expect_error("abs 1 2", None);
2349 }
2350
2351 #[test]
abs_4_with_coefficient()2352 fn abs_4_with_coefficient() {
2353 test_eval("5 (abs 4)", "20");
2354 }
2355
2356 #[test]
mixed_fraction_to_improper_fraction()2357 fn mixed_fraction_to_improper_fraction() {
2358 test_eval_simple("1 2/3 to fraction", "5/3");
2359 }
2360
2361 #[test]
mixed_fractions_1()2362 fn mixed_fractions_1() {
2363 test_eval("5/3", "approx. 1.6666666666");
2364 }
2365
2366 #[test]
mixed_fractions_2()2367 fn mixed_fractions_2() {
2368 test_eval("4 + 1 2/3", "approx. 5.6666666666");
2369 }
2370
2371 #[test]
mixed_fractions_3()2372 fn mixed_fractions_3() {
2373 test_eval("-8 1/2", "-8.5");
2374 }
2375
2376 #[test]
mixed_fractions_4()2377 fn mixed_fractions_4() {
2378 test_eval("-8 1/2'", "-8.5'");
2379 }
2380
2381 #[test]
mixed_fractions_5()2382 fn mixed_fractions_5() {
2383 test_eval("1.(3)i", "1 1/3 i");
2384 }
2385
2386 #[test]
mixed_fractions_6()2387 fn mixed_fractions_6() {
2388 test_eval("1*1 1/2", "1.5");
2389 }
2390
2391 #[test]
mixed_fractions_7()2392 fn mixed_fractions_7() {
2393 test_eval("2*1 1/2", "3");
2394 }
2395
2396 #[test]
mixed_fractions_8()2397 fn mixed_fractions_8() {
2398 test_eval("3*2*1 1/2", "9");
2399 }
2400
2401 #[test]
mixed_fractions_9()2402 fn mixed_fractions_9() {
2403 test_eval("3 + 2*1 1/2", "6");
2404 }
2405
2406 #[test]
mixed_fractions_10()2407 fn mixed_fractions_10() {
2408 test_eval("abs 2*1 1/2", "3");
2409 }
2410
2411 #[test]
mixed_fractions_11()2412 fn mixed_fractions_11() {
2413 expect_error("1/1 1/2", None);
2414 }
2415
2416 #[test]
mixed_fractions_12()2417 fn mixed_fractions_12() {
2418 expect_error("2/1 1/2", None);
2419 }
2420
2421 #[test]
mixed_fractions_13()2422 fn mixed_fractions_13() {
2423 test_eval("1 1/2 m/s^2", "1.5 m / s^2");
2424 }
2425
2426 #[test]
mixed_fractions_14()2427 fn mixed_fractions_14() {
2428 expect_error("(x:2x) 1 1/2", None);
2429 }
2430
2431 #[test]
mixed_fractions_15()2432 fn mixed_fractions_15() {
2433 expect_error("pi 1 1/2", None);
2434 }
2435
2436 #[test]
lone_conversion_arrow()2437 fn lone_conversion_arrow() {
2438 expect_error("->", None);
2439 }
2440
2441 #[test]
conversion_arrow_no_rhs()2442 fn conversion_arrow_no_rhs() {
2443 expect_error("1m->", None);
2444 }
2445
2446 #[test]
conversion_arrow_with_space_in_the_middle()2447 fn conversion_arrow_with_space_in_the_middle() {
2448 expect_error("1m - >", None);
2449 }
2450
2451 #[test]
conversion_arrow_no_lhs()2452 fn conversion_arrow_no_lhs() {
2453 expect_error("->1ft", None);
2454 }
2455
2456 #[test]
meter_to_feet()2457 fn meter_to_feet() {
2458 expect_error("1m -> 45ft", None);
2459 }
2460
2461 #[test]
meter_to_kg_ft()2462 fn meter_to_kg_ft() {
2463 expect_error("1m -> 45 kg ft", None);
2464 }
2465
2466 #[test]
one_foot_to_inches()2467 fn one_foot_to_inches() {
2468 test_eval("1' to inches", "12 inches");
2469 }
2470
2471 #[test]
abs_1()2472 fn abs_1() {
2473 test_eval("abs 1", "1");
2474 }
2475
2476 #[test]
abs_i()2477 fn abs_i() {
2478 test_eval("abs i", "1");
2479 }
2480
2481 #[test]
abs_minus_1()2482 fn abs_minus_1() {
2483 test_eval("abs (-1)", "1");
2484 }
2485
2486 #[test]
abs_minus_i()2487 fn abs_minus_i() {
2488 test_eval("abs (-i)", "1");
2489 }
2490
2491 #[test]
abs_2_i()2492 fn abs_2_i() {
2493 test_eval("abs (2i)", "2");
2494 }
2495
2496 #[test]
abs_1_plus_i()2497 fn abs_1_plus_i() {
2498 test_eval("abs (1 + i)", "approx. 1.4142135619");
2499 }
2500
2501 #[test]
two_kg_squared()2502 fn two_kg_squared() {
2503 test_eval("2 kg^2", "2 kg^2");
2504 }
2505
2506 #[test]
quarter_kg_pow_minus_two()2507 fn quarter_kg_pow_minus_two() {
2508 test_eval("((1/4) kg)^-2", "16 kg^-2");
2509 }
2510
2511 #[test]
newton_subtraction()2512 fn newton_subtraction() {
2513 test_eval("1 N - 1 kg m s^-2", "0 N");
2514 }
2515
2516 #[test]
joule_subtraction()2517 fn joule_subtraction() {
2518 test_eval("1 J - 1 kg m^2 s^-2 + 1 kg / (m^-2 s^2)", "1 J");
2519 }
2520
2521 #[test]
two_to_the_power_of_abs_one()2522 fn two_to_the_power_of_abs_one() {
2523 test_eval("2^abs 1", "2");
2524 }
2525
2526 #[test]
adjacent_numbers_rhs_cubed()2527 fn adjacent_numbers_rhs_cubed() {
2528 expect_error("2 4^3", None);
2529 }
2530
2531 #[test]
negative_adjacent_numbers_rhs_cubed()2532 fn negative_adjacent_numbers_rhs_cubed() {
2533 expect_error("-2 4^3", None);
2534 }
2535
2536 #[test]
product_with_unary_minus_1()2537 fn product_with_unary_minus_1() {
2538 test_eval("3*-2", "-6");
2539 }
2540
2541 #[test]
product_with_unary_minus_2()2542 fn product_with_unary_minus_2() {
2543 test_eval("-3*-2", "6");
2544 }
2545
2546 #[test]
product_with_unary_minus_3()2547 fn product_with_unary_minus_3() {
2548 test_eval("-3*2", "-6");
2549 }
2550
2551 #[test]
illegal_mixed_fraction_with_pow_1()2552 fn illegal_mixed_fraction_with_pow_1() {
2553 expect_error("1 2/3^2", None);
2554 }
2555
2556 #[test]
illegal_mixed_fraction_with_pow_2()2557 fn illegal_mixed_fraction_with_pow_2() {
2558 expect_error("1 2^2/3", None);
2559 }
2560
2561 #[test]
illegal_mixed_fraction_with_pow_3()2562 fn illegal_mixed_fraction_with_pow_3() {
2563 expect_error("1^2 2/3", None);
2564 }
2565
2566 #[test]
illegal_mixed_fraction_with_pow_4()2567 fn illegal_mixed_fraction_with_pow_4() {
2568 expect_error("1 2/-3", None);
2569 }
2570
2571 #[test]
positive_mixed_fraction_sum()2572 fn positive_mixed_fraction_sum() {
2573 test_eval("1 2/3 + 4 5/6", "6.5");
2574 }
2575
2576 #[test]
negative_mixed_fraction_sum()2577 fn negative_mixed_fraction_sum() {
2578 test_eval("1 2/3 + -4 5/6", "approx. -3.1666666666");
2579 }
2580
2581 #[test]
positive_mixed_fraction_subtraction()2582 fn positive_mixed_fraction_subtraction() {
2583 test_eval("1 2/3 - 4 5/6", "approx. -3.1666666666");
2584 }
2585
2586 #[test]
negative_mixed_fraction_subtraction()2587 fn negative_mixed_fraction_subtraction() {
2588 test_eval("1 2/3 - 4 + 5/6", "-1.5");
2589 }
2590
2591 #[test]
barn_to_meters_squared()2592 fn barn_to_meters_squared() {
2593 test_eval("1 barn to m^2", "0.0000000000000000000000000001 m^2");
2594 }
2595
2596 #[test]
liter_to_cubic_meters()2597 fn liter_to_cubic_meters() {
2598 test_eval("1L to m^3", "0.001 m^3");
2599 }
2600
2601 #[test]
five_feet_to_meters()2602 fn five_feet_to_meters() {
2603 test_eval("5 ft to m", "1.524 m");
2604 }
2605
2606 #[test]
log10_4()2607 fn log10_4() {
2608 test_eval("log10 4", "approx. 0.6020599913");
2609 }
2610
2611 #[test]
log_4_as_log10()2612 fn log_4_as_log10() {
2613 test_eval("log 4", "approx. 0.6020599913");
2614 }
2615
2616 #[test]
factorial_of_0()2617 fn factorial_of_0() {
2618 test_eval("0!", "1");
2619 }
2620
2621 #[test]
factorial_of_1()2622 fn factorial_of_1() {
2623 test_eval("1!", "1");
2624 }
2625
2626 #[test]
factorial_of_2()2627 fn factorial_of_2() {
2628 test_eval("2!", "2");
2629 }
2630
2631 #[test]
factorial_of_3()2632 fn factorial_of_3() {
2633 test_eval("3!", "6");
2634 }
2635
2636 #[test]
factorial_of_4()2637 fn factorial_of_4() {
2638 test_eval("4!", "24");
2639 }
2640
2641 #[test]
factorial_of_5()2642 fn factorial_of_5() {
2643 test_eval("5!", "120");
2644 }
2645
2646 #[test]
factorial_of_6()2647 fn factorial_of_6() {
2648 test_eval("6!", "720");
2649 }
2650
2651 #[test]
factorial_of_7()2652 fn factorial_of_7() {
2653 test_eval("7!", "5040");
2654 }
2655
2656 #[test]
factorial_of_8()2657 fn factorial_of_8() {
2658 test_eval("8!", "40320");
2659 }
2660
2661 #[test]
factorial_of_half()2662 fn factorial_of_half() {
2663 expect_error("0.5!", None);
2664 }
2665
2666 #[test]
factorial_of_minus_two()2667 fn factorial_of_minus_two() {
2668 expect_error("(-2)!", None);
2669 }
2670
2671 #[test]
factorial_of_three_i()2672 fn factorial_of_three_i() {
2673 expect_error("3i!", None);
2674 }
2675
2676 #[test]
factorial_of_three_kg()2677 fn factorial_of_three_kg() {
2678 expect_error("(3 kg)!", None);
2679 }
2680
2681 #[test]
test_floor()2682 fn test_floor() {
2683 test_eval("floor(3)", "3");
2684 test_eval("floor(3.9)", "3");
2685 test_eval("floor(-3)", "-3");
2686 test_eval("floor(-3.1)", "-4");
2687 }
2688
2689 #[test]
test_ceil()2690 fn test_ceil() {
2691 test_eval("ceil(3)", "3");
2692 test_eval("ceil(3.3)", "4");
2693 test_eval("ceil(-3)", "-3");
2694 test_eval("ceil(-3.3)", "-3");
2695 }
2696
2697 #[test]
test_round()2698 fn test_round() {
2699 test_eval("round(3)", "3");
2700
2701 test_eval("round(3.3)", "3");
2702 test_eval("round(3.7)", "4");
2703
2704 test_eval("round(-3.3)", "-3");
2705 test_eval("round(-3.7)", "-4");
2706 }
2707
2708 #[test]
recurring_digits_1()2709 fn recurring_digits_1() {
2710 test_eval_simple("9/11 to float", "0.(81)");
2711 }
2712
2713 #[test]
recurring_digits_2()2714 fn recurring_digits_2() {
2715 test_eval_simple("6#1 / 11 to float", "6#0.(0313452421)");
2716 }
2717
2718 #[test]
recurring_digits_3()2719 fn recurring_digits_3() {
2720 test_eval_simple("6#0 + 6#1 / 7 to float", "6#0.(05)");
2721 }
2722
2723 #[test]
recurring_digits_4()2724 fn recurring_digits_4() {
2725 test_eval_simple("0.25 as fraction", "1/4");
2726 }
2727
2728 #[test]
recurring_digits_5()2729 fn recurring_digits_5() {
2730 test_eval("0.21 as 1 dp", "approx. 0.2");
2731 }
2732
2733 #[test]
recurring_digits_6()2734 fn recurring_digits_6() {
2735 test_eval("0.21 to 1 dp to auto", "0.21");
2736 }
2737
2738 #[test]
recurring_digits_7()2739 fn recurring_digits_7() {
2740 test_eval_simple("502938/700 to float", "718.48(285714)");
2741 }
2742
2743 #[test]
builtin_function_name_abs()2744 fn builtin_function_name_abs() {
2745 test_eval("abs", "abs");
2746 }
2747
2748 #[test]
builtin_function_name_sin()2749 fn builtin_function_name_sin() {
2750 test_eval("sin", "sin");
2751 }
2752
2753 #[test]
builtin_function_name_cos()2754 fn builtin_function_name_cos() {
2755 test_eval("cos", "cos");
2756 }
2757
2758 #[test]
builtin_function_name_tan()2759 fn builtin_function_name_tan() {
2760 test_eval("tan", "tan");
2761 }
2762
2763 #[test]
builtin_function_name_asin()2764 fn builtin_function_name_asin() {
2765 test_eval("asin", "asin");
2766 }
2767
2768 #[test]
builtin_function_name_acos()2769 fn builtin_function_name_acos() {
2770 test_eval("acos", "acos");
2771 }
2772
2773 #[test]
builtin_function_name_atan()2774 fn builtin_function_name_atan() {
2775 test_eval("atan", "atan");
2776 }
2777
2778 #[test]
builtin_function_name_sinh()2779 fn builtin_function_name_sinh() {
2780 test_eval("sinh", "sinh");
2781 }
2782
2783 #[test]
builtin_function_name_cosh()2784 fn builtin_function_name_cosh() {
2785 test_eval("cosh", "cosh");
2786 }
2787
2788 #[test]
builtin_function_name_tanh()2789 fn builtin_function_name_tanh() {
2790 test_eval("tanh", "tanh");
2791 }
2792
2793 #[test]
builtin_function_name_asinh()2794 fn builtin_function_name_asinh() {
2795 test_eval("asinh", "asinh");
2796 }
2797
2798 #[test]
builtin_function_name_acosh()2799 fn builtin_function_name_acosh() {
2800 test_eval("acosh", "acosh");
2801 }
2802
2803 #[test]
builtin_function_name_atanh()2804 fn builtin_function_name_atanh() {
2805 test_eval("atanh", "atanh");
2806 }
2807
2808 #[test]
builtin_function_name_ln()2809 fn builtin_function_name_ln() {
2810 test_eval("ln", "ln");
2811 }
2812
2813 #[test]
builtin_function_name_log2()2814 fn builtin_function_name_log2() {
2815 test_eval("log2", "log2");
2816 }
2817
2818 #[test]
builtin_function_name_log10()2819 fn builtin_function_name_log10() {
2820 test_eval("log10", "log10");
2821 }
2822
2823 #[test]
builtin_function_name_log_is_log10()2824 fn builtin_function_name_log_is_log10() {
2825 test_eval("log", "log10");
2826 }
2827
2828 #[test]
builtin_function_name_base()2829 fn builtin_function_name_base() {
2830 test_eval("base", "base");
2831 }
2832
2833 // values from https://en.wikipedia.org/wiki/Exact_trigonometric_values
2834 #[test]
sin_0()2835 fn sin_0() {
2836 test_eval("sin 0", "0");
2837 }
2838
2839 #[test]
sin_1()2840 fn sin_1() {
2841 test_eval("sin 1", "approx. 0.8414709848");
2842 }
2843
2844 #[test]
sin_1_percent()2845 fn sin_1_percent() {
2846 test_eval("sin (1%)", "approx. 0.0099998333");
2847 }
2848
2849 #[test]
atan_1_percent()2850 fn atan_1_percent() {
2851 test_eval("atan (1%)", "approx. 0.0099996666");
2852 }
2853
2854 #[test]
sin_pi()2855 fn sin_pi() {
2856 test_eval("sin pi", "0");
2857 }
2858
2859 #[test]
sin_2_pi()2860 fn sin_2_pi() {
2861 test_eval("sin (2pi)", "0");
2862 }
2863
2864 #[test]
sin_minus_pi()2865 fn sin_minus_pi() {
2866 test_eval("sin (-pi)", "0");
2867 }
2868
2869 #[test]
sin_minus_1000_pi()2870 fn sin_minus_1000_pi() {
2871 test_eval("sin (-1000pi)", "0");
2872 }
2873
2874 #[test]
sin_pi_over_2()2875 fn sin_pi_over_2() {
2876 test_eval("sin (pi/2)", "1");
2877 }
2878
2879 #[test]
sin_3_pi_over_2()2880 fn sin_3_pi_over_2() {
2881 test_eval("sin (3pi/2)", "-1");
2882 }
2883
2884 #[test]
sin_5_pi_over_2()2885 fn sin_5_pi_over_2() {
2886 test_eval("sin (5pi/2)", "1");
2887 }
2888
2889 #[test]
sin_7_pi_over_2()2890 fn sin_7_pi_over_2() {
2891 test_eval("sin (7pi/2)", "-1");
2892 }
2893
2894 #[test]
sin_minus_pi_over_2()2895 fn sin_minus_pi_over_2() {
2896 test_eval("sin (-pi/2)", "-1");
2897 }
2898
2899 #[test]
sin_minus_3_pi_over_2()2900 fn sin_minus_3_pi_over_2() {
2901 test_eval("sin (-3pi/2)", "1");
2902 }
2903
2904 #[test]
sin_minus_5_pi_over_2()2905 fn sin_minus_5_pi_over_2() {
2906 test_eval("sin (-5pi/2)", "-1");
2907 }
2908
2909 #[test]
sin_minus_7_pi_over_2()2910 fn sin_minus_7_pi_over_2() {
2911 test_eval("sin (-7pi/2)", "1");
2912 }
2913
2914 #[test]
sin_minus_1023_pi_over_2()2915 fn sin_minus_1023_pi_over_2() {
2916 test_eval("sin (-1023pi/2)", "1");
2917 }
2918
2919 #[test]
sin_pi_over_6()2920 fn sin_pi_over_6() {
2921 test_eval("sin (pi/6)", "0.5");
2922 }
2923
2924 #[test]
sin_5_pi_over_6()2925 fn sin_5_pi_over_6() {
2926 test_eval("sin (5pi/6)", "0.5");
2927 }
2928
2929 #[test]
sin_7_pi_over_6()2930 fn sin_7_pi_over_6() {
2931 test_eval("sin (7pi/6)", "-0.5");
2932 }
2933
2934 #[test]
sin_11_pi_over_6()2935 fn sin_11_pi_over_6() {
2936 test_eval("sin (11pi/6)", "-0.5");
2937 }
2938
2939 #[test]
sin_minus_pi_over_6()2940 fn sin_minus_pi_over_6() {
2941 test_eval("sin (-pi/6)", "-0.5");
2942 }
2943
2944 #[test]
sin_minus_5_pi_over_6()2945 fn sin_minus_5_pi_over_6() {
2946 test_eval("sin (-5pi/6)", "-0.5");
2947 }
2948
2949 #[test]
sin_minus_7_pi_over_6()2950 fn sin_minus_7_pi_over_6() {
2951 test_eval("sin (-7pi/6)", "0.5");
2952 }
2953
2954 #[test]
sin_minus_11_pi_over_6()2955 fn sin_minus_11_pi_over_6() {
2956 test_eval("sin (-11pi/6)", "0.5");
2957 }
2958
2959 #[test]
sin_180_degrees()2960 fn sin_180_degrees() {
2961 test_eval("sin (180°)", "0");
2962 }
2963
2964 #[test]
sin_30_degrees()2965 fn sin_30_degrees() {
2966 test_eval("sin (30°)", "0.5");
2967 }
2968
2969 #[test]
sin_one_degree()2970 fn sin_one_degree() {
2971 test_eval("sin (1°)", "approx. 0.0174524064");
2972 }
2973
2974 #[test]
cos_0()2975 fn cos_0() {
2976 test_eval("cos 0", "1");
2977 }
2978
2979 #[test]
cos_1()2980 fn cos_1() {
2981 test_eval("cos 1", "approx. 0.5403023058");
2982 }
2983
2984 #[test]
cos_pi()2985 fn cos_pi() {
2986 test_eval("cos pi", "-1");
2987 }
2988
2989 #[test]
cos_2_pi()2990 fn cos_2_pi() {
2991 test_eval("cos (2pi)", "1");
2992 }
2993
2994 #[test]
cos_minus_pi()2995 fn cos_minus_pi() {
2996 test_eval("cos (-pi)", "-1");
2997 }
2998
2999 #[test]
cos_minus_1000_pi()3000 fn cos_minus_1000_pi() {
3001 test_eval("cos (-1000pi)", "1");
3002 }
3003
3004 #[test]
cos_pi_over_2()3005 fn cos_pi_over_2() {
3006 test_eval("cos (pi/2)", "0");
3007 }
3008
3009 #[test]
cos_3_pi_over_2()3010 fn cos_3_pi_over_2() {
3011 test_eval("cos (3pi/2)", "0");
3012 }
3013
3014 #[test]
cos_5_pi_over_2()3015 fn cos_5_pi_over_2() {
3016 test_eval("cos (5pi/2)", "0");
3017 }
3018
3019 #[test]
cos_7_pi_over_2()3020 fn cos_7_pi_over_2() {
3021 test_eval("cos (7pi/2)", "0");
3022 }
3023
3024 #[test]
cos_minus_pi_over_2()3025 fn cos_minus_pi_over_2() {
3026 test_eval("cos (-pi/2)", "0");
3027 }
3028
3029 #[test]
cos_minus_3_pi_over_2()3030 fn cos_minus_3_pi_over_2() {
3031 test_eval("cos (-3pi/2)", "0");
3032 }
3033
3034 #[test]
cos_minus_5_pi_over_2()3035 fn cos_minus_5_pi_over_2() {
3036 test_eval("cos (-5pi/2)", "0");
3037 }
3038
3039 #[test]
cos_minus_7_pi_over_2()3040 fn cos_minus_7_pi_over_2() {
3041 test_eval("cos (-7pi/2)", "0");
3042 }
3043
3044 #[test]
cos_minus_1023_pi_over_2()3045 fn cos_minus_1023_pi_over_2() {
3046 test_eval("cos (-1023pi/2)", "0");
3047 }
3048
3049 #[test]
cos_pi_over_3()3050 fn cos_pi_over_3() {
3051 test_eval("cos (pi/3)", "0.5");
3052 }
3053
3054 #[test]
cos_2_pi_over_3()3055 fn cos_2_pi_over_3() {
3056 test_eval("cos (2pi/3)", "-0.5");
3057 }
3058
3059 #[test]
cos_4_pi_over_3()3060 fn cos_4_pi_over_3() {
3061 test_eval("cos (4pi/3)", "-0.5");
3062 }
3063
3064 #[test]
cos_5_pi_over_3()3065 fn cos_5_pi_over_3() {
3066 test_eval("cos (5pi/3)", "0.5");
3067 }
3068
3069 #[test]
cos_minus_pi_over_3()3070 fn cos_minus_pi_over_3() {
3071 test_eval("cos (-pi/3)", "0.5");
3072 }
3073
3074 #[test]
cos_minus_2_pi_over_3()3075 fn cos_minus_2_pi_over_3() {
3076 test_eval("cos (-2pi/3)", "-0.5");
3077 }
3078
3079 #[test]
cos_minus_4_pi_over_3()3080 fn cos_minus_4_pi_over_3() {
3081 test_eval("cos (-4pi/3)", "-0.5");
3082 }
3083
3084 #[test]
cos_minus_5_pi_over_3()3085 fn cos_minus_5_pi_over_3() {
3086 test_eval("cos (-5pi/3)", "0.5");
3087 }
3088
3089 #[test]
tau()3090 fn tau() {
3091 test_eval("tau", "approx. 6.2831853071");
3092 }
3093
3094 #[test]
sin_tau_over_two()3095 fn sin_tau_over_two() {
3096 test_eval("sin (tau / 2)", "0");
3097 }
3098
3099 #[test]
greek_pi_symbol()3100 fn greek_pi_symbol() {
3101 test_eval("π", "approx. 3.1415926535");
3102 }
3103
3104 #[test]
greek_tau_symbol()3105 fn greek_tau_symbol() {
3106 test_eval("τ", "approx. 6.2831853071");
3107 }
3108
3109 #[test]
tan_0()3110 fn tan_0() {
3111 test_eval("tan 0", "0");
3112 }
3113
3114 #[test]
tan_pi()3115 fn tan_pi() {
3116 test_eval("tan pi", "0");
3117 }
3118
3119 #[test]
tan_2pi()3120 fn tan_2pi() {
3121 test_eval("tan (2pi)", "0");
3122 }
3123
3124 #[test]
asin_1()3125 fn asin_1() {
3126 test_eval("asin 1", "approx. 1.5707963267");
3127 }
3128
3129 #[test]
asin_3()3130 fn asin_3() {
3131 test_eval("asin 3", "approx. 1.5707963267 - 1.762747174i");
3132 }
3133
3134 #[test]
asin_minus_3()3135 fn asin_minus_3() {
3136 test_eval("asin (-3)", "approx. -1.5707963267 + 1.762747174i");
3137 }
3138
3139 #[test]
asin_one_point_zero_one()3140 fn asin_one_point_zero_one() {
3141 test_eval("asin 1.01", "approx. 1.5707963267 - 0.1413037694i");
3142 }
3143
3144 #[test]
asin_minus_one_point_zero_one()3145 fn asin_minus_one_point_zero_one() {
3146 test_eval("asin (-1.01)", "approx. -1.5707963267 + 0.1413037694i");
3147 }
3148
3149 #[test]
acos_0()3150 fn acos_0() {
3151 test_eval("acos 0", "approx. 1.5707963267");
3152 }
3153
3154 #[test]
acos_3()3155 fn acos_3() {
3156 test_eval_simple("acos 3", "approx. 0 + 1.762747174i");
3157 }
3158
3159 #[test]
acos_minus_3()3160 fn acos_minus_3() {
3161 test_eval("acos (-3)", "approx. 3.1415926535 - 1.762747174i");
3162 }
3163
3164 #[test]
acos_one_point_zero_one()3165 fn acos_one_point_zero_one() {
3166 test_eval_simple("acos 1.01", "approx. 0 + 0.1413037694i");
3167 }
3168
3169 #[test]
acos_minus_one_point_zero_one()3170 fn acos_minus_one_point_zero_one() {
3171 test_eval("acos (-1.01)", "approx. 3.1415926535 - 0.1413037694i");
3172 }
3173
3174 #[test]
acos_one()3175 fn acos_one() {
3176 test_eval("acos 1", "approx. 0");
3177 }
3178
3179 #[test]
acos_minus_one()3180 fn acos_minus_one() {
3181 test_eval("acos (-1)", "approx. 3.1415926535");
3182 }
3183
3184 #[test]
atan_1()3185 fn atan_1() {
3186 test_eval("atan 1", "approx. 0.7853981633");
3187 }
3188
3189 #[test]
sinh_0()3190 fn sinh_0() {
3191 test_eval("sinh 0", "approx. 0");
3192 }
3193
3194 #[test]
cosh_0()3195 fn cosh_0() {
3196 test_eval("cosh 0", "approx. 1");
3197 }
3198
3199 #[test]
tanh_0()3200 fn tanh_0() {
3201 test_eval("tanh 0", "approx. 0");
3202 }
3203
3204 #[test]
asinh_0()3205 fn asinh_0() {
3206 test_eval("asinh 0", "approx. 0");
3207 }
3208
3209 #[test]
acosh_0()3210 fn acosh_0() {
3211 test_eval("acosh 0", "approx. 1.5707963267i");
3212 }
3213
3214 #[test]
acosh_2()3215 fn acosh_2() {
3216 test_eval("acosh 2", "approx. 1.3169578969");
3217 }
3218
3219 #[test]
atanh_0()3220 fn atanh_0() {
3221 test_eval("atanh 0", "approx. 0");
3222 }
3223
3224 #[test]
atanh_3()3225 fn atanh_3() {
3226 test_eval("atanh 3", "approx. 0.3465735902 + 1.5707963267i");
3227 }
3228
3229 #[test]
atanh_minus_3()3230 fn atanh_minus_3() {
3231 test_eval("atanh (-3)", "approx. -0.3465735902 + 1.5707963267i");
3232 }
3233
3234 #[test]
atanh_one_point_zero_one()3235 fn atanh_one_point_zero_one() {
3236 test_eval("atanh 1.01", "approx. 2.651652454 + 1.5707963267i");
3237 }
3238
3239 #[test]
atanh_minus_one_point_zero_one()3240 fn atanh_minus_one_point_zero_one() {
3241 test_eval("atanh (-1.01)", "approx. -2.651652454 + 1.5707963267i");
3242 }
3243
3244 #[test]
atanh_1()3245 fn atanh_1() {
3246 expect_error("atanh 1", None);
3247 }
3248
3249 #[test]
atanh_minus_1()3250 fn atanh_minus_1() {
3251 expect_error("atanh (-1)", None);
3252 }
3253
3254 #[test]
ln_2()3255 fn ln_2() {
3256 test_eval("ln 2", "approx. 0.6931471805");
3257 }
3258
3259 #[test]
ln_0()3260 fn ln_0() {
3261 expect_error("ln 0", None);
3262 }
3263
3264 #[test]
exp_2()3265 fn exp_2() {
3266 test_eval("exp 2", "approx. 7.3890560989");
3267 }
3268
3269 #[test]
log10_100()3270 fn log10_100() {
3271 test_eval("log10 100", "approx. 2");
3272 }
3273
3274 #[test]
log10_1000()3275 fn log10_1000() {
3276 test_eval("log10 1000", "approx. 3");
3277 }
3278
3279 #[test]
log10_10000()3280 fn log10_10000() {
3281 test_eval("log10 10000", "approx. 4");
3282 }
3283
3284 #[test]
log10_100000()3285 fn log10_100000() {
3286 test_eval("log10 100000", "approx. 5");
3287 }
3288
3289 #[test]
log_100()3290 fn log_100() {
3291 test_eval("log 100", "approx. 2");
3292 }
3293
3294 #[test]
log_1000()3295 fn log_1000() {
3296 test_eval("log 1000", "approx. 3");
3297 }
3298
3299 #[test]
log_10000()3300 fn log_10000() {
3301 test_eval("log 10000", "approx. 4");
3302 }
3303
3304 #[test]
log_100000()3305 fn log_100000() {
3306 test_eval("log 100000", "approx. 5");
3307 }
3308
3309 #[test]
log2_65536()3310 fn log2_65536() {
3311 test_eval("log2 65536", "approx. 16");
3312 }
3313
3314 #[test]
log10_minus_1()3315 fn log10_minus_1() {
3316 test_eval("log10 (-1)", "approx. 1.3643763538i");
3317 }
3318
3319 #[test]
log2_minus_1()3320 fn log2_minus_1() {
3321 test_eval("log2 (-1)", "approx. 4.5323601418i");
3322 }
3323
3324 #[test]
sqrt_minus_two()3325 fn sqrt_minus_two() {
3326 test_eval_simple("sqrt(-2)", "approx. 0 + 1.4142135623i");
3327 }
3328
3329 #[test]
minus_two_cubed()3330 fn minus_two_cubed() {
3331 test_eval("(-2)^3", "-8");
3332 }
3333
3334 #[test]
minus_two_pow_five()3335 fn minus_two_pow_five() {
3336 test_eval("(-2)^5", "-32");
3337 }
3338
3339 #[test]
two_pow_minus_two()3340 fn two_pow_minus_two() {
3341 test_eval("2^-2", "0.25");
3342 }
3343
3344 #[test]
minus_two_to_the_power_of_minus_two()3345 fn minus_two_to_the_power_of_minus_two() {
3346 test_eval("(-2)^-2", "0.25");
3347 }
3348
3349 #[test]
minus_two_to_the_power_of_minus_three()3350 fn minus_two_to_the_power_of_minus_three() {
3351 test_eval("(-2)^-3", "-0.125");
3352 }
3353
3354 #[test]
minus_two_to_the_power_of_minus_four()3355 fn minus_two_to_the_power_of_minus_four() {
3356 test_eval("(-2)^-4", "0.0625");
3357 }
3358
3359 #[test]
invalid_function_call()3360 fn invalid_function_call() {
3361 expect_error("oishfod 3", None);
3362 }
3363
3364 #[test]
ln()3365 fn ln() {
3366 test_eval("ln", "ln");
3367 }
3368
3369 #[test]
dp()3370 fn dp() {
3371 test_eval("dp", "dp");
3372 }
3373
3374 #[test]
ten_dp()3375 fn ten_dp() {
3376 test_eval("10 dp", "10 dp");
3377 }
3378
3379 #[test]
float()3380 fn float() {
3381 test_eval("float", "float");
3382 }
3383
3384 #[test]
fraction()3385 fn fraction() {
3386 test_eval("fraction", "fraction");
3387 }
3388
3389 #[test]
auto()3390 fn auto() {
3391 test_eval("auto", "auto");
3392 }
3393
3394 #[test]
sqrt_i()3395 fn sqrt_i() {
3396 test_eval("sqrt i", "approx. 0.7071067811 + 0.7071067811i");
3397 }
3398
3399 #[test]
sqrt_minus_two_i()3400 fn sqrt_minus_two_i() {
3401 // FIXME: exactly 1 - i
3402 test_eval("sqrt (-2i)", "approx. 0.9999999999 - 0.9999999999i");
3403 }
3404
3405 #[test]
cbrt_i()3406 fn cbrt_i() {
3407 // FIXME: exactly 0.8660 + 0.5i
3408 test_eval("cbrt i", "approx. 0.8660254037 + 0.4999999999i");
3409 }
3410
3411 #[test]
cbrt_minus_two_i()3412 fn cbrt_minus_two_i() {
3413 test_eval("cbrt (-2i)", "approx. 1.0911236359 - 0.6299605249i");
3414 }
3415
3416 #[test]
sin_i()3417 fn sin_i() {
3418 test_eval("sin i", "approx. 1.1752011936i");
3419 }
3420
3421 #[test]
cos_i()3422 fn cos_i() {
3423 test_eval("cos i", "approx. 1.5430806348");
3424 }
3425
3426 #[test]
tan_i()3427 fn tan_i() {
3428 test_eval("tan i", "approx. 0.7615941559i");
3429 }
3430
3431 #[test]
ln_i()3432 fn ln_i() {
3433 test_eval("ln i", "approx. 1.5707963267i");
3434 }
3435
3436 #[test]
log2_i()3437 fn log2_i() {
3438 test_eval("log2 i", "approx. 2.2661800709i");
3439 }
3440
3441 #[test]
log10_i()3442 fn log10_i() {
3443 test_eval("log10 i", "approx. 0.6821881769i");
3444 }
3445
3446 #[test]
dp_1()3447 fn dp_1() {
3448 expect_error("dp 1", None);
3449 }
3450
3451 #[test]
unary_div_seconds()3452 fn unary_div_seconds() {
3453 test_eval("/s", "1 s^-1");
3454 }
3455
3456 #[test]
per_second()3457 fn per_second() {
3458 test_eval("per second", "1 second^-1");
3459 }
3460
3461 #[test]
hertz_plus_unary_div_seconds()3462 fn hertz_plus_unary_div_seconds() {
3463 test_eval("1 Hz + /s", "2 Hz");
3464 }
3465
3466 #[test]
lambda_1()3467 fn lambda_1() {
3468 test_eval("(x: x) 1", "1");
3469 }
3470
3471 #[test]
lambda_2()3472 fn lambda_2() {
3473 test_eval("(x: y: x) 1 2", "1");
3474 }
3475
3476 #[test]
lambda_3()3477 fn lambda_3() {
3478 test_eval(
3479 "(cis: (cis (pi/3))) (x: cos x + i * (sin x))",
3480 "approx. 0.5 + 0.8660254037i",
3481 );
3482 }
3483
3484 #[test]
lambda_4()3485 fn lambda_4() {
3486 test_eval("(x: iuwhe)", "\\x.iuwhe");
3487 }
3488
3489 #[test]
lambda_5()3490 fn lambda_5() {
3491 test_eval("(b: 5 + b) 1", "6");
3492 }
3493
3494 #[test]
lambda_6()3495 fn lambda_6() {
3496 test_eval("(addFive: 4)(b: 5 + b)", "4");
3497 }
3498
3499 #[test]
lambda_7()3500 fn lambda_7() {
3501 test_eval("(addFive: addFive 4)(b: 5 + b)", "9");
3502 }
3503
3504 #[test]
lambda_8()3505 fn lambda_8() {
3506 test_eval("(x: y: z: x) 1 2 3", "1");
3507 }
3508
3509 #[test]
lambda_9()3510 fn lambda_9() {
3511 test_eval("(x: y: z: y) 1 2 3", "2");
3512 }
3513
3514 #[test]
lambda_10()3515 fn lambda_10() {
3516 test_eval("(x: y: z: z) 1 2 3", "3");
3517 }
3518
3519 #[test]
lambda_11()3520 fn lambda_11() {
3521 test_eval("(one: one + 4) 1", "5");
3522 }
3523
3524 #[test]
lambda_12()3525 fn lambda_12() {
3526 test_eval("(one: one + one) 1", "2");
3527 }
3528
3529 #[test]
lambda_13()3530 fn lambda_13() {
3531 test_eval("(x: x to kg) (5 g)", "0.005 kg");
3532 }
3533
3534 #[test]
lambda_14()3535 fn lambda_14() {
3536 test_eval("(p: q: p p q) (x: y: y) (x: y: y) 1 0", "0");
3537 }
3538
3539 #[test]
lambda_15()3540 fn lambda_15() {
3541 test_eval("(p: q: p p q) (x: y: y) (x: y: x) 1 0", "1");
3542 }
3543
3544 #[test]
lambda_16()3545 fn lambda_16() {
3546 test_eval("(p: q: p p q) (x: y: x) (x: y: y) 1 0", "1");
3547 }
3548
3549 #[test]
lambda_17()3550 fn lambda_17() {
3551 test_eval("(p: q: p p q) (x: y: x) (x: y: x) 1 0", "1");
3552 }
3553
3554 #[test]
lambda_18()3555 fn lambda_18() {
3556 test_eval("(x => x) 1", "1");
3557 }
3558
3559 #[test]
lambda_19()3560 fn lambda_19() {
3561 test_eval("(x: y => x) 1 2", "1");
3562 }
3563
3564 #[test]
lambda_20()3565 fn lambda_20() {
3566 test_eval("(\\x. y => x) 1 2", "1");
3567 }
3568
3569 #[test]
lambda_21()3570 fn lambda_21() {
3571 test_eval("(\\x.\\y.x)1 2", "1");
3572 }
3573
3574 #[test]
lambda_22()3575 fn lambda_22() {
3576 test_eval("a. => 0", "a.:0");
3577 }
3578
3579 #[test]
unit_to_the_power_of_pi()3580 fn unit_to_the_power_of_pi() {
3581 test_eval("kg^pi", "1 kg^π");
3582 }
3583
3584 #[test]
more_complex_unit_power_of_pi()3585 fn more_complex_unit_power_of_pi() {
3586 test_eval("kg^(2pi) / kg^(2pi) to 1", "1");
3587 }
3588
3589 #[test]
cis_0()3590 fn cis_0() {
3591 test_eval("cis 0", "1");
3592 }
3593
3594 #[test]
cis_pi()3595 fn cis_pi() {
3596 test_eval("cis pi", "-1");
3597 }
3598
3599 #[test]
cis_half_pi()3600 fn cis_half_pi() {
3601 test_eval("cis (pi/2)", "i");
3602 }
3603
3604 #[test]
cis_three_pi_over_two()3605 fn cis_three_pi_over_two() {
3606 test_eval("cis (3pi/2)", "-i");
3607 }
3608
3609 #[test]
cis_two_pi()3610 fn cis_two_pi() {
3611 test_eval("cis (2pi)", "1");
3612 }
3613
3614 #[test]
cis_minus_two_pi()3615 fn cis_minus_two_pi() {
3616 test_eval("cis -(2pi)", "1");
3617 }
3618
3619 #[test]
cis_pi_over_six()3620 fn cis_pi_over_six() {
3621 test_eval("cis (pi/6)", "approx. 0.8660254037 + 0.5i");
3622 }
3623
3624 #[test]
name_one()3625 fn name_one() {
3626 test_eval("one", "1");
3627 }
3628
3629 #[test]
name_two()3630 fn name_two() {
3631 test_eval("two", "2");
3632 }
3633
3634 #[test]
name_three()3635 fn name_three() {
3636 test_eval("three", "3");
3637 }
3638
3639 #[test]
name_four()3640 fn name_four() {
3641 test_eval("four", "4");
3642 }
3643
3644 #[test]
name_five()3645 fn name_five() {
3646 test_eval("five", "5");
3647 }
3648
3649 #[test]
name_six()3650 fn name_six() {
3651 test_eval("six", "6");
3652 }
3653
3654 #[test]
name_seven()3655 fn name_seven() {
3656 test_eval("seven", "7");
3657 }
3658
3659 #[test]
name_eight()3660 fn name_eight() {
3661 test_eval("eight", "8");
3662 }
3663
3664 #[test]
name_nine()3665 fn name_nine() {
3666 test_eval("nine", "9");
3667 }
3668
3669 #[test]
name_ten()3670 fn name_ten() {
3671 test_eval("ten", "10");
3672 }
3673
3674 #[test]
name_eleven()3675 fn name_eleven() {
3676 test_eval("eleven", "11");
3677 }
3678
3679 #[test]
name_twelve()3680 fn name_twelve() {
3681 test_eval("twelve", "12");
3682 }
3683
3684 #[test]
name_thirteen()3685 fn name_thirteen() {
3686 test_eval("thirteen", "13");
3687 }
3688
3689 #[test]
name_fourteen()3690 fn name_fourteen() {
3691 test_eval("fourteen", "14");
3692 }
3693
3694 #[test]
name_fifteen()3695 fn name_fifteen() {
3696 test_eval("fifteen", "15");
3697 }
3698
3699 #[test]
name_sixteen()3700 fn name_sixteen() {
3701 test_eval("sixteen", "16");
3702 }
3703
3704 #[test]
name_seventeen()3705 fn name_seventeen() {
3706 test_eval("seventeen", "17");
3707 }
3708
3709 #[test]
name_eighteen()3710 fn name_eighteen() {
3711 test_eval("eighteen", "18");
3712 }
3713
3714 #[test]
name_nineteen()3715 fn name_nineteen() {
3716 test_eval("nineteen", "19");
3717 }
3718
3719 #[test]
name_twenty()3720 fn name_twenty() {
3721 test_eval("twenty", "20");
3722 }
3723
3724 #[test]
name_thirty()3725 fn name_thirty() {
3726 test_eval("thirty", "30");
3727 }
3728
3729 #[test]
name_forty()3730 fn name_forty() {
3731 test_eval("forty", "40");
3732 }
3733
3734 #[test]
name_fifty()3735 fn name_fifty() {
3736 test_eval("fifty", "50");
3737 }
3738
3739 #[test]
name_sixty()3740 fn name_sixty() {
3741 test_eval("sixty", "60");
3742 }
3743
3744 #[test]
name_seventy()3745 fn name_seventy() {
3746 test_eval("seventy", "70");
3747 }
3748
3749 #[test]
name_eighty()3750 fn name_eighty() {
3751 test_eval("eighty", "80");
3752 }
3753
3754 #[test]
name_ninety()3755 fn name_ninety() {
3756 test_eval("ninety", "90");
3757 }
3758
3759 #[test]
name_hundred()3760 fn name_hundred() {
3761 test_eval("hundred", "100");
3762 }
3763
3764 #[test]
name_thousand()3765 fn name_thousand() {
3766 test_eval("thousand", "1000");
3767 }
3768
3769 #[test]
name_million()3770 fn name_million() {
3771 test_eval("million", "1000000");
3772 }
3773
3774 #[test]
name_dozen()3775 fn name_dozen() {
3776 test_eval("dozen", "12");
3777 }
3778
3779 #[test]
name_one_dozen()3780 fn name_one_dozen() {
3781 test_eval("one dozen", "12");
3782 }
3783
3784 #[test]
name_two_dozen()3785 fn name_two_dozen() {
3786 test_eval("two dozen", "24");
3787 }
3788
3789 #[test]
name_three_dozen()3790 fn name_three_dozen() {
3791 test_eval("three dozen", "36");
3792 }
3793
3794 #[test]
name_four_dozen()3795 fn name_four_dozen() {
3796 test_eval("four dozen", "48");
3797 }
3798
3799 #[test]
name_five_dozen()3800 fn name_five_dozen() {
3801 test_eval("five dozen", "60");
3802 }
3803
3804 #[test]
name_six_dozen()3805 fn name_six_dozen() {
3806 test_eval("six dozen", "72");
3807 }
3808
3809 #[test]
name_seven_dozen()3810 fn name_seven_dozen() {
3811 test_eval("seven dozen", "84");
3812 }
3813
3814 #[test]
name_eight_dozen()3815 fn name_eight_dozen() {
3816 test_eval("eight dozen", "96");
3817 }
3818
3819 #[test]
name_nine_dozen()3820 fn name_nine_dozen() {
3821 test_eval("nine dozen", "108");
3822 }
3823
3824 #[test]
name_ten_dozen()3825 fn name_ten_dozen() {
3826 test_eval("ten dozen", "120");
3827 }
3828
3829 #[test]
name_eleven_dozen()3830 fn name_eleven_dozen() {
3831 test_eval("eleven dozen", "132");
3832 }
3833
3834 #[test]
name_twelve_dozen()3835 fn name_twelve_dozen() {
3836 test_eval("twelve dozen", "144");
3837 }
3838
3839 #[test]
name_gross()3840 fn name_gross() {
3841 test_eval("gross", "144");
3842 }
3843
3844 #[test]
name_thirteen_dozen()3845 fn name_thirteen_dozen() {
3846 test_eval("thirteen dozen", "156");
3847 }
3848
3849 #[test]
name_fourteen_dozen()3850 fn name_fourteen_dozen() {
3851 test_eval("fourteen dozen", "168");
3852 }
3853
3854 #[test]
name_fifteen_dozen()3855 fn name_fifteen_dozen() {
3856 test_eval("fifteen dozen", "180");
3857 }
3858
3859 #[test]
name_sixteen_dozen()3860 fn name_sixteen_dozen() {
3861 test_eval("sixteen dozen", "192");
3862 }
3863
3864 #[test]
name_seventeen_dozen()3865 fn name_seventeen_dozen() {
3866 test_eval("seventeen dozen", "204");
3867 }
3868
3869 #[test]
name_eighteen_dozen()3870 fn name_eighteen_dozen() {
3871 test_eval("eighteen dozen", "216");
3872 }
3873
3874 #[test]
name_nineteen_dozen()3875 fn name_nineteen_dozen() {
3876 test_eval("nineteen dozen", "228");
3877 }
3878
3879 #[test]
name_twenty_dozen()3880 fn name_twenty_dozen() {
3881 test_eval("twenty dozen", "240");
3882 }
3883
3884 #[test]
name_thirty_dozen()3885 fn name_thirty_dozen() {
3886 test_eval("thirty dozen", "360");
3887 }
3888
3889 #[test]
name_forty_dozen()3890 fn name_forty_dozen() {
3891 test_eval("forty dozen", "480");
3892 }
3893
3894 #[test]
name_fifty_dozen()3895 fn name_fifty_dozen() {
3896 test_eval("fifty dozen", "600");
3897 }
3898
3899 #[test]
name_sixty_dozen()3900 fn name_sixty_dozen() {
3901 test_eval("sixty dozen", "720");
3902 }
3903
3904 #[test]
name_seventy_dozen()3905 fn name_seventy_dozen() {
3906 test_eval("seventy dozen", "840");
3907 }
3908
3909 #[test]
name_eighty_dozen()3910 fn name_eighty_dozen() {
3911 test_eval("eighty dozen", "960");
3912 }
3913
3914 #[test]
name_ninety_dozen()3915 fn name_ninety_dozen() {
3916 test_eval("ninety dozen", "1080");
3917 }
3918
3919 #[test]
name_hundred_dozen()3920 fn name_hundred_dozen() {
3921 test_eval("hundred dozen", "1200");
3922 }
3923
3924 #[test]
name_thousand_dozen()3925 fn name_thousand_dozen() {
3926 test_eval("thousand dozen", "12000");
3927 }
3928
3929 #[test]
name_million_dozen()3930 fn name_million_dozen() {
3931 test_eval("million dozen", "12000000");
3932 }
3933
3934 #[test]
lone_prefix_yotta()3935 fn lone_prefix_yotta() {
3936 test_eval("yotta", "1000000000000000000000000");
3937 }
3938
3939 #[test]
lone_prefix_zetta()3940 fn lone_prefix_zetta() {
3941 test_eval("zetta", "1000000000000000000000");
3942 }
3943
3944 #[test]
lone_prefix_exa()3945 fn lone_prefix_exa() {
3946 test_eval("exa", "1000000000000000000");
3947 }
3948
3949 #[test]
lone_prefix_peta()3950 fn lone_prefix_peta() {
3951 test_eval("peta", "1000000000000000");
3952 }
3953
3954 #[test]
lone_prefix_tera()3955 fn lone_prefix_tera() {
3956 test_eval("tera", "1000000000000");
3957 }
3958
3959 #[test]
lone_prefix_giga()3960 fn lone_prefix_giga() {
3961 test_eval("giga", "1000000000");
3962 }
3963
3964 #[test]
lone_prefix_mega()3965 fn lone_prefix_mega() {
3966 test_eval("mega", "1000000");
3967 }
3968
3969 #[test]
lone_prefix_myria()3970 fn lone_prefix_myria() {
3971 test_eval("myria", "10000");
3972 }
3973
3974 #[test]
lone_prefix_kilo()3975 fn lone_prefix_kilo() {
3976 test_eval("kilo", "1000");
3977 }
3978
3979 #[test]
lone_prefix_hecto()3980 fn lone_prefix_hecto() {
3981 test_eval("hecto", "100");
3982 }
3983
3984 #[test]
lone_prefix_deca()3985 fn lone_prefix_deca() {
3986 test_eval("deca", "10");
3987 }
3988
3989 #[test]
lone_prefix_deka()3990 fn lone_prefix_deka() {
3991 test_eval("deka", "10");
3992 }
3993
3994 #[test]
lone_prefix_deci()3995 fn lone_prefix_deci() {
3996 test_eval("deci", "0.1");
3997 }
3998
3999 #[test]
lone_prefix_centi()4000 fn lone_prefix_centi() {
4001 test_eval("centi", "0.01");
4002 }
4003
4004 #[test]
lone_prefix_milli()4005 fn lone_prefix_milli() {
4006 test_eval("milli", "0.001");
4007 }
4008
4009 #[test]
lone_prefix_micro()4010 fn lone_prefix_micro() {
4011 test_eval("micro", "0.000001");
4012 }
4013
4014 #[test]
lone_prefix_nano()4015 fn lone_prefix_nano() {
4016 test_eval("nano", "0.000000001");
4017 }
4018
4019 #[test]
lone_prefix_pico()4020 fn lone_prefix_pico() {
4021 test_eval("pico", "0.000000000001");
4022 }
4023
4024 #[test]
lone_prefix_femto()4025 fn lone_prefix_femto() {
4026 test_eval("femto", "0.000000000000001");
4027 }
4028
4029 #[test]
lone_prefix_atto()4030 fn lone_prefix_atto() {
4031 test_eval("atto", "0.000000000000000001");
4032 }
4033
4034 #[test]
lone_prefix_zepto()4035 fn lone_prefix_zepto() {
4036 test_eval("zepto", "0.000000000000000000001");
4037 }
4038
4039 #[test]
lone_prefix_yocto()4040 fn lone_prefix_yocto() {
4041 test_eval("yocto", "0.000000000000000000000001");
4042 }
4043
4044 #[test]
billion()4045 fn billion() {
4046 test_eval("billion", "1000000000");
4047 }
4048
4049 #[test]
trillion()4050 fn trillion() {
4051 test_eval("trillion", "1000000000000");
4052 }
4053
4054 #[test]
quadrillion()4055 fn quadrillion() {
4056 test_eval("quadrillion", "1000000000000000");
4057 }
4058
4059 #[test]
quintillion()4060 fn quintillion() {
4061 test_eval("quintillion", "1000000000000000000");
4062 }
4063
4064 #[test]
sextillion()4065 fn sextillion() {
4066 test_eval("sextillion", "1000000000000000000000");
4067 }
4068
4069 #[test]
septillion()4070 fn septillion() {
4071 test_eval("septillion", "1000000000000000000000000");
4072 }
4073
4074 #[test]
octillion()4075 fn octillion() {
4076 test_eval("octillion", "1000000000000000000000000000");
4077 }
4078
4079 #[test]
nonillion()4080 fn nonillion() {
4081 test_eval("nonillion", "1000000000000000000000000000000");
4082 }
4083
4084 #[test]
decillion()4085 fn decillion() {
4086 test_eval("decillion", "1000000000000000000000000000000000");
4087 }
4088
4089 #[test]
undecillion()4090 fn undecillion() {
4091 test_eval("undecillion", "1000000000000000000000000000000000000");
4092 }
4093
4094 #[test]
duodecillion()4095 fn duodecillion() {
4096 test_eval("duodecillion", "1000000000000000000000000000000000000000");
4097 }
4098
4099 #[test]
tredecillion()4100 fn tredecillion() {
4101 test_eval(
4102 "tredecillion",
4103 "1000000000000000000000000000000000000000000",
4104 );
4105 }
4106
4107 #[test]
quattuordecillion()4108 fn quattuordecillion() {
4109 test_eval(
4110 "quattuordecillion",
4111 "1000000000000000000000000000000000000000000000",
4112 );
4113 }
4114
4115 #[test]
quindecillion()4116 fn quindecillion() {
4117 test_eval(
4118 "quindecillion",
4119 "1000000000000000000000000000000000000000000000000",
4120 );
4121 }
4122
4123 #[test]
sexdecillion()4124 fn sexdecillion() {
4125 test_eval(
4126 "sexdecillion",
4127 "1000000000000000000000000000000000000000000000000000",
4128 );
4129 }
4130
4131 #[test]
septendecillion()4132 fn septendecillion() {
4133 test_eval(
4134 "septendecillion",
4135 "1000000000000000000000000000000000000000000000000000000",
4136 );
4137 }
4138
4139 #[test]
octodecillion()4140 fn octodecillion() {
4141 test_eval(
4142 "octodecillion",
4143 "1000000000000000000000000000000000000000000000000000000000",
4144 );
4145 }
4146
4147 #[test]
novemdecillion()4148 fn novemdecillion() {
4149 test_eval(
4150 "novemdecillion",
4151 "1000000000000000000000000000000000000000000000000000000000000",
4152 );
4153 }
4154
4155 #[test]
vigintillion()4156 fn vigintillion() {
4157 test_eval(
4158 "vigintillion",
4159 "1000000000000000000000000000000000000000000000000000000000000000",
4160 );
4161 }
4162
4163 #[test]
one_cent()4164 fn one_cent() {
4165 test_eval("cent", "1 cent");
4166 }
4167
4168 #[test]
two_cent()4169 fn two_cent() {
4170 test_eval("2 cent", "2 cents");
4171 }
4172
4173 #[test]
to_dp()4174 fn to_dp() {
4175 expect_error("1 to dp", None);
4176 }
4177
4178 #[test]
to_sf()4179 fn to_sf() {
4180 expect_error("1 to sf", None);
4181 }
4182
4183 #[test]
sf()4184 fn sf() {
4185 test_eval("sf", "sf");
4186 }
4187
4188 #[test]
one_sf()4189 fn one_sf() {
4190 test_eval("1 sf", "1 sf");
4191 }
4192
4193 #[test]
ten_sf()4194 fn ten_sf() {
4195 test_eval("10 sf", "10 sf");
4196 }
4197
4198 #[test]
one_over_sin()4199 fn one_over_sin() {
4200 test_eval_simple("1/sin", "\\x.(1/(sin x))");
4201 }
4202
4203 #[test]
zero_sf()4204 fn zero_sf() {
4205 expect_error("0 sf", None);
4206 }
4207
4208 #[test]
sf_1()4209 fn sf_1() {
4210 test_eval("1234567.55645 to 1 sf", "approx. 1000000");
4211 }
4212
4213 #[test]
sf_2()4214 fn sf_2() {
4215 test_eval("1234567.55645 to 2 sf", "approx. 1200000");
4216 }
4217
4218 #[test]
sf_3()4219 fn sf_3() {
4220 test_eval("1234567.55645 to 3 sf", "approx. 1230000");
4221 }
4222
4223 #[test]
sf_4()4224 fn sf_4() {
4225 test_eval("1234567.55645 to 4 sf", "approx. 1234000");
4226 }
4227
4228 #[test]
sf_5()4229 fn sf_5() {
4230 test_eval("1234567.55645 to 5 sf", "approx. 1234500");
4231 }
4232
4233 #[test]
sf_6()4234 fn sf_6() {
4235 test_eval("1234567.55645 to 6 sf", "approx. 1234560");
4236 }
4237
4238 #[test]
sf_7()4239 fn sf_7() {
4240 test_eval("1234567.55645 to 7 sf", "approx. 1234567");
4241 }
4242
4243 #[test]
sf_8()4244 fn sf_8() {
4245 test_eval("1234567.55645 to 8 sf", "approx. 1234567.5");
4246 }
4247
4248 #[test]
sf_9()4249 fn sf_9() {
4250 test_eval("1234567.55645 to 9 sf", "approx. 1234567.55");
4251 }
4252
4253 #[test]
sf_10()4254 fn sf_10() {
4255 test_eval("1234567.55645 to 10 sf", "approx. 1234567.556");
4256 }
4257
4258 #[test]
sf_11()4259 fn sf_11() {
4260 test_eval("1234567.55645 to 11 sf", "approx. 1234567.5564");
4261 }
4262
4263 #[test]
sf_12()4264 fn sf_12() {
4265 test_eval("1234567.55645 to 12 sf", "1234567.55645");
4266 }
4267
4268 #[test]
sf_13()4269 fn sf_13() {
4270 test_eval("1234567.55645 to 13 sf", "1234567.55645");
4271 }
4272
4273 #[test]
sf_small_1()4274 fn sf_small_1() {
4275 test_eval("pi / 1000000 to 1 sf", "approx. 0.000003");
4276 }
4277
4278 #[test]
sf_small_2()4279 fn sf_small_2() {
4280 test_eval("pi / 1000000 to 2 sf", "approx. 0.0000031");
4281 }
4282
4283 #[test]
sf_small_3()4284 fn sf_small_3() {
4285 test_eval("pi / 1000000 to 3 sf", "approx. 0.00000314");
4286 }
4287
4288 #[test]
sf_small_4()4289 fn sf_small_4() {
4290 test_eval("pi / 1000000 to 4 sf", "approx. 0.000003141");
4291 }
4292
4293 #[test]
sf_small_5()4294 fn sf_small_5() {
4295 test_eval("pi / 1000000 to 5 sf", "approx. 0.0000031415");
4296 }
4297
4298 #[test]
sf_small_6()4299 fn sf_small_6() {
4300 test_eval_simple("pi / 1000000 to 6 sf", "approx. 0.00000314159");
4301 }
4302
4303 #[test]
sf_small_7()4304 fn sf_small_7() {
4305 test_eval_simple("pi / 1000000 to 7 sf", "approx. 0.000003141592");
4306 }
4307
4308 #[test]
sf_small_8()4309 fn sf_small_8() {
4310 test_eval_simple("pi / 1000000 to 8 sf", "approx. 0.0000031415926");
4311 }
4312
4313 #[test]
sf_small_9()4314 fn sf_small_9() {
4315 test_eval_simple("pi / 1000000 to 9 sf", "approx. 0.00000314159265");
4316 }
4317
4318 #[test]
sf_small_10()4319 fn sf_small_10() {
4320 test_eval_simple("pi / 1000000 to 10 sf", "approx. 0.000003141592653");
4321 }
4322
4323 #[test]
sf_small_11()4324 fn sf_small_11() {
4325 test_eval_simple("pi / 1000000 to 11 sf", "approx. 0.0000031415926535");
4326 }
4327
4328 #[test]
no_prefixes_for_speed_of_light()4329 fn no_prefixes_for_speed_of_light() {
4330 expect_error("mc", None);
4331 }
4332
4333 #[test]
quarter()4334 fn quarter() {
4335 test_eval("quarter", "0.25");
4336 }
4337
4338 #[test]
million_pi_1_sf()4339 fn million_pi_1_sf() {
4340 test_eval("1e6 pi to 1 sf", "approx. 3000000");
4341 }
4342
4343 #[test]
million_pi_2_sf()4344 fn million_pi_2_sf() {
4345 test_eval("1e6 pi to 2 sf", "approx. 3100000");
4346 }
4347
4348 #[test]
million_pi_3_sf()4349 fn million_pi_3_sf() {
4350 test_eval("1e6 pi to 3 sf", "approx. 3140000");
4351 }
4352
4353 #[test]
million_pi_4_sf()4354 fn million_pi_4_sf() {
4355 test_eval("1e6 pi to 4 sf", "approx. 3141000");
4356 }
4357
4358 #[test]
million_pi_5_sf()4359 fn million_pi_5_sf() {
4360 test_eval("1e6 pi to 5 sf", "approx. 3141500");
4361 }
4362
4363 #[test]
million_pi_6_sf()4364 fn million_pi_6_sf() {
4365 test_eval("1e6 pi to 6 sf", "approx. 3141590");
4366 }
4367
4368 #[test]
million_pi_7_sf()4369 fn million_pi_7_sf() {
4370 test_eval("1e6 pi to 7 sf", "approx. 3141592");
4371 }
4372
4373 #[test]
million_pi_8_sf()4374 fn million_pi_8_sf() {
4375 test_eval("1e6 pi to 8 sf", "approx. 3141592.6");
4376 }
4377
4378 #[test]
million_pi_9_sf()4379 fn million_pi_9_sf() {
4380 test_eval("1e6 pi to 9 sf", "approx. 3141592.65");
4381 }
4382
4383 #[test]
million_pi_10_sf()4384 fn million_pi_10_sf() {
4385 test_eval("1e6 pi to 10 sf", "approx. 3141592.653");
4386 }
4387
4388 #[test]
large_integer_to_1_sf()4389 fn large_integer_to_1_sf() {
4390 test_eval("1234567 to 1 sf", "approx. 1000000");
4391 }
4392
4393 #[test]
large_integer_to_2_sf()4394 fn large_integer_to_2_sf() {
4395 test_eval("1234567 to 2 sf", "approx. 1200000");
4396 }
4397
4398 #[test]
large_integer_to_3_sf()4399 fn large_integer_to_3_sf() {
4400 test_eval("1234567 to 3 sf", "approx. 1230000");
4401 }
4402
4403 #[test]
large_integer_to_4_sf()4404 fn large_integer_to_4_sf() {
4405 test_eval("1234567 to 4 sf", "approx. 1234000");
4406 }
4407
4408 #[test]
large_integer_to_5_sf()4409 fn large_integer_to_5_sf() {
4410 test_eval("1234567 to 5 sf", "approx. 1234500");
4411 }
4412
4413 #[test]
large_integer_to_6_sf()4414 fn large_integer_to_6_sf() {
4415 test_eval("1234567 to 6 sf", "approx. 1234560");
4416 }
4417
4418 #[test]
large_integer_to_7_sf()4419 fn large_integer_to_7_sf() {
4420 test_eval("1234567 to 7 sf", "1234567");
4421 }
4422
4423 #[test]
large_integer_to_8_sf()4424 fn large_integer_to_8_sf() {
4425 test_eval("1234567 to 8 sf", "1234567");
4426 }
4427
4428 #[test]
large_integer_to_9_sf()4429 fn large_integer_to_9_sf() {
4430 test_eval("1234567 to 9 sf", "1234567");
4431 }
4432
4433 #[test]
large_integer_to_10_sf()4434 fn large_integer_to_10_sf() {
4435 test_eval("1234567 to 10 sf", "1234567");
4436 }
4437
4438 #[test]
trailing_zeroes_sf_1()4439 fn trailing_zeroes_sf_1() {
4440 test_eval("1234560 to 5sf", "approx. 1234500");
4441 }
4442
4443 #[test]
trailing_zeroes_sf_2()4444 fn trailing_zeroes_sf_2() {
4445 test_eval("1234560 to 6sf", "1234560");
4446 }
4447
4448 #[test]
trailing_zeroes_sf_3()4449 fn trailing_zeroes_sf_3() {
4450 test_eval("1234560 to 7sf", "1234560");
4451 }
4452
4453 #[test]
trailing_zeroes_sf_4()4454 fn trailing_zeroes_sf_4() {
4455 test_eval("1234560.1 to 6sf", "approx. 1234560");
4456 }
4457
4458 #[test]
trailing_zeroes_sf_5()4459 fn trailing_zeroes_sf_5() {
4460 test_eval("12345601 to 6sf", "approx. 12345600");
4461 }
4462
4463 #[test]
trailing_zeroes_sf_6()4464 fn trailing_zeroes_sf_6() {
4465 test_eval("12345601 to 7sf", "approx. 12345600");
4466 }
4467
4468 #[test]
trailing_zeroes_sf_7()4469 fn trailing_zeroes_sf_7() {
4470 test_eval("12345601 to 8sf", "12345601");
4471 }
4472
4473 #[test]
kwh_conversion()4474 fn kwh_conversion() {
4475 test_eval("100 kWh/yr to watt", "approx. 11.4079552707 watts");
4476 }
4477
4478 #[test]
debug_pi_n()4479 fn debug_pi_n() {
4480 test_eval_simple(
4481 "@debug pi N",
4482 "pi N (= 1000/1000 kilogram meter second^-2) (base 10, auto, simplifiable)",
4483 );
4484 }
4485
4486 #[test]
square_m_to_sqft()4487 fn square_m_to_sqft() {
4488 test_eval("3 square feet to square meters", "0.27870912 meters^2");
4489 }
4490
4491 #[test]
test_hex_unit_conversion()4492 fn test_hex_unit_conversion() {
4493 test_eval_simple("1 yard lb to hex to kg m to 3sf", "approx. 0.6a2 kg m");
4494 }
4495
4496 #[test]
test_hex_unit_conversion_complex()4497 fn test_hex_unit_conversion_complex() {
4498 test_eval_simple("i yard lb to hex to kg m to 3sf", "approx. 0.6a2 i kg m");
4499 }
4500
4501 #[test]
convert_to_billion()4502 fn convert_to_billion() {
4503 test_eval_simple("1000000000 to billion", "1 billion");
4504 }
4505
4506 #[test]
acres_to_sqmi()4507 fn acres_to_sqmi() {
4508 test_eval("640 acre to mi^2", "1 mi^2");
4509 }
4510
4511 #[test]
one_square_mile_to_acres()4512 fn one_square_mile_to_acres() {
4513 test_eval("1 mile^2 to acre", "640 acres");
4514 }
4515
4516 #[test]
one_hectare_to_km_sq()4517 fn one_hectare_to_km_sq() {
4518 test_eval("1 hectare to km^2", "0.01 km^2");
4519 }
4520
4521 #[test]
two_km_sq_to_hectares()4522 fn two_km_sq_to_hectares() {
4523 test_eval("2 km^2 to hectare", "200 hectares");
4524 }
4525
4526 #[test]
kg_to_unitless()4527 fn kg_to_unitless() {
4528 expect_error(
4529 "kg to unitless",
4530 Some(
4531 "cannot convert from kg to unitless: units 'kilogram' and 'unitless' are incompatible",
4532 ),
4533 );
4534 }
4535
4536 #[test]
percent_to_unitless()4537 fn percent_to_unitless() {
4538 test_eval("1% to unitless", "0.01");
4539 }
4540
4541 #[test]
convert_to_numerical_product()4542 fn convert_to_numerical_product() {
4543 expect_error("550Mbit/s to GB/s * 12000s", None);
4544 }
4545
4546 #[test]
unit_simplification()4547 fn unit_simplification() {
4548 test_eval("0.18mL * 40 mg/mL", "7.2 mg");
4549 }
4550
4551 #[test]
unit_simplification_kg_1()4552 fn unit_simplification_kg_1() {
4553 test_eval("kg g", "0.001 kg^2");
4554 }
4555
4556 #[test]
unit_simplification_kg_2()4557 fn unit_simplification_kg_2() {
4558 test_eval("kg g^0", "1 kg");
4559 }
4560
4561 #[test]
unit_simplification_kg_3()4562 fn unit_simplification_kg_3() {
4563 test_eval("kg g^-1", "1000");
4564 }
4565
4566 #[test]
unit_simplification_kg_4()4567 fn unit_simplification_kg_4() {
4568 test_eval("kg^2 g", "0.001 kg^3");
4569 }
4570
4571 #[test]
unit_simplification_kg_5()4572 fn unit_simplification_kg_5() {
4573 test_eval("kg^2 g^0", "1 kg^2");
4574 }
4575
4576 #[test]
unit_simplification_kg_6()4577 fn unit_simplification_kg_6() {
4578 test_eval("kg^2 g^-1", "1000 kg");
4579 }
4580
4581 #[test]
unit_simplification_kg_7()4582 fn unit_simplification_kg_7() {
4583 test_eval("kg^2 g^-2", "1000000");
4584 }
4585
4586 #[test]
eccentricity_of_earth()4587 fn eccentricity_of_earth() {
4588 test_eval("eccentricity of earth", "0.0167086");
4589 }
4590
4591 #[test]
mass_of_earth()4592 fn mass_of_earth() {
4593 test_eval("mass of earth", "5972370000000000000000000 kg");
4594 }
4595
4596 #[test]
maths_with_earth_properties()4597 fn maths_with_earth_properties() {
4598 test_eval(
4599 "escape_velocity of earth / gravity of earth",
4600 "approx. 1140.6545558371 s",
4601 );
4602 }
4603
4604 #[test]
kelvin_to_rankine()4605 fn kelvin_to_rankine() {
4606 test_eval("273K to °R", "491.4 °R");
4607 }
4608
4609 #[test]
joule_per_kelvin_to_joule_per_celsius()4610 fn joule_per_kelvin_to_joule_per_celsius() {
4611 test_eval("1J/K to J/°C", "1 J / °C");
4612 }
4613
4614 #[test]
kelvin_plus_celsius()4615 fn kelvin_plus_celsius() {
4616 test_eval("1K+1°C", "2 K");
4617 }
4618
4619 #[test]
kelvin_plus_fahrenheit()4620 fn kelvin_plus_fahrenheit() {
4621 test_eval("1K+1°F", "approx. 1.5555555555 K");
4622 }
4623
4624 #[test]
celsius_plus_kelvin()4625 fn celsius_plus_kelvin() {
4626 test_eval("1°C+1K", "2 °C");
4627 }
4628
4629 #[test]
fahrenheit_plus_kelvin()4630 fn fahrenheit_plus_kelvin() {
4631 test_eval("1°F+1K", "2.8 °F");
4632 }
4633
4634 #[test]
celsius_plus_fahrenheit()4635 fn celsius_plus_fahrenheit() {
4636 test_eval("1°C+1°F", "approx. 1.5555555555 °C");
4637 }
4638
4639 #[test]
celsius_plus_rankine()4640 fn celsius_plus_rankine() {
4641 test_eval("1°C+1°R", "approx. 1.5555555555 °C");
4642 }
4643
4644 #[test]
fahrenheit_plus_celsius()4645 fn fahrenheit_plus_celsius() {
4646 test_eval("1°F+1°C", "2.8 °F");
4647 }
4648
4649 #[test]
fahrenheit_plus_kilokelvin()4650 fn fahrenheit_plus_kilokelvin() {
4651 test_eval("1°F+10kK", "18001 °F");
4652 }
4653
4654 #[test]
celsius_plus_millikelvin()4655 fn celsius_plus_millikelvin() {
4656 test_eval("-273.15°C+1mK", "-273.149 °C");
4657 }
4658
4659 #[test]
joule_per_kelvin_to_joule_per_fahrenheit()4660 fn joule_per_kelvin_to_joule_per_fahrenheit() {
4661 test_eval("1J/K to J/°F", "approx. 0.5555555555 J / °F");
4662 }
4663
4664 #[test]
ice_melting_point_to_kelvin()4665 fn ice_melting_point_to_kelvin() {
4666 test_eval("0°C to K", "273.15 K");
4667 }
4668
4669 #[test]
degrees_kelvin_as_alias()4670 fn degrees_kelvin_as_alias() {
4671 test_eval("6°K", "6 K");
4672 }
4673
4674 #[test]
fahrenheit_squared_plus_kelvin_squared()4675 fn fahrenheit_squared_plus_kelvin_squared() {
4676 test_eval("(1°F)^2 + 1 K^2", "4.24 °F^2");
4677 }
4678
4679 #[test]
fahrenheit_squared_to_kelvin_squared()4680 fn fahrenheit_squared_to_kelvin_squared() {
4681 test_eval("(1°F)^2 to 1 K^2", "approx. 0.3086419753 K^2");
4682 }
4683
4684 #[test]
hundred_celsius_to_fahrenheit()4685 fn hundred_celsius_to_fahrenheit() {
4686 test_eval("100°C to °F", "212 °F");
4687 }
4688
4689 #[test]
zero_celsius_to_fahrenheit()4690 fn zero_celsius_to_fahrenheit() {
4691 test_eval("0°C to °F", "32 °F");
4692 }
4693
4694 #[test]
zero_kelvin_to_fahrenheit()4695 fn zero_kelvin_to_fahrenheit() {
4696 test_eval("0K to °F", "-459.67 °F");
4697 }
4698
4699 #[test]
zero_millicelsius_to_fahrenheit()4700 fn zero_millicelsius_to_fahrenheit() {
4701 test_eval("0 millicelsius to °F", "32 °F");
4702 }
4703
4704 #[test]
zero_kilocelsius_to_fahrenheit()4705 fn zero_kilocelsius_to_fahrenheit() {
4706 test_eval("0 kilocelsius to °F", "32 °F");
4707 }
4708
4709 #[test]
zero_kilocelsius_to_millifahrenheit()4710 fn zero_kilocelsius_to_millifahrenheit() {
4711 test_eval("0 kilocelsius to millifahrenheit", "32000 millifahrenheit");
4712 }
4713
4714 #[test]
five_percent_celsius_to_fahrenheit()4715 fn five_percent_celsius_to_fahrenheit() {
4716 test_eval("5% °C to °F", "32.09 °F");
4717 }
4718
4719 #[test]
five_celsius_to_fahrenheit()4720 fn five_celsius_to_fahrenheit() {
4721 test_eval("5°C to °F", "41 °F");
4722 }
4723
4724 #[test]
fifteen_celsius_to_rankine()4725 fn fifteen_celsius_to_rankine() {
4726 test_eval("15°C to °R", "518.67 °R");
4727 }
4728
4729 #[test]
fifteen_celsius_to_kelvin()4730 fn fifteen_celsius_to_kelvin() {
4731 test_eval("15°C to K", "288.15 K");
4732 }
4733
4734 #[test]
celsius_as_c()4735 fn celsius_as_c() {
4736 test_eval("4C", "4 °C");
4737 }
4738
4739 #[test]
fahrenheit_as_f()4740 fn fahrenheit_as_f() {
4741 test_eval("4C to F", "39.2 °F");
4742 }
4743
4744 #[test]
radians_to_degrees()4745 fn radians_to_degrees() {
4746 test_eval("pi radians to °", "180°");
4747 }
4748
4749 #[test]
minus_40_fahrenheit_to_celsius()4750 fn minus_40_fahrenheit_to_celsius() {
4751 test_eval("-40 F to C", "-40 °C");
4752 }
4753
4754 #[test]
gigabits_to_gigabytes()4755 fn gigabits_to_gigabytes() {
4756 test_eval("25Gib/s to GB/s", "3.3554432 GB / s");
4757 }
4758
4759 #[test]
one_plus_one()4760 fn one_plus_one() {
4761 test_eval("1 + 1", "2");
4762 }
4763
4764 #[test]
unterminated_raw_empty_string()4765 fn unterminated_raw_empty_string() {
4766 expect_error("#\"", Some("unterminated string literal"));
4767 }
4768
4769 #[test]
unterminated_raw_string()4770 fn unterminated_raw_string() {
4771 expect_error("#\"hello", Some("unterminated string literal"));
4772 }
4773
4774 #[test]
empty_raw_string()4775 fn empty_raw_string() {
4776 test_eval("#\"\"#", "");
4777 }
4778
4779 #[test]
hello_world_raw_string()4780 fn hello_world_raw_string() {
4781 test_eval_simple("#\"Hello, world!\"#", "Hello, world!");
4782 }
4783
4784 #[test]
backslash_in_raw_string_literal()4785 fn backslash_in_raw_string_literal() {
4786 test_eval_simple("#\"\\\"#", "\\");
4787 }
4788
4789 #[test]
4790 fn double_quote_in_raw_string() {
4791 test_eval_simple("#\"A quote: \"\"#", "A quote: \"");
4792 }
4793
4794 #[test]
raw_string_debug_representation()4795 fn raw_string_debug_representation() {
4796 test_eval_simple("@debug #\"hi\"#", "\"hi\"");
4797 }
4798
4799 #[test]
string_debug_representation()4800 fn string_debug_representation() {
4801 test_eval_simple("@debug \"hi\"", "\"hi\"");
4802 }
4803
4804 #[test]
cis_4()4805 fn cis_4() {
4806 test_eval("cis 4", "approx. -0.6536436208 - 0.7568024953i");
4807 }
4808
4809 #[test]
a_prime()4810 fn a_prime() {
4811 expect_error("a'", Some("unknown identifier 'a''"));
4812 }
4813
4814 #[test]
a_double_prime()4815 fn a_double_prime() {
4816 expect_error("a\"", Some("unknown identifier 'a\"'"));
4817 }
4818
4819 #[test]
one_inch_with_space()4820 fn one_inch_with_space() {
4821 test_eval("1 \"", "1\"");
4822 }
4823
4824 #[test]
empty_string()4825 fn empty_string() {
4826 test_eval("\"\"", "");
4827 }
4828
4829 #[test]
unterminated_empty_string()4830 fn unterminated_empty_string() {
4831 expect_error("\"", Some("unterminated string literal"));
4832 }
4833
4834 #[test]
unterminated_string()4835 fn unterminated_string() {
4836 expect_error("\"hello", Some("unterminated string literal"));
4837 }
4838
4839 #[test]
hello_world_string()4840 fn hello_world_string() {
4841 test_eval_simple("\"Hello, world!\"", "Hello, world!");
4842 }
4843
4844 #[test]
backslash_in_string_literal()4845 fn backslash_in_string_literal() {
4846 test_eval_simple(r#""\\""#, "\\");
4847 }
4848
4849 #[test]
4850 fn add_string_to_number() {
4851 expect_error("\"hi\" + 2", Some("expected a number"));
4852 }
4853
4854 #[test]
simple_string_concatenation()4855 fn simple_string_concatenation() {
4856 test_eval_simple(r#""hi" + "a""#, "hia");
4857 }
4858
4859 #[test]
triple_string_concatenation()4860 fn triple_string_concatenation() {
4861 test_eval_simple(r#""hi" + "a" + "3""#, "hia3");
4862 }
4863
4864 #[test]
number_to_string()4865 fn number_to_string() {
4866 test_eval_simple("\"pi = \" + (pi to string)", "pi = approx. 3.1415926535");
4867 }
4868
4869 #[test]
escape_sequence_backslashes()4870 fn escape_sequence_backslashes() {
4871 test_eval_simple(r#""\\\\ \\""#, "\\\\ \\");
4872 }
4873
4874 #[test]
4875 fn escape_sequence_linebreak() {
4876 test_eval_simple(r#""\n""#, "\n");
4877 }
4878
4879 #[test]
4880 fn escape_sequence_tab() {
4881 test_eval_simple(r#""\t""#, "\t");
4882 }
4883
4884 #[test]
4885 fn escape_sequence_quote() {
4886 test_eval_simple(r#""\"""#, "\"");
4887 }
4888
4889 #[test]
escape_sequence_vertical_tab()4890 fn escape_sequence_vertical_tab() {
4891 test_eval_simple(r#""\v""#, "\u{0b}");
4892 }
4893
4894 #[test]
escape_sequence_escape()4895 fn escape_sequence_escape() {
4896 test_eval_simple(r#""\e""#, "\u{1b}");
4897 }
4898
4899 #[test]
escape_sequence_backspace()4900 fn escape_sequence_backspace() {
4901 test_eval_simple(r#""\b""#, "\u{8}");
4902 }
4903
4904 #[test]
escape_sequence_tilde()4905 fn escape_sequence_tilde() {
4906 test_eval_simple(r#""\x7e""#, "~");
4907 }
4908
4909 #[test]
escape_sequence_first_char_out_of_range()4910 fn escape_sequence_first_char_out_of_range() {
4911 expect_error(
4912 r#""\x9e""#,
4913 Some("expected an escape sequence between \\x00 and \\x7f"),
4914 );
4915 }
4916
4917 #[test]
escape_sequence_second_char_out_of_range()4918 fn escape_sequence_second_char_out_of_range() {
4919 expect_error(
4920 r#""\x7g""#,
4921 Some("expected an escape sequence between \\x00 and \\x7f"),
4922 );
4923 }
4924
4925 #[test]
multiple_escape_sequences()4926 fn multiple_escape_sequences() {
4927 test_eval_simple(r#""\\\n\e\v\b\t\x00\x7F""#, "\\\n\u{1b}\u{0b}\u{8}\t\0\x7f");
4928 }
4929
4930 #[test]
bell_in_string()4931 fn bell_in_string() {
4932 test_eval_simple("\"\\a\"", "\u{7}");
4933 }
4934
4935 #[test]
form_feed_in_string()4936 fn form_feed_in_string() {
4937 test_eval_simple("\"\\f\"", "\u{c}");
4938 }
4939
4940 #[test]
escaped_single_quote_in_string()4941 fn escaped_single_quote_in_string() {
4942 test_eval_simple("\" \\' \"", " ' ");
4943 }
4944
4945 #[test]
skip_whitespace_in_string()4946 fn skip_whitespace_in_string() {
4947 test_eval_simple("\" hi \\z \n\t \r\n \' \\z\\za\\z :\"", " hi ' a:");
4948 }
4949
4950 #[test]
single_quote_string()4951 fn single_quote_string() {
4952 test_eval_simple("'hi'", "hi");
4953 }
4954
4955 #[test]
single_quote_string_unterminated()4956 fn single_quote_string_unterminated() {
4957 expect_error(r#"'hi\"\'"#, Some("unterminated string literal"));
4958 }
4959
4960 #[test]
single_quote_string_with_escapes()4961 fn single_quote_string_with_escapes() {
4962 test_eval_simple(r#"'hi\"\''"#, "hi\"'");
4963 }
4964
4965 #[test]
control_char_escape_question_mark()4966 fn control_char_escape_question_mark() {
4967 test_eval_simple("'\\^?'", "\x7f");
4968 }
4969
4970 #[test]
control_char_escape_at_symbol()4971 fn control_char_escape_at_symbol() {
4972 test_eval_simple("'\\^@'", "\0");
4973 }
4974
4975 #[test]
control_char_escape_a()4976 fn control_char_escape_a() {
4977 test_eval_simple("'\\^A'", "\x01");
4978 }
4979
4980 #[test]
control_char_escape_b()4981 fn control_char_escape_b() {
4982 test_eval_simple("'\\^B'", "\x02");
4983 }
4984
4985 #[test]
control_char_escape_c()4986 fn control_char_escape_c() {
4987 test_eval_simple("'\\^C'", "\x03");
4988 }
4989
4990 #[test]
control_char_escape_d()4991 fn control_char_escape_d() {
4992 test_eval_simple("'\\^D'", "\x04");
4993 }
4994
4995 #[test]
control_char_escape_e()4996 fn control_char_escape_e() {
4997 test_eval_simple("'\\^E'", "\x05");
4998 }
4999
5000 #[test]
control_char_escape_f()5001 fn control_char_escape_f() {
5002 test_eval_simple("'\\^F'", "\x06");
5003 }
5004
5005 #[test]
control_char_escape_g()5006 fn control_char_escape_g() {
5007 test_eval_simple("'\\^G'", "\x07");
5008 }
5009
5010 #[test]
control_char_escape_h()5011 fn control_char_escape_h() {
5012 test_eval_simple("'\\^H'", "\x08");
5013 }
5014
5015 #[test]
control_char_escape_i()5016 fn control_char_escape_i() {
5017 test_eval_simple("'\\^I'", "\x09");
5018 }
5019
5020 #[test]
control_char_escape_j()5021 fn control_char_escape_j() {
5022 test_eval_simple("'\\^J'", "\x0a");
5023 }
5024
5025 #[test]
control_char_escape_k()5026 fn control_char_escape_k() {
5027 test_eval_simple("'\\^K'", "\x0b");
5028 }
5029
5030 #[test]
control_char_escape_l()5031 fn control_char_escape_l() {
5032 test_eval_simple("'\\^L'", "\x0c");
5033 }
5034
5035 #[test]
control_char_escape_p()5036 fn control_char_escape_p() {
5037 test_eval_simple("'\\^P'", "\x10");
5038 }
5039
5040 #[test]
control_char_escape_x()5041 fn control_char_escape_x() {
5042 test_eval_simple("'\\^X'", "\x18");
5043 }
5044
5045 #[test]
control_char_escape_y()5046 fn control_char_escape_y() {
5047 test_eval_simple("'\\^Y'", "\x19");
5048 }
5049
5050 #[test]
control_char_escape_z()5051 fn control_char_escape_z() {
5052 test_eval_simple("'\\^Z'", "\x1a");
5053 }
5054
5055 #[test]
control_char_escape_opening_square_bracket()5056 fn control_char_escape_opening_square_bracket() {
5057 test_eval_simple("'\\^['", "\x1b");
5058 }
5059
5060 #[test]
control_char_escape_backslash()5061 fn control_char_escape_backslash() {
5062 test_eval_simple("'\\^\\'", "\x1c");
5063 }
5064
5065 #[test]
control_char_escape_closing_square_bracket()5066 fn control_char_escape_closing_square_bracket() {
5067 test_eval_simple("'\\^]'", "\x1d");
5068 }
5069
5070 #[test]
control_char_escape_caret()5071 fn control_char_escape_caret() {
5072 test_eval_simple("'\\^^'", "\x1e");
5073 }
5074
5075 #[test]
control_char_escape_underscore()5076 fn control_char_escape_underscore() {
5077 test_eval_simple("'\\^_'", "\x1f");
5078 }
5079
5080 #[test]
control_char_escape_lowercase()5081 fn control_char_escape_lowercase() {
5082 expect_error("'\\^a'", None);
5083 }
5084
5085 #[test]
control_char_escape_gt()5086 fn control_char_escape_gt() {
5087 expect_error("'\\^>'", None);
5088 }
5089
5090 #[test]
control_char_escape_backtick()5091 fn control_char_escape_backtick() {
5092 expect_error("'\\^`'", None);
5093 }
5094
5095 #[test]
unicode_escape_7e()5096 fn unicode_escape_7e() {
5097 test_eval_simple("'\\u{7e}'", "~");
5098 }
5099
5100 #[test]
unicode_escape_696969()5101 fn unicode_escape_696969() {
5102 expect_error(
5103 "'\\u{696969}'",
5104 Some("invalid Unicode escape sequence, expected e.g. \\u{7e}"),
5105 );
5106 }
5107
5108 #[test]
unicode_escape_69()5109 fn unicode_escape_69() {
5110 test_eval("'\\u{69}'", "i");
5111 }
5112
5113 #[test]
unicode_escape_69x()5114 fn unicode_escape_69x() {
5115 expect_error(
5116 "'\\u{69x}'",
5117 Some("invalid Unicode escape sequence, expected e.g. \\u{7e}"),
5118 );
5119 }
5120
5121 #[test]
unicode_escape_empty()5122 fn unicode_escape_empty() {
5123 expect_error(
5124 "'\\u{}'",
5125 Some("invalid Unicode escape sequence, expected e.g. \\u{7e}"),
5126 );
5127 }
5128
5129 #[test]
unicode_escape_5437()5130 fn unicode_escape_5437() {
5131 test_eval_simple("'\\u{5437}'", "\u{5437}");
5132 }
5133
5134 #[test]
unicode_escape_5()5135 fn unicode_escape_5() {
5136 test_eval_simple("'\\u{5}'", "\u{5}");
5137 }
5138
5139 #[test]
unicode_escape_0()5140 fn unicode_escape_0() {
5141 test_eval_simple("'\\u{0}'", "\0");
5142 }
5143
5144 #[test]
unicode_escape_1()5145 fn unicode_escape_1() {
5146 test_eval_simple("'\\u{1}'", "\u{1}");
5147 }
5148
5149 #[test]
unicode_escape_10ffff()5150 fn unicode_escape_10ffff() {
5151 test_eval_simple("'\\u{10ffff}'", "\u{10ffff}");
5152 }
5153
5154 #[test]
unicode_escape_aaa_uppercase()5155 fn unicode_escape_aaa_uppercase() {
5156 test_eval_simple("'\\u{AAA}'", "\u{aaa}");
5157 }
5158
5159 #[test]
5160 #[ignore]
today()5161 fn today() {
5162 let mut context = Context::new();
5163 context.set_current_time_v1(1617517099000, 0);
5164 assert_eq!(
5165 evaluate("today", &mut context).unwrap().get_main_result(),
5166 "Sunday, 4 April 2021"
5167 );
5168 }
5169
5170 #[test]
5171 #[ignore]
today_with_tz()5172 fn today_with_tz() {
5173 let mut context = Context::new();
5174 context.set_current_time_v1(1619943083155, 43200);
5175 assert_eq!(
5176 evaluate("today", &mut context).unwrap().get_main_result(),
5177 "Sunday, 2 May 2021"
5178 );
5179 }
5180
5181 #[test]
acre_foot_to_m_3()5182 fn acre_foot_to_m_3() {
5183 test_eval("acre foot to m^3", "1233.48183754752 m^3");
5184 }
5185
5186 #[test]
cm_to_double_quote()5187 fn cm_to_double_quote() {
5188 test_eval("2.54cm to \"", "1\"");
5189 }
5190
5191 #[test]
cm_to_single_quote()5192 fn cm_to_single_quote() {
5193 test_eval("30.48cm to \'", "1'");
5194 }
5195
5196 #[test]
single_line_comment()5197 fn single_line_comment() {
5198 test_eval("30.48cm to \' # converting cm to feet", "1'");
5199 }
5200
5201 #[test]
single_line_comment_and_linebreak()5202 fn single_line_comment_and_linebreak() {
5203 test_eval("30.48cm to \' # converting cm to feet\n", "1'");
5204 }
5205
5206 #[test]
single_line_comment_and_linebreak_2()5207 fn single_line_comment_and_linebreak_2() {
5208 test_eval("30.48cm to # converting cm\n feet # to feet", "1 foot");
5209 }
5210
5211 #[test]
single_line_comment_and_linebreak_3()5212 fn single_line_comment_and_linebreak_3() {
5213 test_eval("30.48cm to # converting cm\n ' # to feet", "1'");
5214 }
5215
5216 #[test]
percent_plus_per_mille()5217 fn percent_plus_per_mille() {
5218 test_eval("4% + 3\u{2030}", "0.043");
5219 }
5220
5221 #[test]
custom_base_unit()5222 fn custom_base_unit() {
5223 test_eval_simple("5 'tests'", "5 tests");
5224 }
5225
5226 #[test]
custom_base_unit_in_calculation()5227 fn custom_base_unit_in_calculation() {
5228 test_eval_simple("5 'pigeons' per meter", "5 pigeons / meter");
5229 }
5230
5231 #[test]
5232 #[ignore]
custom_base_unit_in_calculation_2()5233 fn custom_base_unit_in_calculation_2() {
5234 test_eval("5 'pigeons' per meter / 'pigeons'", "5 meters");
5235 }
5236
5237 #[test]
five_k()5238 fn five_k() {
5239 test_eval("5k", "5000");
5240 }
5241
5242 #[test]
upper_case_meter()5243 fn upper_case_meter() {
5244 test_eval("4 Metres", "4 metres");
5245 }
5246
5247 #[test]
mixed_case_meter()5248 fn mixed_case_meter() {
5249 test_eval("4 mEtRes", "4 metres");
5250 }
5251
5252 #[test]
asin_minus_1_1()5253 fn asin_minus_1_1() {
5254 test_eval("asin -1.1", "approx. -1.5707963267 + 0.4435682543i");
5255 }
5256
5257 #[test]
custom_unit_test()5258 fn custom_unit_test() {
5259 test_eval_simple("15*3*50/1000 'cases'", "2.25 cases");
5260 }
5261
5262 #[test]
simplify_ms_per_year()5263 fn simplify_ms_per_year() {
5264 test_eval("ms/year", "approx. 0");
5265 }
5266
5267 #[test]
not_simplify_explicit_to()5268 fn not_simplify_explicit_to() {
5269 test_eval_simple(
5270 "1.550519768*10^-8 to ms/year",
5271 "489.296375410515266426112 ms / year",
5272 );
5273 }
5274
5275 #[test]
unicode_operators()5276 fn unicode_operators() {
5277 test_eval("5 − 2 ✕ 3 × 1 ÷ 1 ∕ 3", "3");
5278 }
5279
5280 #[test]
bool_true()5281 fn bool_true() {
5282 test_eval("true", "true");
5283 }
5284
5285 #[test]
bool_false()5286 fn bool_false() {
5287 test_eval("false", "false");
5288 }
5289
5290 #[test]
zero_to_bool()5291 fn zero_to_bool() {
5292 test_eval("0 to bool", "false");
5293 }
5294
5295 #[test]
zero_to_boolean()5296 fn zero_to_boolean() {
5297 test_eval("0 to boolean", "false");
5298 }
5299
5300 #[test]
one_to_bool()5301 fn one_to_bool() {
5302 test_eval("1 to bool", "true");
5303 }
5304
5305 #[test]
minus_one_to_bool()5306 fn minus_one_to_bool() {
5307 test_eval("-1 to bool", "true");
5308 }
5309
5310 #[test]
not_true()5311 fn not_true() {
5312 test_eval("not true", "false");
5313 }
5314
5315 #[test]
not_false()5316 fn not_false() {
5317 test_eval("not false", "true");
5318 }
5319
5320 #[test]
not_one()5321 fn not_one() {
5322 expect_error("not 1", None);
5323 }
5324
5325 #[test]
sqm()5326 fn sqm() {
5327 test_eval("5 sqm", "5 m^2");
5328 }
5329
5330 #[test]
sqft()5331 fn sqft() {
5332 test_eval("5 sqft", "5 ft^2");
5333 }
5334
5335 #[test]
modulo()5336 fn modulo() {
5337 for a in 0..30 {
5338 for b in 1..30 {
5339 let input = format!("{a} mod {b}");
5340 let output = (a % b).to_string();
5341 test_eval(&input, &output);
5342 }
5343 }
5344 }
5345
5346 #[test]
modulo_zero()5347 fn modulo_zero() {
5348 expect_error("5 mod 0", Some("modulo by zero"));
5349 }
5350
5351 #[test]
binary_modulo()5352 fn binary_modulo() {
5353 test_eval("0b1001010 mod 5", "0b100");
5354 }
5355
5356 #[test]
huge_modulo()5357 fn huge_modulo() {
5358 test_eval(
5359 "9283749283460298374027364928736492873469287354267354 mod 4",
5360 "2",
5361 );
5362 }
5363
5364 #[test]
month_of_date()5365 fn month_of_date() {
5366 test_eval_simple("month of ('2020-03-04' to date)", "March");
5367 }
5368
5369 #[test]
weekday_of_date()5370 fn weekday_of_date() {
5371 test_eval_simple("day_of_week of ('2020-05-08' to date)", "Friday");
5372 }
5373
5374 #[test]
day_of_week_type_name()5375 fn day_of_week_type_name() {
5376 expect_error(
5377 "5 to (day_of_week of ('2020-05-08' to date)",
5378 Some("cannot convert value to day of week"),
5379 );
5380 }
5381
5382 #[test]
phi()5383 fn phi() {
5384 test_eval("phi", "approx. 1.6180339886");
5385 }
5386
5387 #[test]
five_dollars()5388 fn five_dollars() {
5389 test_eval("$5", "$5");
5390 }
5391
5392 #[test]
dollar_prefix()5393 fn dollar_prefix() {
5394 test_eval_simple("$200/3 to 2dp", "approx. $66.66");
5395 }
5396
5397 #[test]
dollar_multiplication()5398 fn dollar_multiplication() {
5399 test_eval("$3 * 7", "$21");
5400 }
5401
5402 #[test]
5403 #[ignore]
dollar_multiplication_reverse()5404 fn dollar_multiplication_reverse() {
5405 test_eval("7 * $3", "$21");
5406 }
5407
5408 #[test]
gbp_symbol()5409 fn gbp_symbol() {
5410 test_eval("£5 + £3", "£8");
5411 }
5412
5413 #[test]
jpy_symbol()5414 fn jpy_symbol() {
5415 test_eval("¥5 + ¥3", "¥8");
5416 }
5417
5418 #[test]
two_statements()5419 fn two_statements() {
5420 test_eval("2; 4", "4");
5421 }
5422
5423 #[test]
five_statements()5424 fn five_statements() {
5425 test_eval("2; 4; 8kg; c:2c; a = 2", "2");
5426 }
5427
5428 #[test]
variable_assignment()5429 fn variable_assignment() {
5430 test_eval("a = b = 2; b", "2");
5431 }
5432
5433 #[test]
overwrite_variable()5434 fn overwrite_variable() {
5435 test_eval("a = 3; a = a + 4a; a", "15");
5436 }
5437
5438 #[test]
multiple_variables()5439 fn multiple_variables() {
5440 test_eval("a = 3; b = 2a; c = a * b; c + a", "21");
5441 }
5442
5443 #[test]
mixed_frac()5444 fn mixed_frac() {
5445 test_eval_simple("4/3 to mixed_frac", "1 1/3");
5446 }
5447
5448 #[test]
farad_conversion()5449 fn farad_conversion() {
5450 test_eval("1 farad to A^2 kg^-1 m^-2 s^4", "1 A^2 s^4 kg^-1 m^-2");
5451 }
5452
5453 #[test]
coulomb_farad_mode()5454 fn coulomb_farad_mode() {
5455 let mut ctx = Context::new();
5456 ctx.use_coulomb_and_farad();
5457 assert_eq!(
5458 evaluate("5C to coulomb", &mut ctx)
5459 .unwrap()
5460 .get_main_result(),
5461 "5 coulomb"
5462 );
5463 assert_eq!(
5464 evaluate("5uF to farad", &mut ctx)
5465 .unwrap()
5466 .get_main_result(),
5467 "0.000005 farad"
5468 );
5469 }
5470
5471 #[test]
test_rolling_dice()5472 fn test_rolling_dice() {
5473 let mut ctx = Context::new();
5474 ctx.set_random_u32_fn(|| 5);
5475 evaluate("roll d20", &mut ctx).unwrap();
5476 }
5477
5478 #[test]
test_d6()5479 fn test_d6() {
5480 test_eval_simple(
5481 "d6",
5482 "{ 1: 16.67%, 2: 16.67%, 3: 16.67%, 4: 16.67%, 5: 16.67%, 6: 16.67% }",
5483 );
5484 }
5485
5486 #[test]
test_2d6()5487 fn test_2d6() {
5488 test_eval_simple(
5489 "2d6",
5490 "{ 2: 2.78%, 3: 5.56%, 4: 8.33%, 5: 11.11%, \
5491 6: 13.89%, 7: 16.67%, 8: 13.89%, 9: 11.11%, 10: 8.33%, 11: 5.56%, 12: 2.78% }",
5492 )
5493 }
5494
5495 #[test]
test_invalid_dice_syntax_1()5496 fn test_invalid_dice_syntax_1() {
5497 expect_error("0d6", Some("invalid dice syntax, try e.g. `4d6`"));
5498 }
5499
5500 #[test]
test_invalid_dice_syntax_2()5501 fn test_invalid_dice_syntax_2() {
5502 expect_error("1d0", Some("invalid dice syntax, try e.g. `4d6`"));
5503 }
5504
5505 #[test]
test_invalid_dice_syntax_3()5506 fn test_invalid_dice_syntax_3() {
5507 expect_error("0d0", Some("invalid dice syntax, try e.g. `4d6`"));
5508 }
5509
5510 #[test]
test_invalid_dice_syntax_4()5511 fn test_invalid_dice_syntax_4() {
5512 expect_error("d30000000000000000", None);
5513 }
5514
5515 #[test]
test_invalid_dice_syntax_5()5516 fn test_invalid_dice_syntax_5() {
5517 // this produces different error messages on 32-bit vs 64-bit platforms
5518 expect_error("30000000000000000d2", None);
5519 }
5520
5521 #[test]
unit_literal()5522 fn unit_literal() {
5523 test_eval("()", "()");
5524 }
5525
5526 #[test]
empty_statements()5527 fn empty_statements() {
5528 test_eval("1234;", "1234");
5529 test_eval(";432", "432");
5530 test_eval(";", "()");
5531 test_eval(";;3", "3");
5532 test_eval("34;;;", "34");
5533 test_eval(";2;;3;a=4;;4a", "16");
5534 test_eval(";2;;3;a=4;;4a;;;()", "()");
5535 }
5536
5537 #[test]
add_days_to_date()5538 fn add_days_to_date() {
5539 test_eval_simple(
5540 "('2020-05-04' to date) + 500 days",
5541 "Thursday, 16 September 2021",
5542 );
5543 }
5544
5545 #[test]
fancy_syntax()5546 fn fancy_syntax() {
5547 test_eval("(\u{3bb}x.x) 5", "5");
5548 }
5549
5550 #[test]
kmh()5551 fn kmh() {
5552 test_eval("25146 kmh to mph", "15625 mph");
5553 }
5554
5555 #[test]
km_slash_h()5556 fn km_slash_h() {
5557 test_eval("25146 km/h to mph", "15625 mph");
5558 }
5559
5560 #[test]
planck()5561 fn planck() {
5562 test_eval("planck", "0.000000000000000000000000000000000662607015 J s");
5563 }
5564
5565 #[test]
implicit_unit_fudging()5566 fn implicit_unit_fudging() {
5567 test_eval("5'1 to m to 2dp", "approx. 1.54 m");
5568 }
5569
5570 #[test]
implicit_unit_fudging_2()5571 fn implicit_unit_fudging_2() {
5572 test_eval("0'1 to m to 2dp", "approx. 0.02 m");
5573 }
5574
5575 #[test]
implicit_unit_fudging_3()5576 fn implicit_unit_fudging_3() {
5577 expect_error(
5578 "0'1 + 5",
5579 Some("cannot convert from unitless to ': units 'unitless' and 'meter' are incompatible"),
5580 );
5581 }
5582
5583 #[test]
implicit_unit_fudging_4()5584 fn implicit_unit_fudging_4() {
5585 test_eval("5'1 + 5m", "approx. 21.4875328083'");
5586 }
5587
5588 #[test]
implicit_unit_fudging_5()5589 fn implicit_unit_fudging_5() {
5590 expect_error(
5591 "5'1 + 5kg",
5592 Some("cannot convert from kg to ': units 'kilogram' and 'meter' are incompatible"),
5593 );
5594 }
5595
5596 #[test]
millicoulomb()5597 fn millicoulomb() {
5598 test_eval("5 coulomb to mC", "5000 mC");
5599 }
5600
5601 #[test]
millifarad()5602 fn millifarad() {
5603 test_eval("5 farad to mF", "5000 mF");
5604 }
5605
5606 #[test]
point()5607 fn point() {
5608 test_eval("0.5 points to mm", "approx. 0.1763888888 mm");
5609 }
5610
5611 #[test]
rad_per_sec()5612 fn rad_per_sec() {
5613 test_eval("10 RPM to rad/s", "approx. 1.0471975511 rad / s")
5614 }
5615
5616 #[test]
fudged_rhs_feet_conv()5617 fn fudged_rhs_feet_conv() {
5618 test_eval("6 foot 4 in cm", "193.04 cm");
5619 }
5620
5621 #[test]
trivial_fn()5622 fn trivial_fn() {
5623 // used for testing fn serialization
5624 test_eval("x:()", "\\x.()");
5625 }
5626
5627 #[test]
unknown_argument_error_msg()5628 fn unknown_argument_error_msg() {
5629 expect_error("sqrt(aiusbdla)", Some("unknown identifier 'aiusbdla'"));
5630 }
5631
5632 #[test]
log10_cancelled_units()5633 fn log10_cancelled_units() {
5634 test_eval("log10 (1m / (1m", "approx. 0");
5635 }
5636
5637 #[test]
shebang()5638 fn shebang() {
5639 test_eval("#!/usr/bin/env fend\n1 + 1", "2");
5640 }
5641
5642 #[test]
bitwise_and_1()5643 fn bitwise_and_1() {
5644 test_eval("0 & 0", "0");
5645 test_eval("0 & 1", "0");
5646 test_eval("1 & 0", "0");
5647 test_eval("1 & 1", "1");
5648 }
5649
5650 #[test]
bitwise_and_2()5651 fn bitwise_and_2() {
5652 test_eval("0 & 91802367489176234987162938461829374691238641", "0");
5653 }
5654
5655 #[test]
bitwise_and_3()5656 fn bitwise_and_3() {
5657 test_eval(
5658 "912834710927364108273648927346788234682764 &
5659 98123740918263740896274873648273642342534252",
5660 "207742386994266479278471200397877100888076",
5661 );
5662 }
5663
5664 #[test]
bitwise_or_1()5665 fn bitwise_or_1() {
5666 test_eval("0 | 0", "0");
5667 test_eval("0 | 1", "1");
5668 test_eval("1 | 0", "1");
5669 test_eval("1 | 1", "1");
5670 }
5671
5672 #[test]
bitwise_or_2()5673 fn bitwise_or_2() {
5674 test_eval("3 | 4", "7");
5675 }
5676
5677 #[test]
bitwise_or_3()5678 fn bitwise_or_3() {
5679 test_eval("255 | 34", "255");
5680 }
5681
5682 #[test]
bitwise_or_4()5683 fn bitwise_or_4() {
5684 test_eval("0b0011 | 0b0101", "0b111");
5685 }
5686
5687 #[test]
bitwise_xor_1()5688 fn bitwise_xor_1() {
5689 test_eval("0 xor 0", "0");
5690 test_eval("0 xor 1", "1");
5691 test_eval("1 xor 0", "1");
5692 test_eval("1 xor 1", "0");
5693 }
5694
5695 #[test]
bitwise_xor_2()5696 fn bitwise_xor_2() {
5697 test_eval(
5698 "019278364182374698123476928376459726354982 xor
5699 387294658347659283475689347659823745692837465",
5700 "387286275339643142048939049610868709852535935",
5701 );
5702 }
5703
5704 #[test]
lshift()5705 fn lshift() {
5706 test_eval("0 << 10", "0");
5707 test_eval("54 << 1", "108");
5708 test_eval("54 << 2", "216");
5709 test_eval("54 << 3", "432");
5710 }
5711
5712 #[test]
rshift()5713 fn rshift() {
5714 test_eval("54 >> 12", "0");
5715 test_eval("54 >> 1", "27");
5716 test_eval("54 >> 2", "13");
5717 test_eval("54 >> 3", "6");
5718 }
5719
5720 #[test]
shift_and_and()5721 fn shift_and_and() {
5722 test_eval("54 << 1 & 54 >> 1", "8");
5723 }
5724
5725 #[test]
combination_test()5726 fn combination_test() {
5727 test_eval("5 nCr 2", "10");
5728 test_eval("5 choose 2", "10");
5729 test_eval("10 nCr 3", "120");
5730 test_eval("10 choose 3", "120");
5731 }
5732
5733 #[test]
permutation_test()5734 fn permutation_test() {
5735 test_eval("5 nPr 2", "20");
5736 test_eval("5 permute 2", "20");
5737 test_eval("10 nPr 3", "720");
5738 test_eval("10 permute 3", "720");
5739 }
5740
5741 // ERROR
5742 #[test]
date_literals()5743 fn date_literals() {
5744 test_eval_simple("@1970-01-01", "Thursday, 1 January 1970");
5745 }
5746
5747 // ERROR
5748 #[test]
date_literal_subtraction()5749 fn date_literal_subtraction() {
5750 test_eval_simple("@2022-11-29 - 2 days", "Sunday, 27 November 2022");
5751 test_eval_simple("@2022-11-29 - 2 weeks", "Tuesday, 15 November 2022");
5752 test_eval_simple("@2022-11-29 - 2 months", "Thursday, 29 September 2022");
5753 test_eval_simple("@2022-11-29 - 2 years", "Sunday, 29 November 2020");
5754
5755 test_eval_simple("@2022-03-01 - 1 month", "Tuesday, 1 February 2022");
5756 test_eval_simple("@2020-02-28 - 1 year", "Thursday, 28 February 2019");
5757 expect_error(
5758 "@2020-02-29 - 1 year",
5759 "February 29, 2019 does not exist, did you mean Thursday, 28 February 2019 or Friday, 1 March 2019?".into(),
5760 );
5761 expect_error(
5762 "@2020-02-29 - 12 month",
5763 "February 29, 2019 does not exist, did you mean Thursday, 28 February 2019 or Friday, 1 March 2019?".into(),
5764 );
5765 test_eval_simple("@2020-08-01 - 1 year", "Thursday, 1 August 2019");
5766 }
5767
5768 #[test]
atan_meter()5769 fn atan_meter() {
5770 test_eval("atan((30 centi meter) / (2 meter))", "approx. 0.1488899476");
5771 test_eval("atan((30 centimeter) / (2 meter))", "approx. 0.1488899476");
5772 }
5773
5774 #[test]
centimeter_no_currencies()5775 fn centimeter_no_currencies() {
5776 let mut context = Context::new();
5777 assert_eq!(
5778 evaluate("1 centimeter", &mut context)
5779 .unwrap()
5780 .get_main_result(),
5781 "1 centimeter"
5782 );
5783 }
5784
5785 #[test]
underscore_variables()5786 fn underscore_variables() {
5787 test_eval("test_a = 5; test_a", "5");
5788 }
5789
5790 #[test]
light_year_1()5791 fn light_year_1() {
5792 test_eval("light_year / light to days", "365.25 days");
5793 }
5794
5795 #[test]
light_year_2()5796 fn light_year_2() {
5797 test_eval("light year / light to days", "365.25 days");
5798 }
5799
5800 #[test]
light_year_3()5801 fn light_year_3() {
5802 test_eval("lightyear / light to days", "365.25 days");
5803 }
5804
5805 #[test]
light_year_4()5806 fn light_year_4() {
5807 test_eval("light day / light to days", "1 day");
5808 }
5809
5810 #[test]
mixed_case_abbreviations_1()5811 fn mixed_case_abbreviations_1() {
5812 test_eval("5 KB", "5 kB");
5813 }
5814
5815 #[test]
mixed_case_abbreviations_2()5816 fn mixed_case_abbreviations_2() {
5817 test_eval("5 Kb", "5 kb");
5818 }
5819
5820 #[test]
mixed_case_abbreviations_3()5821 fn mixed_case_abbreviations_3() {
5822 test_eval("5 gb", "5 Gb");
5823 }
5824
5825 #[test]
mixed_case_abbreviations_4()5826 fn mixed_case_abbreviations_4() {
5827 test_eval("5 kiwh", "5 KiWh");
5828 }
5829
5830 #[test]
thou()5831 fn thou() {
5832 test_eval("2 thou to mm", "0.0508 mm");
5833 }
5834
5835 #[test]
hubble_constant()5836 fn hubble_constant() {
5837 test_eval_simple(
5838 "70 km s^-1 Mpc^-1 to 25dp",
5839 "approx. 0.0000000000000000022685455 s^-1",
5840 );
5841 }
5842
5843 #[test]
oc()5844 fn oc() {
5845 test_eval("5 oC", "5 °C");
5846 }
5847
5848 #[test]
to_million()5849 fn to_million() {
5850 test_eval_simple("5 to million", "0.000005 million");
5851 }
5852
5853 #[test]
ohms_law()5854 fn ohms_law() {
5855 test_eval("(5 volts) / (2 ohms)", "2.5 amperes");
5856 }
5857
5858 #[test]
simplification_sec_hz()5859 fn simplification_sec_hz() {
5860 test_eval("c/(145MHz)", "approx. 2.0675341931 meters");
5861 }
5862
5863 #[test]
simplification_ohms()5864 fn simplification_ohms() {
5865 test_eval("4556 ohm * ampere", "4556 volts");
5866 }
5867
5868 #[test]
simplification_ohms_2()5869 fn simplification_ohms_2() {
5870 test_eval("4556 volt / ampere", "4556 ohms");
5871 }
5872
5873 #[test]
alias_sqrt()5874 fn alias_sqrt() {
5875 test_eval(
5876 "partial_result = 2*(0.84 femto meter) / (1.35e-22 m/s^2); sqrt(partial_result)",
5877 "approx. 3527.6684147527 s",
5878 );
5879 }
5880
5881 #[test]
test_superscript()5882 fn test_superscript() {
5883 test_eval("200²", "40000");
5884 test_eval("13¹³ days", "302875106592253 days");
5885 }
5886
5887 #[test]
test_equality()5888 fn test_equality() {
5889 test_eval("1 + 2 == 3", "true");
5890 test_eval("1 + 2 != 4", "true");
5891 test_eval("1 + 2 ≠ 4", "true");
5892 test_eval("1 + 2 <> 4", "true");
5893 test_eval("true == false", "false");
5894 test_eval("true != false", "true");
5895 test_eval("true ≠ false", "true");
5896 test_eval("2m == 200cm", "true");
5897 test_eval("2kg == 200cm", "false");
5898 test_eval("2kg == true", "false");
5899 test_eval("2.010m == 200cm", "false");
5900 test_eval("2.000m == approx. 200cm", "true");
5901 }
5902
5903 #[test]
test_roman()5904 fn test_roman() {
5905 expect_error(
5906 "0 to roman",
5907 Some("zero cannot be represented as a roman numeral"),
5908 );
5909 test_eval_simple("1 to roman", "I");
5910 test_eval_simple("2 to roman", "II");
5911 test_eval_simple("3 to roman", "III");
5912 test_eval_simple("4 to roman", "IV");
5913 test_eval_simple("5 to roman", "V");
5914 test_eval_simple("6 to roman", "VI");
5915 test_eval_simple("7 to roman", "VII");
5916 test_eval_simple("8 to roman", "VIII");
5917 test_eval_simple("9 to roman", "IX");
5918 test_eval_simple("10 to roman", "X");
5919 test_eval_simple("11 to roman", "XI");
5920 test_eval_simple("12 to roman", "XII");
5921 test_eval_simple("13 to roman", "XIII");
5922 test_eval_simple("14 to roman", "XIV");
5923 test_eval_simple("15 to roman", "XV");
5924 test_eval_simple("16 to roman", "XVI");
5925 test_eval_simple("17 to roman", "XVII");
5926 test_eval_simple("18 to roman", "XVIII");
5927 test_eval_simple("19 to roman", "XIX");
5928 test_eval_simple("20 to roman", "XX");
5929 test_eval_simple("21 to roman", "XXI");
5930 test_eval_simple("22 to roman", "XXII");
5931 test_eval_simple("45 to roman", "XLV");
5932 test_eval_simple("134 to roman", "CXXXIV");
5933 test_eval_simple("1965 to roman", "MCMLXV");
5934 test_eval_simple("2020 to roman", "MMXX");
5935 test_eval_simple("3456 to roman", "MMMCDLVI");
5936 test_eval_simple("1452 to roman", "MCDLII");
5937 test_eval_simple("20002 to roman", "MMMMMMMMMMMMMMMMMMMMII");
5938 expect_error(
5939 "100001 to roman",
5940 Some("100001 must lie in the interval [1, 100000]"),
5941 );
5942 }
5943
5944 #[test]
rack_unit()5945 fn rack_unit() {
5946 test_eval("4U to cm", "17.78 cm");
5947 }
5948
5949 #[test]
test_mean()5950 fn test_mean() {
5951 test_eval("mean d1", "1");
5952 test_eval("mean d2", "1.5");
5953 test_eval("mean d500", "250.5");
5954
5955 test_eval("mean (d1 + d1)", "2");
5956 test_eval("mean (d2 + d500)", "252");
5957
5958 test_eval("mean (d6 / d2)", "2.625");
5959 test_eval("mean (d10 / d2)", "4.125");
5960
5961 test_eval("average d500", "250.5");
5962 }
5963