Added assertions to most tests

This commit is contained in:
Eduard Urbach 2024-07-28 18:47:13 +02:00
parent c2c147f1b4
commit 32d7455c38
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
15 changed files with 86 additions and 266 deletions

View File

@ -1,61 +1,16 @@
import sys
main() { main() {
if 0 & 0 != 0 { assert 0 & 0 == 0
sys.exit(1) assert 0 & 1 == 0
} assert 1 & 0 == 0
assert 1 & 1 == 1
if 0 & 1 != 0 { assert 1 & 2 == 0
sys.exit(2) assert 1 & 3 == 1
} assert 2 & 0 == 0
assert 2 & 1 == 0
if 1 & 0 != 0 { assert 2 & 2 == 2
sys.exit(3) assert 2 & 3 == 2
} assert 3 & 0 == 0
assert 3 & 1 == 1
if 1 & 1 != 1 { assert 3 & 2 == 2
sys.exit(4) assert 3 & 3 == 3
}
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)
} }

View File

@ -1,61 +1,16 @@
import sys
main() { main() {
if 0 | 0 != 0 { assert 0 | 0 == 0
sys.exit(1) assert 0 | 1 == 1
} assert 1 | 0 == 1
assert 1 | 1 == 1
if 0 | 1 != 1 { assert 1 | 2 == 3
sys.exit(2) assert 1 | 3 == 3
} assert 2 | 0 == 2
assert 2 | 1 == 3
if 1 | 0 != 1 { assert 2 | 2 == 2
sys.exit(3) assert 2 | 3 == 3
} assert 3 | 0 == 3
assert 3 | 1 == 3
if 1 | 1 != 1 { assert 3 | 2 == 3
sys.exit(4) assert 3 | 3 == 3
}
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)
} }

View File

@ -1,61 +1,16 @@
import sys
main() { main() {
if 0 ^ 0 != 0 { assert 0 ^ 0 == 0
sys.exit(1) assert 0 ^ 1 == 1
} assert 1 ^ 0 == 1
assert 1 ^ 1 == 0
if 0 ^ 1 != 1 { assert 1 ^ 2 == 3
sys.exit(2) assert 1 ^ 3 == 2
} assert 2 ^ 0 == 2
assert 2 ^ 1 == 3
if 1 ^ 0 != 1 { assert 2 ^ 2 == 0
sys.exit(3) assert 2 ^ 3 == 1
} assert 3 ^ 0 == 3
assert 3 ^ 1 == 2
if 1 ^ 1 != 0 { assert 3 ^ 2 == 1
sys.exit(4) assert 3 ^ 3 == 0
}
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)
} }

View File

@ -1,7 +1,5 @@
import sys
main() { main() {
sys.exit(f(1) + f(2) + f(3)) assert f(1) + f(2) + f(3) == 9
} }
f(x) { f(x) {

View File

@ -1,6 +1,7 @@
main() { main() {
x := 1000 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) { div(x, y) {

View File

@ -1,7 +1,5 @@
import sys
main() { main() {
sys.exit(f(f(f(1)))) assert f(f(f(1))) == 4
} }
f(x) { f(x) {

View File

@ -1,5 +1,5 @@
main() { main() {
syscall(60, f(1, 2, 3)) assert f(1, 2, 3) == 21
} }
f(x, y, z) { f(x, y, z) {

View File

@ -1,5 +1,5 @@
main() { main() {
syscall(60, f(1)) assert f(1) == 3
} }
f(x) { f(x) {

View File

@ -1,5 +1,6 @@
main() { main() {
x := 2 x := 2
y := 3 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
} }

View File

@ -2,5 +2,5 @@ main() {
x := 1 x := 1
y := x + 1 y := x + 1
x = 2 x = 2
syscall(60, y) assert y == 2
} }

View File

@ -1,5 +1,5 @@
main() { main() {
syscall(60, f(2)) assert f(2) == 6
} }
f(x) { f(x) {

View File

@ -1,5 +1,5 @@
main() { main() {
syscall(60, f(1)) assert f(1) == 3
} }
f(x) { f(x) {

View File

@ -1,57 +1,15 @@
import sys
main() { main() {
if 0 << 0 != 0 { assert 0 << 0 == 0
sys.exit(1) assert 0 >> 0 == 0
} assert 1 << 0 == 1
assert 1 >> 0 == 1
if 0 >> 0 != 0 { assert 1 >> 1 == 0
sys.exit(2) assert 1 << 1 == 2
} assert 1 << 2 == 4
assert 1 << 3 == 8
if 1 << 0 != 1 { assert 1 << 4 == 16
sys.exit(3) assert 16 >> 1 == 8
} assert 16 >> 2 == 4
assert 16 >> 3 == 2
if 1 >> 0 != 1 { assert 16 >> 4 == 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)
} }

View File

@ -1,6 +1,5 @@
main() { main() {
x := f(2, 3) assert f(2, 3) == 25
syscall(60, x)
} }
f(x, y) { f(x, y) {

View File

@ -18,24 +18,12 @@ var programs = []struct {
ExitCode int ExitCode int
}{ }{
{"empty", "", "", 0}, {"empty", "", "", 0},
{"math", "", "", 10}, {"assert", "", "", 1},
{"precedence", "", "", 10}, {"reuse", "", "", 0},
{"square-sum", "", "", 25}, {"reassign", "", "", 0},
{"chained-calls", "", "", 9}, {"return", "", "", 0},
{"nested-calls", "", "", 4}, {"math", "", "", 0},
{"param", "", "", 3}, {"precedence", "", "", 0},
{"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},
{"bitwise-and", "", "", 0}, {"bitwise-and", "", "", 0},
{"bitwise-or", "", "", 0}, {"bitwise-or", "", "", 0},
{"bitwise-xor", "", "", 0}, {"bitwise-xor", "", "", 0},
@ -43,9 +31,21 @@ var programs = []struct {
{"modulo", "", "", 0}, {"modulo", "", "", 0},
{"modulo-assign", "", "", 0}, {"modulo-assign", "", "", 0},
{"division-split", "", "", 0}, {"division-split", "", "", 0},
{"assert", "", "", 1},
{"negative", "", "", 32}, {"negative", "", "", 32},
{"negation", "", "", 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) { func TestPrograms(t *testing.T) {