Skip to content

Commit

Permalink
Added dataype (arithmetic) tests (#319)
Browse files Browse the repository at this point in the history
* Arithmetic Tests

* Added datatype correctness tests

* Remove specific types from the MainType struct

* Remove time.cpp

Co-authored-by: Ghaith Hachem <ghaith.hachem@bachmann.info>
  • Loading branch information
rarris and ghaith committed Oct 18, 2021
1 parent e38d922 commit eed5b41
Show file tree
Hide file tree
Showing 10 changed files with 1,494 additions and 97 deletions.
58 changes: 58 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ generational-arena = "0.2.8"
regex = "1"

[dev-dependencies]
num = "0.4"
insta = "1.8.0"
pretty_assertions = "0.6.1"


[lib]
name = "rusty"
path = "src/lib.rs"
Expand Down
101 changes: 98 additions & 3 deletions tests/correctness/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,52 @@ fn matrix_array_assignments() {
}
}

#[test]
fn two_dim_array_math() {
let function = "
FUNCTION main : INT
VAR
x,y,z : INT;
int_array : ARRAY[0..4, 0..4] OF INT;
END_VAR
x := int_array[0,1];
y := int_array[0,2];
z := int_array[4,4];
x := 10;
y := 20;
z := 5;
main := x+y-z*z/z;
END_FUNCTION
";

let mut maintype = new();
let res: i16 = compile_and_run(function.to_string(), &mut maintype);
assert_eq!(res, 25);
}

#[test]
fn three_dim_array_math() {
let function = "
FUNCTION main : INT
VAR
x,y,z : INT;
int_array : ARRAY[0..4, 0..4, 0..4] OF INT;
END_VAR
x := int_array[0,1,0];
y := int_array[0,2,3];
z := int_array[4,4,0];
x := 10;
y := 20;
z := 5;
main := x+y-z*z/z+x-y;
END_FUNCTION
";

let mut maintype = new();
let res: i16 = compile_and_run(function.to_string(), &mut maintype);
assert_eq!(res, 15);
}

#[test]
fn matrix_array_assignments2() {
let function = r"
Expand All @@ -124,9 +170,9 @@ fn matrix_array_assignments2() {
END_VAR
FOR x := 0 TO 4 DO
FOR y := 0 TO 4 DO
matrix[x][y] := x*y;
END_FOR
FOR y := 0 TO 4 DO
matrix[x][y] := x*y;
END_FOR
END_FOR
END_PROGRAM
";
Expand Down Expand Up @@ -210,3 +256,52 @@ fn cube_array_assignments2() {
}
}
}

#[test]
fn two_dim_array_if() {
let function = "
FUNCTION main : INT
VAR
x,y,z : INT;
int_array : ARRAY[0..4, 0..4] OF INT;
END_VAR
int_array[0,1] := 10;
y := 20;
IF y > 21 THEN
int_array[4,4] := 40;
ELSIF y < 21 THEN
int_array[4,4] := 20;
END_IF;
main := int_array[4,4];
END_FUNCTION
";

let mut maintype = new();
let res: i16 = compile_and_run(function.to_string(), &mut maintype);
assert_eq!(res, 20);
}

#[test]
fn two_dim_array_while() {
let function = "
FUNCTION main : INT
VAR
x,y,z,counter : INT;
int_array : ARRAY[0..4, 0..4] OF INT;
END_VAR
int_array[0,1] := 10;
y := 20;
WHILE counter = 0 DO
int_array[4,4] := 1;
counter := counter +1;
END_WHILE
main := counter;
END_FUNCTION
";

let mut maintype = new();
let res: i16 = compile_and_run(function.to_string(), &mut maintype);
assert_eq!(res, 1);
}
Loading

0 comments on commit eed5b41

Please sign in to comment.