From 32d7455c38c77a5aa4f83e8fc8e10d92793704d2 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sun, 28 Jul 2024 18:47:13 +0200 Subject: [PATCH] Added assertions to most tests --- tests/programs/bitwise-and.q | 73 +++++++--------------------------- tests/programs/bitwise-or.q | 73 +++++++--------------------------- tests/programs/bitwise-xor.q | 73 +++++++--------------------------- tests/programs/chained-calls.q | 4 +- tests/programs/math.q | 3 +- tests/programs/nested-calls.q | 4 +- tests/programs/param-multi.q | 2 +- tests/programs/param.q | 2 +- tests/programs/precedence.q | 3 +- tests/programs/reassign.q | 2 +- tests/programs/return.q | 2 +- tests/programs/reuse.q | 2 +- tests/programs/shift.q | 68 ++++++------------------------- tests/programs/square-sum.q | 3 +- tests/programs_test.go | 38 +++++++++--------- 15 files changed, 86 insertions(+), 266 deletions(-) diff --git a/tests/programs/bitwise-and.q b/tests/programs/bitwise-and.q index fda2dcc..34df541 100644 --- a/tests/programs/bitwise-and.q +++ b/tests/programs/bitwise-and.q @@ -1,61 +1,16 @@ -import sys - main() { - if 0 & 0 != 0 { - sys.exit(1) - } - - if 0 & 1 != 0 { - sys.exit(2) - } - - if 1 & 0 != 0 { - sys.exit(3) - } - - if 1 & 1 != 1 { - sys.exit(4) - } - - if 1 & 2 != 0 { - sys.exit(5) - } - - if 1 & 3 != 1 { - sys.exit(6) - } - - if 2 & 0 != 0 { - sys.exit(7) - } - - if 2 & 1 != 0 { - sys.exit(8) - } - - if 2 & 2 != 2 { - sys.exit(9) - } - - if 2 & 3 != 2 { - sys.exit(10) - } - - if 3 & 0 != 0 { - sys.exit(11) - } - - if 3 & 1 != 1 { - sys.exit(12) - } - - if 3 & 2 != 2 { - sys.exit(13) - } - - if 3 & 3 != 3 { - sys.exit(14) - } - - sys.exit(0) + assert 0 & 0 == 0 + assert 0 & 1 == 0 + assert 1 & 0 == 0 + assert 1 & 1 == 1 + assert 1 & 2 == 0 + assert 1 & 3 == 1 + assert 2 & 0 == 0 + assert 2 & 1 == 0 + assert 2 & 2 == 2 + assert 2 & 3 == 2 + assert 3 & 0 == 0 + assert 3 & 1 == 1 + assert 3 & 2 == 2 + assert 3 & 3 == 3 } \ No newline at end of file diff --git a/tests/programs/bitwise-or.q b/tests/programs/bitwise-or.q index 6ea338f..12de2d2 100644 --- a/tests/programs/bitwise-or.q +++ b/tests/programs/bitwise-or.q @@ -1,61 +1,16 @@ -import sys - main() { - if 0 | 0 != 0 { - sys.exit(1) - } - - if 0 | 1 != 1 { - sys.exit(2) - } - - if 1 | 0 != 1 { - sys.exit(3) - } - - if 1 | 1 != 1 { - sys.exit(4) - } - - if 1 | 2 != 3 { - sys.exit(5) - } - - if 1 | 3 != 3 { - sys.exit(6) - } - - if 2 | 0 != 2 { - sys.exit(7) - } - - if 2 | 1 != 3 { - sys.exit(8) - } - - if 2 | 2 != 2 { - sys.exit(9) - } - - if 2 | 3 != 3 { - sys.exit(10) - } - - if 3 | 0 != 3 { - sys.exit(11) - } - - if 3 | 1 != 3 { - sys.exit(12) - } - - if 3 | 2 != 3 { - sys.exit(13) - } - - if 3 | 3 != 3 { - sys.exit(14) - } - - sys.exit(0) + assert 0 | 0 == 0 + assert 0 | 1 == 1 + assert 1 | 0 == 1 + assert 1 | 1 == 1 + assert 1 | 2 == 3 + assert 1 | 3 == 3 + assert 2 | 0 == 2 + assert 2 | 1 == 3 + assert 2 | 2 == 2 + assert 2 | 3 == 3 + assert 3 | 0 == 3 + assert 3 | 1 == 3 + assert 3 | 2 == 3 + assert 3 | 3 == 3 } \ No newline at end of file diff --git a/tests/programs/bitwise-xor.q b/tests/programs/bitwise-xor.q index f648051..e18f5e8 100644 --- a/tests/programs/bitwise-xor.q +++ b/tests/programs/bitwise-xor.q @@ -1,61 +1,16 @@ -import sys - main() { - if 0 ^ 0 != 0 { - sys.exit(1) - } - - if 0 ^ 1 != 1 { - sys.exit(2) - } - - if 1 ^ 0 != 1 { - sys.exit(3) - } - - if 1 ^ 1 != 0 { - sys.exit(4) - } - - if 1 ^ 2 != 3 { - sys.exit(5) - } - - if 1 ^ 3 != 2 { - sys.exit(6) - } - - if 2 ^ 0 != 2 { - sys.exit(7) - } - - if 2 ^ 1 != 3 { - sys.exit(8) - } - - if 2 ^ 2 != 0 { - sys.exit(9) - } - - if 2 ^ 3 != 1 { - sys.exit(10) - } - - if 3 ^ 0 != 3 { - sys.exit(11) - } - - if 3 ^ 1 != 2 { - sys.exit(12) - } - - if 3 ^ 2 != 1 { - sys.exit(13) - } - - if 3 ^ 3 != 0 { - sys.exit(14) - } - - sys.exit(0) + assert 0 ^ 0 == 0 + assert 0 ^ 1 == 1 + assert 1 ^ 0 == 1 + assert 1 ^ 1 == 0 + assert 1 ^ 2 == 3 + assert 1 ^ 3 == 2 + assert 2 ^ 0 == 2 + assert 2 ^ 1 == 3 + assert 2 ^ 2 == 0 + assert 2 ^ 3 == 1 + assert 3 ^ 0 == 3 + assert 3 ^ 1 == 2 + assert 3 ^ 2 == 1 + assert 3 ^ 3 == 0 } \ No newline at end of file diff --git a/tests/programs/chained-calls.q b/tests/programs/chained-calls.q index 49ddb84..e62a02e 100644 --- a/tests/programs/chained-calls.q +++ b/tests/programs/chained-calls.q @@ -1,7 +1,5 @@ -import sys - main() { - sys.exit(f(1) + f(2) + f(3)) + assert f(1) + f(2) + f(3) == 9 } f(x) { diff --git a/tests/programs/math.q b/tests/programs/math.q index b3bb8ee..6fd1712 100644 --- a/tests/programs/math.q +++ b/tests/programs/math.q @@ -1,6 +1,7 @@ main() { x := 1000 - syscall(60, div10(x) / 10 + div(x, 100) * 4 - 40 - x + x) + result := div10(x) / 10 + div(x, 100) * 4 - 40 - x + x + assert result == 10 } div(x, y) { diff --git a/tests/programs/nested-calls.q b/tests/programs/nested-calls.q index f226bcb..a23e15c 100644 --- a/tests/programs/nested-calls.q +++ b/tests/programs/nested-calls.q @@ -1,7 +1,5 @@ -import sys - main() { - sys.exit(f(f(f(1)))) + assert f(f(f(1))) == 4 } f(x) { diff --git a/tests/programs/param-multi.q b/tests/programs/param-multi.q index 97d7ec7..1267e94 100644 --- a/tests/programs/param-multi.q +++ b/tests/programs/param-multi.q @@ -1,5 +1,5 @@ main() { - syscall(60, f(1, 2, 3)) + assert f(1, 2, 3) == 21 } f(x, y, z) { diff --git a/tests/programs/param.q b/tests/programs/param.q index bac5204..11ee501 100644 --- a/tests/programs/param.q +++ b/tests/programs/param.q @@ -1,5 +1,5 @@ main() { - syscall(60, f(1)) + assert f(1) == 3 } f(x) { diff --git a/tests/programs/precedence.q b/tests/programs/precedence.q index bfb4fd2..c8ea775 100644 --- a/tests/programs/precedence.q +++ b/tests/programs/precedence.q @@ -1,5 +1,6 @@ main() { x := 2 y := 3 - syscall(60, (x + y + (x + y) * (x + y)) / x / y + x + y) + result := (x + y + (x + y) * (x + y)) / x / y + x + y + assert result == 10 } \ No newline at end of file diff --git a/tests/programs/reassign.q b/tests/programs/reassign.q index df940d8..26aa3e8 100644 --- a/tests/programs/reassign.q +++ b/tests/programs/reassign.q @@ -2,5 +2,5 @@ main() { x := 1 y := x + 1 x = 2 - syscall(60, y) + assert y == 2 } \ No newline at end of file diff --git a/tests/programs/return.q b/tests/programs/return.q index 13f1e6a..f5e13d5 100644 --- a/tests/programs/return.q +++ b/tests/programs/return.q @@ -1,5 +1,5 @@ main() { - syscall(60, f(2)) + assert f(2) == 6 } f(x) { diff --git a/tests/programs/reuse.q b/tests/programs/reuse.q index 073fd49..010f747 100644 --- a/tests/programs/reuse.q +++ b/tests/programs/reuse.q @@ -1,5 +1,5 @@ main() { - syscall(60, f(1)) + assert f(1) == 3 } f(x) { diff --git a/tests/programs/shift.q b/tests/programs/shift.q index 1fd1ddf..2bb90b8 100644 --- a/tests/programs/shift.q +++ b/tests/programs/shift.q @@ -1,57 +1,15 @@ -import sys - main() { - if 0 << 0 != 0 { - sys.exit(1) - } - - if 0 >> 0 != 0 { - sys.exit(2) - } - - if 1 << 0 != 1 { - sys.exit(3) - } - - if 1 >> 0 != 1 { - sys.exit(4) - } - - if 1 >> 1 != 0 { - sys.exit(5) - } - - if 1 << 1 != 2 { - sys.exit(6) - } - - if 1 << 2 != 4 { - sys.exit(7) - } - - if 1 << 3 != 8 { - sys.exit(8) - } - - if 1 << 4 != 16 { - sys.exit(9) - } - - if 16 >> 1 != 8 { - sys.exit(10) - } - - if 16 >> 2 != 4 { - sys.exit(11) - } - - if 16 >> 3 != 2 { - sys.exit(12) - } - - if 16 >> 4 != 1 { - sys.exit(13) - } - - sys.exit(0) + assert 0 << 0 == 0 + assert 0 >> 0 == 0 + assert 1 << 0 == 1 + assert 1 >> 0 == 1 + assert 1 >> 1 == 0 + assert 1 << 1 == 2 + assert 1 << 2 == 4 + assert 1 << 3 == 8 + assert 1 << 4 == 16 + assert 16 >> 1 == 8 + assert 16 >> 2 == 4 + assert 16 >> 3 == 2 + assert 16 >> 4 == 1 } \ No newline at end of file diff --git a/tests/programs/square-sum.q b/tests/programs/square-sum.q index aace245..04b1237 100644 --- a/tests/programs/square-sum.q +++ b/tests/programs/square-sum.q @@ -1,6 +1,5 @@ main() { - x := f(2, 3) - syscall(60, x) + assert f(2, 3) == 25 } f(x, y) { diff --git a/tests/programs_test.go b/tests/programs_test.go index 46e2a1b..3a2d801 100644 --- a/tests/programs_test.go +++ b/tests/programs_test.go @@ -18,24 +18,12 @@ var programs = []struct { ExitCode int }{ {"empty", "", "", 0}, - {"math", "", "", 10}, - {"precedence", "", "", 10}, - {"square-sum", "", "", 25}, - {"chained-calls", "", "", 9}, - {"nested-calls", "", "", 4}, - {"param", "", "", 3}, - {"param-multi", "", "", 21}, - {"param-order", "", "", 0}, - {"reuse", "", "", 3}, - {"return", "", "", 6}, - {"reassign", "", "", 2}, - {"branch", "", "", 0}, - {"branch-and", "", "", 0}, - {"branch-or", "", "", 0}, - {"branch-both", "", "", 0}, - {"jump-near", "", "", 0}, - {"loop", "", "", 0}, - {"loop-lifetime", "", "", 0}, + {"assert", "", "", 1}, + {"reuse", "", "", 0}, + {"reassign", "", "", 0}, + {"return", "", "", 0}, + {"math", "", "", 0}, + {"precedence", "", "", 0}, {"bitwise-and", "", "", 0}, {"bitwise-or", "", "", 0}, {"bitwise-xor", "", "", 0}, @@ -43,9 +31,21 @@ var programs = []struct { {"modulo", "", "", 0}, {"modulo-assign", "", "", 0}, {"division-split", "", "", 0}, - {"assert", "", "", 1}, {"negative", "", "", 32}, {"negation", "", "", 32}, + {"square-sum", "", "", 0}, + {"chained-calls", "", "", 0}, + {"nested-calls", "", "", 0}, + {"param", "", "", 0}, + {"param-multi", "", "", 0}, + {"param-order", "", "", 0}, + {"branch", "", "", 0}, + {"branch-and", "", "", 0}, + {"branch-or", "", "", 0}, + {"branch-both", "", "", 0}, + {"jump-near", "", "", 0}, + {"loop", "", "", 0}, + {"loop-lifetime", "", "", 0}, } func TestPrograms(t *testing.T) {