diff --git a/kalk/src/integration_testing.rs b/kalk/src/integration_testing.rs index 9dc602a..10847d8 100644 --- a/kalk/src/integration_testing.rs +++ b/kalk/src/integration_testing.rs @@ -1,6 +1,7 @@ #[cfg(test)] mod tests { use std::{fs::File, io::Read, path::PathBuf}; + use test_case::test_case; use crate::kalk_value::KalkValue; @@ -40,33 +41,17 @@ mod tests { } } - #[test] - fn test_basics() { - assert!(is_true(eval_file("basics"))); - } - - #[test] - fn test_radix() { - assert!(is_true(eval_file("radix"))); - } - - #[test] - fn test_variables() { - assert!(is_true(eval_file("variables"))); - } - - #[test] - fn test_functions() { - assert!(is_true(eval_file("functions"))); - } - - #[test] - fn test_derivation() { - assert!(is_true(eval_file("derivation"))); - } - - #[test] - fn test_integration() { - assert!(is_true(eval_file("integration"))); + #[test_case("basics")] + #[test_case("derivation")] + #[test_case("functions")] + #[test_case("groups")] + #[test_case("integration")] + #[test_case("matrices")] + #[test_case("radix")] + #[test_case("sum")] + #[test_case("variables")] + #[test_case("vectors")] + fn test_file(name: &str) { + assert!(is_true(eval_file(name))); } } diff --git a/kalk/src/parser.rs b/kalk/src/parser.rs index 4d0ca88..3641ceb 100644 --- a/kalk/src/parser.rs +++ b/kalk/src/parser.rs @@ -315,6 +315,7 @@ fn parse_or(context: &mut Context) -> Result { if match_token(context, TokenKind::Or) { let op = advance(context).kind; + skip_newlines(context); let right = Box::new(parse_or(context)?); return Ok(Expr::Binary(Box::new(left), op, right)); } @@ -327,6 +328,7 @@ fn parse_and(context: &mut Context) -> Result { if match_token(context, TokenKind::And) { let op = advance(context).kind; + skip_newlines(context); let right = Box::new(parse_and(context)?); return Ok(Expr::Binary(Box::new(left), op, right)); } diff --git a/tests/basics.kalker b/tests/basics.kalker index d8bc951..b152313 100644 --- a/tests/basics.kalker +++ b/tests/basics.kalker @@ -1,4 +1,5 @@ x = 2 y = 3 f(x) = 2x(x - 3)(y + 2) -f(f(x) + y) \ No newline at end of file + +f(f(x) + y) = 3400 \ No newline at end of file diff --git a/tests/derivation.kalker b/tests/derivation.kalker new file mode 100644 index 0000000..194d740 --- /dev/null +++ b/tests/derivation.kalker @@ -0,0 +1,2 @@ +f(x) = 2x^2 + x +f'(2) = 9 \ No newline at end of file diff --git a/tests/functions.kalker b/tests/functions.kalker new file mode 100644 index 0000000..48676a1 --- /dev/null +++ b/tests/functions.kalker @@ -0,0 +1,5 @@ +x = 3 +f(x) = 2*x +g(x, y) = 2*x*y + +f(x) = 6 and fx = 6 and x = 3 and g(x, x + 1) = 24 \ No newline at end of file diff --git a/tests/groups.kalker b/tests/groups.kalker new file mode 100644 index 0000000..f4e68c7 --- /dev/null +++ b/tests/groups.kalker @@ -0,0 +1 @@ +|-3| + ⌊2.6⌋ + ⌈4.2⌉ = 10 \ No newline at end of file diff --git a/tests/integration.kalker b/tests/integration.kalker new file mode 100644 index 0000000..fd422ae --- /dev/null +++ b/tests/integration.kalker @@ -0,0 +1,5 @@ +a = integrate(0, pi, sinxdx) +b = integrate(0, pi, sinx dx) +c = integrate(0, pi, sinx, dx) + +a = 2 and b = 2 and c = 2 \ No newline at end of file diff --git a/tests/matrices.kalker b/tests/matrices.kalker new file mode 100644 index 0000000..bfcbee1 --- /dev/null +++ b/tests/matrices.kalker @@ -0,0 +1,38 @@ +m_1 = [1, 2, 3 + 4, 5, 6 + 7, 8, 9] + +m_2 = [2, 3, 4 + 5, 6, 7 + 8, 9, 10] + +v = (1, 2, 3) + +m_1 + m_2 = [3, 5, 7 + 9, 11, 13 + 15, 17, 19] and +m_2 - m_1 = [1, 1, 1 + 1, 1, 1 + 1, 1, 1] and +m_1 * m_2 = [36, 42, 48 + 81, 96, 111 + 126, 150, 174] and +[4, 9; 12, 3] / [2, 3; 4, 3] = [2, 3; 3, 1] and + +m_1 + v = [2, 3, 4; 6, 7, 8; 10, 11, 12] and +m_1 - v = [0, 1, 2; 2, 3, 4; 4, 5, 6] and +m_1 * v = (14, 32, 50) and +m_1 / v = [1, 2, 3; 2, 5/2, 3; 7/3, 8/3, 3] and + +m_1 + 2 = [3, 4, 5 + 6, 7, 8 + 9, 10, 11] and +m_1 - 2 = [-1, 0, 1 + 2, 3, 4 + 5, 6, 7] and +m_1 * 2 = [2, 4, 6 + 8, 10, 12 + 14, 16, 18] and +m_1 / 2 = [1/2, 1, 3/2 + 2, 5/2, 3 + 7/2, 4, 9/2] \ No newline at end of file diff --git a/tests/radix.kalker b/tests/radix.kalker index 35edf3d..d98d5ef 100644 --- a/tests/radix.kalker +++ b/tests/radix.kalker @@ -1 +1 @@ -0b1101.101 + 1101.101_2 + 0o13.5 + 13.5_8 + 11.5 + 0xb.5i \ No newline at end of file +0b1101.101 + 1101.101_2 + 0o13.5 + 13.5_8 + 11.5 + 0xb.5i = 62 + 11.3125i \ No newline at end of file diff --git a/tests/sum.kalker b/tests/sum.kalker new file mode 100644 index 0000000..b0d1c8b --- /dev/null +++ b/tests/sum.kalker @@ -0,0 +1,2 @@ +n = 10 +sum(1, 5, 2n) = 30 and n = 10 \ No newline at end of file diff --git a/tests/variables.kalker b/tests/variables.kalker new file mode 100644 index 0000000..8415837 --- /dev/null +++ b/tests/variables.kalker @@ -0,0 +1,5 @@ +x = 2 +y = 3 +z = 5 + +x = 2 and y = 3 and z = 5 and xy = 6 and xyz = 30 \ No newline at end of file diff --git a/tests/vectors.kalker b/tests/vectors.kalker new file mode 100644 index 0000000..daa49d7 --- /dev/null +++ b/tests/vectors.kalker @@ -0,0 +1,11 @@ +(2, 3, 5) + (7, 11, 13) = (9, 14, 18) and +(2, 3, 5) - (7, 11, 13) = (-5, -8, -8) and +(2, 3, 5) * (7, 11, 13) = 112 and +(8, 9, 25) / (2, 3, 5) = (4, 3, 5) and + +(2, 3, 5) + 2 = (4, 5, 7) and +(2, 3, 5) - 2 = (0, 1, 3) and +(2, 3, 5) * 2 = (4, 6, 10) and +(4, 8, 16) / 2 = (2, 4, 8) and +abs([-3, 2, -5]) = (3, 2, 5) and +|[-3, 2, -5]| = (3, 2, 5) \ No newline at end of file