mirror of
https://github.com/PaddiM8/kalker.git
synced 2024-12-12 09:30:40 +01:00
Added integration tests for derivation, functions, groups, integration, matrices, sum, variables, and vectors
This commit is contained in:
parent
f7c8ef8ad8
commit
c31001777e
@ -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)));
|
||||
}
|
||||
}
|
||||
|
@ -315,6 +315,7 @@ fn parse_or(context: &mut Context) -> Result<Expr, CalcError> {
|
||||
|
||||
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<Expr, CalcError> {
|
||||
|
||||
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));
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
x = 2
|
||||
y = 3
|
||||
f(x) = 2x(x - 3)(y + 2)
|
||||
f(f(x) + y)
|
||||
|
||||
f(f(x) + y) = 3400
|
2
tests/derivation.kalker
Normal file
2
tests/derivation.kalker
Normal file
@ -0,0 +1,2 @@
|
||||
f(x) = 2x^2 + x
|
||||
f'(2) = 9
|
5
tests/functions.kalker
Normal file
5
tests/functions.kalker
Normal file
@ -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
|
1
tests/groups.kalker
Normal file
1
tests/groups.kalker
Normal file
@ -0,0 +1 @@
|
||||
|-3| + ⌊2.6⌋ + ⌈4.2⌉ = 10
|
5
tests/integration.kalker
Normal file
5
tests/integration.kalker
Normal file
@ -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
|
38
tests/matrices.kalker
Normal file
38
tests/matrices.kalker
Normal file
@ -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]
|
@ -1 +1 @@
|
||||
0b1101.101 + 1101.101_2 + 0o13.5 + 13.5_8 + 11.5 + 0xb.5i
|
||||
0b1101.101 + 1101.101_2 + 0o13.5 + 13.5_8 + 11.5 + 0xb.5i = 62 + 11.3125i
|
2
tests/sum.kalker
Normal file
2
tests/sum.kalker
Normal file
@ -0,0 +1,2 @@
|
||||
n = 10
|
||||
sum(1, 5, 2n) = 30 and n = 10
|
5
tests/variables.kalker
Normal file
5
tests/variables.kalker
Normal file
@ -0,0 +1,5 @@
|
||||
x = 2
|
||||
y = 3
|
||||
z = 5
|
||||
|
||||
x = 2 and y = 3 and z = 5 and xy = 6 and xyz = 30
|
11
tests/vectors.kalker
Normal file
11
tests/vectors.kalker
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user