Fixed incorrect division results
This commit is contained in:
@ -1,13 +1,11 @@
|
||||
main() {
|
||||
quotient := 0
|
||||
remainder := 0
|
||||
dividend := 256
|
||||
divisor := 100
|
||||
|
||||
quotient, remainder = 256 / 100
|
||||
quotient, remainder := 256 / 100
|
||||
assert quotient == 2
|
||||
assert remainder == 56
|
||||
|
||||
|
||||
quotient, remainder = dividend / 100
|
||||
assert quotient == 2
|
||||
assert remainder == 56
|
||||
@ -15,7 +13,7 @@ main() {
|
||||
quotient, remainder = 256 / divisor
|
||||
assert quotient == 2
|
||||
assert remainder == 56
|
||||
|
||||
|
||||
quotient, remainder = dividend / divisor
|
||||
assert quotient == 2
|
||||
assert remainder == 56
|
||||
|
@ -1,9 +0,0 @@
|
||||
main() {
|
||||
f(10)
|
||||
}
|
||||
|
||||
f(new int) {
|
||||
old := new
|
||||
new -= 1
|
||||
assert new != old
|
||||
}
|
30
tests/programs/operator-assign.q
Normal file
30
tests/programs/operator-assign.q
Normal file
@ -0,0 +1,30 @@
|
||||
main() {
|
||||
number(10)
|
||||
register(10)
|
||||
}
|
||||
|
||||
number(x int) {
|
||||
y := x
|
||||
x -= 1
|
||||
assert x < y
|
||||
x += 1
|
||||
assert x == y
|
||||
x *= 2
|
||||
assert x > y
|
||||
x /= 2
|
||||
assert x == y
|
||||
}
|
||||
|
||||
register(x int) {
|
||||
y := x
|
||||
num := 1
|
||||
x -= num
|
||||
assert x < y
|
||||
x += num
|
||||
assert x == y
|
||||
num = 2
|
||||
x *= num
|
||||
assert x > y
|
||||
x /= num
|
||||
assert x == y
|
||||
}
|
@ -7,11 +7,11 @@ main() {
|
||||
f := 6
|
||||
g := 7
|
||||
|
||||
assert a != 0
|
||||
assert b != 0
|
||||
assert c != 0
|
||||
assert d != 0
|
||||
assert e != 0
|
||||
assert f != 0
|
||||
assert g != 0
|
||||
assert a == 1
|
||||
assert b == 2
|
||||
assert c == 3
|
||||
assert d == 4
|
||||
assert e == 5
|
||||
assert f == 6
|
||||
assert g == 7
|
||||
}
|
@ -14,58 +14,56 @@ import (
|
||||
|
||||
var programs = []struct {
|
||||
Name string
|
||||
Input string
|
||||
Output string
|
||||
ExitCode int
|
||||
}{
|
||||
{"empty", "", "", 0},
|
||||
{"assert", "", "", 1},
|
||||
{"variables", "", "", 0},
|
||||
{"reassign", "", "", 0},
|
||||
{"reuse", "", "", 0},
|
||||
{"return", "", "", 0},
|
||||
{"return-multi", "", "", 0},
|
||||
{"math", "", "", 0},
|
||||
{"precedence", "", "", 0},
|
||||
{"op-assign", "", "", 0},
|
||||
{"binary", "", "", 0},
|
||||
{"octal", "", "", 0},
|
||||
{"hexadecimal", "", "", 0},
|
||||
{"const", "", "", 0},
|
||||
{"escape-rune", "", "", 0},
|
||||
{"escape-string", "", "", 0},
|
||||
{"bitwise-and", "", "", 0},
|
||||
{"bitwise-or", "", "", 0},
|
||||
{"bitwise-xor", "", "", 0},
|
||||
{"shift", "", "", 0},
|
||||
{"modulo", "", "", 0},
|
||||
{"modulo-assign", "", "", 0},
|
||||
{"div-split", "", "", 0},
|
||||
{"int64", "", "", 0},
|
||||
{"negative", "", "", 0},
|
||||
{"negation", "", "", 0},
|
||||
{"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},
|
||||
{"branch-save", "", "", 0},
|
||||
{"jump-near", "", "", 0},
|
||||
{"switch", "", "", 0},
|
||||
{"loop-infinite", "", "", 0},
|
||||
{"loop-lifetime", "", "", 0},
|
||||
{"loop-for", "", "", 0},
|
||||
{"memory-free", "", "", 0},
|
||||
{"out-of-memory", "", "", 0},
|
||||
{"index-static", "", "", 0},
|
||||
{"index-dynamic", "", "", 0},
|
||||
{"struct", "", "", 0},
|
||||
{"len", "", "", 0},
|
||||
{"empty", 0},
|
||||
{"assert", 1},
|
||||
{"binary", 0},
|
||||
{"octal", 0},
|
||||
{"hexadecimal", 0},
|
||||
{"variables", 0},
|
||||
{"reassign", 0},
|
||||
{"reuse", 0},
|
||||
{"return", 0},
|
||||
{"return-multi", 0},
|
||||
{"math", 0},
|
||||
{"precedence", 0},
|
||||
{"operator-assign", 0},
|
||||
{"const", 0},
|
||||
{"escape-rune", 0},
|
||||
{"escape-string", 0},
|
||||
{"bitwise-and", 0},
|
||||
{"bitwise-or", 0},
|
||||
{"bitwise-xor", 0},
|
||||
{"shift", 0},
|
||||
{"modulo", 0},
|
||||
{"modulo-assign", 0},
|
||||
{"div-split", 0},
|
||||
{"int64", 0},
|
||||
{"negative", 0},
|
||||
{"negation", 0},
|
||||
{"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},
|
||||
{"branch-save", 0},
|
||||
{"jump-near", 0},
|
||||
{"switch", 0},
|
||||
{"loop-infinite", 0},
|
||||
{"loop-lifetime", 0},
|
||||
{"loop-for", 0},
|
||||
{"memory-free", 0},
|
||||
{"out-of-memory", 0},
|
||||
{"index-static", 0},
|
||||
{"index-dynamic", 0},
|
||||
{"struct", 0},
|
||||
{"len", 0},
|
||||
}
|
||||
|
||||
func TestPrograms(t *testing.T) {
|
||||
@ -74,12 +72,12 @@ func TestPrograms(t *testing.T) {
|
||||
|
||||
t.Run(test.Name+"/debug", func(t *testing.T) {
|
||||
config.Optimize(false)
|
||||
run(t, file, "debug", test.Input, test.Output, test.ExitCode)
|
||||
run(t, file, "debug", "", "", test.ExitCode)
|
||||
})
|
||||
|
||||
t.Run(test.Name+"/release", func(t *testing.T) {
|
||||
config.Optimize(true)
|
||||
run(t, file, "release", test.Input, test.Output, test.ExitCode)
|
||||
run(t, file, "release", "", "", test.ExitCode)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user