Skip to content

Commit

Permalink
hw(5): Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thbwd authored and nicdard committed Dec 7, 2021
1 parent 1b63f4a commit fa9a274
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions 05/sharedtests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ open Assert
let shared_suite : suite =
[ Test ("Dbernhard tests", Dbernhard.dbernhard_tests)
; Test ("Nicdard tests", Nicdard.nicdard_tests)
; Test ("thbwd tests", Thbwd.tests)
]
22 changes: 22 additions & 0 deletions 05/thbwd.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
open Assert
open Gradedtests

let prefix = Test_config.global_prefix ^ "./compiler-design-eth-tests/05/thbwd/"

let tests = (
executed_oat_file [
(prefix ^ "compile_struct_order.oat", "", "123412340");
(prefix ^ "polymorphic_array.oat", "", "1230");
] @
typecheck_file_error [
prefix ^ "dead_code1.oat";
prefix ^ "dead_code2.oat";
prefix ^ "illegal_for_stmt.oat";
prefix ^ "assign_global_function.oat";
prefix ^ "array_init_shadowing.oat";
] @
typecheck_file_correct [
prefix ^ "undead_code1.oat";
prefix ^ "undead_code2.oat";
]
)
5 changes: 5 additions & 0 deletions 05/thbwd/array_init_shadowing.oat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int program(int argc, string[] argv) {
var j = 43;
var y = new int[3]{j->0};
return 0;
}
12 changes: 12 additions & 0 deletions 05/thbwd/assign_global_function.oat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
int x() {
return 4;
}

int y() {
return 2;
}

int program(int argc, string[] argv) {
x = y;
return 0;
}
21 changes: 21 additions & 0 deletions 05/thbwd/compile_struct_order.oat
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
struct Test {
int x;
int y;
int a;
int z
}

global gt = new Test {y=2; x=1; z=4; a=3};

int program(int argc, string[] argv) {
var t = new Test {z=4; y=2; a=3; x=1};
print_int(gt.x);
print_int(gt.y);
print_int(gt.a);
print_int(gt.z);
print_int(t.x);
print_int(t.y);
print_int(t.a);
print_int(t.z);
return 0;
}
5 changes: 5 additions & 0 deletions 05/thbwd/dead_code1.oat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int program(int argc, string[] argv) {
return 0;
print_string("I'm a zombie");
return 0;
}
9 changes: 9 additions & 0 deletions 05/thbwd/dead_code2.oat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
int program(int argc, string[] argv) {
if (332 < 43) {
return 4;
} else {
return 43;
}
print_string("I'm a zombie");
return 0;
}
6 changes: 6 additions & 0 deletions 05/thbwd/illegal_for_stmt.oat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int program(int argc, string[] argv) {
for (var i = 0; i < 40; return 3;) {
print_string("I'm a zombie");
}
return 0;
}
11 changes: 11 additions & 0 deletions 05/thbwd/polymorphic_array.oat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
struct A { int x }
struct B { int x ; int y }
struct C { int x ; int y ; int z }

int program(int argc, string[] argv) {
var y = new A[]{new A{x=1}, new B{x=2; y=54}, new C{x=3; y=511; z=432}};
for (var i = 0; i < 3; i = i + 1;) {
print_int(y[i].x);
}
return 0;
}
7 changes: 7 additions & 0 deletions 05/thbwd/undead_code1.oat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int program(int argc, string[] argv) {
while (true) {
return 0;
}
print_string("I'm a zombie");
return 0;
}
7 changes: 7 additions & 0 deletions 05/thbwd/undead_code2.oat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int program(int argc, string[] argv) {
for (var i = 0; i < 10; i = i + 1;) {
return 0;
}
print_string("I'm a zombie");
return 0;
}

0 comments on commit fa9a274

Please sign in to comment.