Skip to content

Commit

Permalink
fixed issues in ArithmeticTests
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Jun 26, 2024
1 parent 3437f34 commit 60ba8ac
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/lang/flybytes/tests/ArithmeticTests.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Class unOpClass(Type t, UnOp op) {

bool testBinOp(Class c, Type t, num lhs, num rhs, num answer) {
m = loadClass(c);
reply = val(t, m.invokeStatic(methodDesc(t, "op", [t, t]), [prim(t, lhs), prim(t,rhs)]));
reply = intVal(t, m.invokeStatic(methodDesc(t, "op", [t, t]), [prim(t, lhs), prim(t,rhs)]));

if (answer != reply) {
println("op(<lhs>,<rhs>) == <round(t, answer)> != <round(t,reply)>");
Expand All @@ -50,7 +50,7 @@ bool testBinOp(Class c, Type t, num lhs, num rhs, num answer) {

bool testUnOp(Class c, Type t, num arg, num answer) {
m = loadClass(c);
reply = val(t, m.invokeStatic(methodDesc(t, "op", [t]), [prim(t, arg)]));
reply = intVal(t, m.invokeStatic(methodDesc(t, "op", [t]), [prim(t, arg)]));

if (answer != reply) {
println("op(<arg>) == <round(t, answer)> != <round(t,reply)>");
Expand All @@ -62,7 +62,7 @@ bool testUnOp(Class c, Type t, num arg, num answer) {

bool testBinOpRange(Class c, Type t, num lhs, num rhs, real answer) {
m = loadClass(c);
reply = val(t, m.invokeStatic(methodDesc(t, "op", [t, t]), [prim(t, lhs), prim(t,rhs)]));
reply = realVal(t, m.invokeStatic(methodDesc(t, "op", [t, t]), [prim(t, lhs), prim(t,rhs)]));

if (real r := reply, abs(answer - r) > 0.1) {
println("op(<lhs>,<rhs>) == <answer> != <reply> (diff: <abs(answer - r)>)");
Expand All @@ -74,7 +74,7 @@ bool testBinOpRange(Class c, Type t, num lhs, num rhs, real answer) {

bool testUnOpRange(Class c, Type t, num arg, real answer) {
m = loadClass(c);
real reply = val(t, m.invokeStatic(methodDesc(t, "op", [t]), [prim(t, arg)]));
real reply = realVal(t, m.invokeStatic(methodDesc(t, "op", [t]), [prim(t, arg)]));

if (abs(answer - reply) > 0.1) {
return false;
Expand Down Expand Up @@ -114,7 +114,7 @@ test bool testDivInt(int i, int j)
testBinOp(binOpClass(t, div), t, I, J, I / J));

test bool testRem(int i, int j)
= all (t <- exactArithmeticTypes
= all (t <- exactArithmeticTypes,
I := (i % maxIntValue(t)),
J := abs(((j % maxIntValue(t)) / 2)) + 1, // never 0,
testBinOp(binOpClass(t, rem), t, I, J, I % J));
Expand Down Expand Up @@ -159,7 +159,7 @@ private real round(float(), real f) = precision(f, 0);
private real round(double(), real f) = precision(f, 0);
private default int round(Type _, int f) = f;
private num val(float(), Mirror r) = r.toValue(#real);
private num val(double(), Mirror r) = r.toValue(#real);
private default num val(Type _, Mirror r) = r.toValue(#int);
private real realVal(float(), Mirror r) = r.toValue(#real);
private real realVal(double(), Mirror r) = r.toValue(#real);
private int intVal(Type _, Mirror r) = r.toValue(#int);

0 comments on commit 60ba8ac

Please sign in to comment.