42 #include <type_traits>
50 #define TESTS_PER_OPERATION 20
55 VecOwn<Expression> returnValues;
56 returnValues.emplace_back(std::move(expression));
59 Own<Statement> query = mk<ram::Query>(mk<ram::SubroutineReturn>(std::move(returnValues)));
60 std::map<std::string, Own<Statement>> subs;
61 subs.insert(std::make_pair(
"test", std::move(query)));
64 Own<Program> prog = mk<Program>(std::move(rels), mk<ram::Sequence>(), std::move(subs));
69 TranslationUnit translationUnit(std::move(prog), symTab, errReport, debugReport);
72 Own<Engine> interpreter = mk<Engine>(translationUnit);
74 std::string name(
"test");
75 std::vector<RamDomain> ret;
77 interpreter->executeSubroutine(name, {}, ret);
89 return evalExpression(mk<ram::IntrinsicOperator>(functor, std::move(args)), symTab);
100 args.push_back(mk<SignedConstant>(arg1));
108 args.push_back(mk<SignedConstant>(arg1));
109 args.push_back(mk<SignedConstant>(arg2));
114 TEST(SignedConstant, ArithmeticEvaluation) {
132 EXPECT_EQ(ramBitCast<RamFloat>(result), -randomNumber);
136 TEST(Unary, BinaryNot) {
144 TEST(Unary, UnsignedBinaryNot) {
147 for (
auto randomNumber : testutil::generateRandomVector<RamUnsigned>(
TESTS_PER_OPERATION)) {
149 EXPECT_EQ(ramBitCast<RamUnsigned>(result), ~randomNumber);
153 TEST(Unary, LogicalNeg) {
161 TEST(Unary, UnsignedLogicalNeg) {
164 for (
auto randomNumber : testutil::generateRandomVector<RamUnsigned>(
TESTS_PER_OPERATION)) {
170 TEST(Unary, SingedTpUnsigned) {
179 TEST(Unary, UnsignedToSigned) {
182 for (
auto randomNumber : testutil::generateRandomVector<RamUnsigned>(
TESTS_PER_OPERATION)) {
188 TEST(Unary, SignedToFloat) {
197 TEST(Unary, FloatToSigned) {
206 TEST(Unary, UnsignedToFloat) {
209 for (
auto randomNumber : testutil::generateRandomVector<RamUnsigned>(
TESTS_PER_OPERATION)) {
215 TEST(Unary, FloatToUnsigned) {
224 TEST(Binary, SignedAdd) {
238 TEST(Binary, UnsignedAdd) {
248 EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 + arg2);
252 TEST(Binary, FloatAdd) {
259 auto arg1 = vecArg1[
i];
260 auto arg2 = vecArg2[
i];
262 EXPECT_EQ(ramBitCast<RamFloat>(result), arg1 + arg2);
266 TEST(Binary, SignedSub) {
273 auto arg1 = vecArg1[
i];
274 auto arg2 = vecArg2[
i];
280 TEST(Binary, UnsignedSub) {
287 auto arg1 = vecArg1[
i];
288 auto arg2 = vecArg2[
i];
290 EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 - arg2);
294 TEST(Binary, FloatSub) {
301 auto arg1 = vecArg1[
i];
302 auto arg2 = vecArg2[
i];
304 EXPECT_EQ(ramBitCast<RamFloat>(result), arg1 - arg2);
308 TEST(Binary, SignedMul) {
315 auto arg1 = vecArg1[
i];
316 auto arg2 = vecArg2[
i];
322 TEST(Binary, UnsignedMul) {
329 auto arg1 = vecArg1[
i];
330 auto arg2 = vecArg2[
i];
332 EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 * arg2);
336 TEST(Binary, FloatMul) {
343 auto arg1 = vecArg1[
i];
344 auto arg2 = vecArg2[
i];
346 EXPECT_EQ(ramBitCast<RamFloat>(result), arg1 * arg2);
350 TEST(Binary, SignedDiv) {
357 auto arg1 = vecArg1[
i];
358 auto arg2 = vecArg2[
i];
366 TEST(Binary, UnsignedDiv) {
373 auto arg1 = vecArg1[
i];
374 auto arg2 = vecArg2[
i];
377 EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 / arg2);
382 TEST(Binary, FloatDiv) {
389 auto arg1 = vecArg1[
i];
390 auto arg2 = vecArg2[
i];
393 EXPECT_EQ(ramBitCast<RamFloat>(result), arg1 / arg2);
398 TEST(Binary, SignedExp) {
405 auto arg1 = vecArg1[
i];
406 auto arg2 = vecArg2[
i];
412 TEST(Binary, UnsignedExp) {
419 auto arg1 = vecArg1[
i];
420 auto arg2 = vecArg2[
i];
426 TEST(Binary, FloatExp) {
433 auto arg1 = vecArg1[
i];
434 auto arg2 = vecArg2[
i];
436 auto expected =
static_cast<RamFloat>(std::pow(arg1, arg2));
437 EXPECT_TRUE((std::isnan(result) && std::isnan(expected)) || result == expected);
441 TEST(Binary, SignedMod) {
448 auto arg1 = vecArg1[
i];
449 auto arg2 = vecArg2[
i];
455 TEST(Binary, UnsignedMod) {
462 auto arg1 = vecArg1[
i];
463 auto arg2 = vecArg2[
i];
465 EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 % arg2);
469 TEST(Binary, SignedBinaryAnd) {
476 auto arg1 = vecArg1[
i];
477 auto arg2 = vecArg2[
i];
483 TEST(Binary, UnsignedBinaryAnd) {
490 auto arg1 = vecArg1[
i];
491 auto arg2 = vecArg2[
i];
493 EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 & arg2);
497 TEST(Binary, SignedBinaryOr) {
504 auto arg1 = vecArg1[
i];
505 auto arg2 = vecArg2[
i];
511 TEST(Binary, UnsignedBinaryOr) {
518 auto arg1 = vecArg1[
i];
519 auto arg2 = vecArg2[
i];
521 EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 | arg2);
525 TEST(Binary, SignedBinaryXor) {
532 auto arg1 = vecArg1[
i];
533 auto arg2 = vecArg2[
i];
539 TEST(Binary, UnsignedBinaryXor) {
546 auto arg1 = vecArg1[
i];
547 auto arg2 = vecArg2[
i];
549 EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 ^ arg2);
553 TEST(Binary, SignedLogicalAnd) {
560 auto arg1 = vecArg1[
i];
561 auto arg2 = vecArg2[
i];
567 TEST(Binary, UnsignedLogicalAnd) {
574 auto arg1 = vecArg1[
i];
575 auto arg2 = vecArg2[
i];
577 EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 || arg2);
581 TEST(Binary, SignedLogicalOr) {
588 auto arg1 = vecArg1[
i];
589 auto arg2 = vecArg2[
i];
595 TEST(Binary, UnsignedLogicalOr) {
602 auto arg1 = vecArg1[
i];
603 auto arg2 = vecArg2[
i];
605 EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 || arg2);
609 TEST(MultiArg, Max) {
614 args.push_back(mk<SignedConstant>(
i));
622 TEST(MultiArg, UnsignedMax) {
632 EXPECT_EQ(ramBitCast<RamUnsigned>(result), 100);
635 TEST(MultiArg, FloatMax) {
648 TEST(MultiArg, SymbolMax) {
655 args.push_back(mk<SignedConstant>(symTab.
lookup(std::to_string(
i))));
663 TEST(MultiArg, Min) {
668 args.push_back(mk<SignedConstant>(
i));
676 TEST(MultiArg, UnsignedMin) {
686 EXPECT_EQ(ramBitCast<RamUnsigned>(result), 0);
689 TEST(MultiArg, FloatMin) {
702 TEST(MultiArg, SymbolMin) {
709 args.push_back(mk<SignedConstant>(symTab.
lookup(std::to_string(
i))));