mod common; #[test] fn add() { common::test_program("print 3 + 4\n", "7\n"); } #[test] fn sub() { common::test_program("print 3 - 4\n", "-1\n"); } #[test] fn mul2() { common::test_program("print 3 * true\n", "3\n"); } #[test] fn mul3() { common::test_program("print 3 * false\n", "0\n"); } #[test] fn mul4() { common::test_program("print 3 * 1.5\n", "4.5\n"); } #[test] fn mul() { common::test_program("print 3 * 4\n", "12\n"); } #[test] fn div() { common::test_program("print 3 / 4\n", "0.75\n"); common::test_program("print 3 / 0\n", "inf\n"); } #[test] fn pow() { common::test_program("print 3^4\n", "81\n"); common::test_program("print 3^-4\n", "0.012345679012345678\n"); common::test_program("print 3i^-4i\n", "0.012345679012345678\n"); common::test_program("print 2^2^2^2\n", "65536\n"); } #[test] fn modulus() { common::test_program("print 3 % 3\n", "0\n"); common::test_program("print 4 % 4\n", "0\n"); common::test_program("print 5 % 5\n", "0\n"); common::test_program("print 5 % 2\n", "1\n"); common::test_program("print 2 % 5\n", "2\n"); common::test_program("print 0 % 0\n", "NaN\n"); common::test_program("print 1 % 0\n", "NaN\n"); common::test_program("print 5234 % 1\n", "0\n"); common::test_program("print 3.5 % 2\n", "1.5\n"); common::test_program("print 4.5 % 2\n", "0.5\n"); common::test_program("print 1 % 1.5\n", "1\n"); common::test_program("print 1.5 % 1.5\n", "0\n"); common::test_program("print 1.5 % 1.6\n", "1.5\n"); common::test_program("print 1.5 % 1.4\n", "0.10000000000000009\n"); } #[test] fn add_equal() { common::test_program( " a = 2 a += 3 print a ", "5\n", ); } #[test] fn sub_equal() { common::test_program( " a = 2 a -= 3 print a ", "-1\n", ); } #[test] fn mul_equal() { common::test_program( " a = 2 a *= 3 print a ", "6\n", ); } #[test] fn div_equal() { common::test_program( " a = 6 a /= 3 print a ", "2\n", ); } #[test] fn pow_equal() { common::test_program( " a = 2 a ^= 3 print a ", "8\n", ); } #[test] fn mod_equal() { common::test_program( " a = 8 a %= 3 print a ", "2\n", ); }