module lang::flybytes::tests::ComparisonTests
rascal-0.40.17
flybytes-0.2.8
Usage
import lang::flybytes::tests::ComparisonTests;
Source code
http://github.com/usethesource/flybytes/blob/main/src/lang/flybytes/tests/ComparisonTests.rsc
Dependencies
import lang::flybytes::Compiler;
import lang::flybytes::Mirror;
import lang::flybytes::api::JavaLang;
import Node;
import util::Math;
alias CompOp
Exp (Exp, Exp)
function cmpOpClass
Class cmpOpClass(Type t, CompOp op)
function testCmpOp
bool testCmpOp(Class c, Type t, Mirror lhs, Mirror rhs, bool answer)
function make
value make(object(str cl), int _)
value make(string(), int i)
value make(array(integer()), int i)
function fit
real fit(float(), real r)
real fit(double(), real r)
Tests
test testEqTrue
test bool testEqTrue(int i)
= all (t <- intTypes,
I := prim(t, abs(i) % maxIntValue(t)),
testCmpOp(cmpOpClass(t, eq), t, I, I, true));
test testEqFalse
test bool testEqFalse(int i)
= all (t <- intTypes,
I := abs(i) % maxIntValue(t),
testCmpOp(cmpOpClass(t, eq), t, prim(t, I), prim(t, I - 1), false));
test testNEqTrue
test bool testNEqTrue(int i)
= all (t <- intTypes,
I := abs(i) % maxIntValue(t),
testCmpOp(cmpOpClass(t, ne), t, prim(t, I), prim(t, I - 1), true));
test testNEqFalse
test bool testNEqFalse(int i)
= all (t <- intTypes,
I := prim(t, abs(i) % maxIntValue(t)),
testCmpOp(cmpOpClass(t, ne), t, I, I, false));
test testLt
test bool testLt(int i, int j)
= all (t <- intTypes,
I := (i % maxIntValue(t)),
J := (j % maxIntValue(t)),
testCmpOp(cmpOpClass(t, lt), t, prim(t, I), prim(t, J), I < J));
test testGt
test bool testGt(int i, int j)
= all (t <- intTypes,
I := (i % maxIntValue(t)),
J := (j % maxIntValue(t)),
testCmpOp(cmpOpClass(t, gt), t, prim(t, I), prim(t, J), I > J));
test testGeInt
test bool testGeInt(int i, int j)
= all (t <- intTypes,
I := (i % maxIntValue(t)),
J := (j % maxIntValue(t)),
testCmpOp(cmpOpClass(t, ge), t, prim(t, I), prim(t, J), I >= J));
test testLe
test bool testLe(int i, int j)
= all (t <- intTypes,
I := (i % maxIntValue(t)),
J := (j % maxIntValue(t)),
testCmpOp(cmpOpClass(t, le), t, prim(t, I), prim(t, J), I <= J));
test testEqTrue2
test bool testEqTrue2(real r)
= all (t <- floatTypes,
I := 1. / (r + .1),
testCmpOp(cmpOpClass(t, eq), t, prim(t, I), prim(t, I), true));
test testEqFalse2
test bool testEqFalse2(real r)
= all (t <- floatTypes,
I := 1. / (r + .1),
testCmpOp(cmpOpClass(t, eq), t, prim(t, I), prim(t, I + .1), false));
test testLe2
test bool testLe2(real i, real j)
= all (t <- floatTypes,
I := fit(t, 1. / (i + .1)),
J := fit(t, 1. / (j + .1)),
testCmpOp(cmpOpClass(t, le), t, prim(t, I), prim(t, J), I <= J));
test testLt2
test bool testLt2(real i, real j)
= all (t <- floatTypes,
I := fit(t, 1. / (i + .1)),
J := fit(t, 1. / (j + .1)),
testCmpOp(cmpOpClass(t, lt), t, prim(t, I), prim(t, J), I < J));
test testGt2
test bool testGt2(real i, real j)
= all (t <- floatTypes,
I := fit(t, 1. / (i + .1)),
J := fit(t, 1. / (j + .1)),
testCmpOp(cmpOpClass(t, gt), t, prim(t, I), prim(t, J), I > J));
test testGeReal
test bool testGeReal(real i, real j)
= all (t <- floatTypes,
I := fit(t, 1. / (i + .1)),
J := fit(t, 1. / (j + .1)),
testCmpOp(cmpOpClass(t, ge), t, prim(t, I), prim(t, J), I >= J));
test testEqTrue3
test bool testEqTrue3()
= all (t <- objectTypes,
v := make(t, 1),
testCmpOp(cmpOpClass(t, eq), t, v, v, true));
test testEqFalse3
test bool testEqFalse3()
= all (t <- objectTypes,
v1 := make(t, 1),
v2 := make(t, 2),
testCmpOp(cmpOpClass(t, eq), t, v1, v2, false));