souffle  2.0.2-371-g6315b36
Functions
souffle::interpreter::test Namespace Reference

Functions

RamDomain evalBinary (FunctorOp functor, RamDomain arg1, RamDomain arg2)
 Evaluate a binary operator. More...
 
RamDomain evalExpression (Own< Expression > expression)
 Function to evaluate a single Expression. More...
 
RamDomain evalExpression (Own< Expression > expression, SymbolTable &symTab)
 Function to evaluate a single Expression. More...
 
RamDomain evalMultiArg (FunctorOp functor, VecOwn< Expression > args)
 
RamDomain evalMultiArg (FunctorOp functor, VecOwn< Expression > args, SymbolTable &symTab)
 
RamDomain evalUnary (FunctorOp functor, RamDomain arg1)
 Evaluate a single argument expression. More...
 
 TEST (Basic, Iteration)
 
 TEST (Binary, FloatAdd)
 
 TEST (Binary, FloatDiv)
 
 TEST (Binary, FloatExp)
 
 TEST (Binary, FloatMul)
 
 TEST (Binary, FloatSub)
 
 TEST (Binary, SignedAdd)
 
 TEST (Binary, SignedBinaryAnd)
 
 TEST (Binary, SignedBinaryOr)
 
 TEST (Binary, SignedBinaryXor)
 
 TEST (Binary, SignedDiv)
 
 TEST (Binary, SignedExp)
 
 TEST (Binary, SignedLogicalAnd)
 
 TEST (Binary, SignedLogicalOr)
 
 TEST (Binary, SignedMod)
 
 TEST (Binary, SignedMul)
 
 TEST (Binary, SignedSub)
 
 TEST (Binary, UnsignedAdd)
 
 TEST (Binary, UnsignedBinaryAnd)
 
 TEST (Binary, UnsignedBinaryOr)
 
 TEST (Binary, UnsignedBinaryXor)
 
 TEST (Binary, UnsignedDiv)
 
 TEST (Binary, UnsignedExp)
 
 TEST (Binary, UnsignedLogicalAnd)
 
 TEST (Binary, UnsignedLogicalOr)
 
 TEST (Binary, UnsignedMod)
 
 TEST (Binary, UnsignedMul)
 
 TEST (Binary, UnsignedSub)
 
 TEST (Independence, Iteration)
 
 TEST (IndependentCopying, Iteration)
 
 TEST (IndependentMoving, Iteration)
 
 TEST (IO_load, Float)
 
 TEST (IO_load, MixedTypesLoad)
 
 TEST (IO_load, Signed)
 
 TEST (IO_load, Unsigned)
 
 TEST (IO_store, Float)
 
 TEST (IO_store, FloatSimple)
 
 TEST (IO_store, MixedTypes)
 
 TEST (IO_store, Signed)
 
 TEST (IO_store, SignedChangedDelimiter)
 
 TEST (IO_store, Unsigned)
 
 TEST (MultiArg, FloatMax)
 
 TEST (MultiArg, FloatMin)
 
 TEST (MultiArg, Max)
 
 TEST (MultiArg, Min)
 
 TEST (MultiArg, SymbolMax)
 
 TEST (MultiArg, SymbolMin)
 
 TEST (MultiArg, UnsignedMax)
 
 TEST (MultiArg, UnsignedMin)
 
 TEST (Relation0, Construction)
 
 TEST (Relation0, Iteration)
 
 TEST (Relation1, Construction)
 
 TEST (Reordering, Iteration)
 
 TEST (SignedConstant, ArithmeticEvaluation)
 
 TEST (Unary, BinaryNot)
 
 TEST (Unary, FloatNeg)
 
 TEST (Unary, FloatToSigned)
 
 TEST (Unary, FloatToUnsigned)
 
 TEST (Unary, LogicalNeg)
 
 TEST (Unary, Neg)
 
 TEST (Unary, SignedToFloat)
 
 TEST (Unary, SingedTpUnsigned)
 
 TEST (Unary, UnsignedBinaryNot)
 
 TEST (Unary, UnsignedLogicalNeg)
 
 TEST (Unary, UnsignedToFloat)
 
 TEST (Unary, UnsignedToSigned)
 
const std::string testInterpreterStore (std::vector< std::string > attribs, std::vector< std::string > attribsTypes, VecOwn< Expression > exprs)
 

Function Documentation

◆ evalBinary()

RamDomain souffle::interpreter::test::evalBinary ( FunctorOp  functor,
RamDomain  arg1,
RamDomain  arg2 
)

Evaluate a binary operator.

Definition at line 112 of file ram_arithmetic_test.cpp.

114  {
115  RamDomain num = 42;
116  Own<Expression> expression = mk<SignedConstant>(num);
117  RamDomain result = evalExpression(std::move(expression));
118  EXPECT_EQ(result, num);

Referenced by TEST().

◆ evalExpression() [1/2]

RamDomain souffle::interpreter::test::evalExpression ( Own< Expression expression)

Function to evaluate a single Expression.

Definition at line 89 of file ram_arithmetic_test.cpp.

92  {

◆ evalExpression() [2/2]

RamDomain souffle::interpreter::test::evalExpression ( Own< Expression expression,
SymbolTable symTab 
)

Function to evaluate a single Expression.

Definition at line 59 of file ram_arithmetic_test.cpp.

77  {}, ret);
78 
79  return ret.at(0);
80 }
81 
82 /** Function to evaluate a single Expression. */
83 RamDomain evalExpression(Own<Expression> expression) {
84  SymbolTable symTab;
85  return evalExpression(std::move(expression), symTab);
86 }

◆ evalMultiArg() [1/2]

RamDomain souffle::interpreter::test::evalMultiArg ( FunctorOp  functor,
VecOwn< Expression args 
)

Definition at line 98 of file ram_arithmetic_test.cpp.

98  {
99  VecOwn<Expression> args;
100  args.push_back(mk<SignedConstant>(arg1));
101 

References evalMultiArg().

Here is the call graph for this function:

◆ evalMultiArg() [2/2]

RamDomain souffle::interpreter::test::evalMultiArg ( FunctorOp  functor,
VecOwn< Expression args,
SymbolTable symTab 
)

Definition at line 94 of file ram_arithmetic_test.cpp.

98  {

Referenced by evalMultiArg(), and evalUnary().

◆ evalUnary()

RamDomain souffle::interpreter::test::evalUnary ( FunctorOp  functor,
RamDomain  arg1 
)

Evaluate a single argument expression.

Definition at line 104 of file ram_arithmetic_test.cpp.

106  {
107  VecOwn<Expression> args;
108  args.push_back(mk<SignedConstant>(arg1));
109  args.push_back(mk<SignedConstant>(arg2));

References evalMultiArg().

Referenced by TEST().

Here is the call graph for this function:

◆ TEST() [1/66]

souffle::interpreter::test::TEST ( Basic  ,
Iteration   
)

Definition at line 94 of file interpreter_relation_test.cpp.

94  {"i"}, {"i"}, 0);
95 
96  // add some values
97  relInt.insert(tuple(&relInt, {1}));
98  relInt.insert(tuple(&relInt, {2}));
99  relInt.insert(tuple(&relInt, {3}));
100  relInt.insert(tuple(&relInt, {4}));
101 
102  // Iterate
103  souffle::Relation::iterator it = relInt.begin();
104  std::size_t count = 0;
105  while (it != relInt.end()) {
106  // Check the 'deref' doesn't crash
107  auto value = (*it)[0];
108  (void)value;
109  ++it;
110  ++count;
111  }
112  EXPECT_EQ(4, count);
113 }
114 
115 TEST(Independence, Iteration) {
116  // create a table
117  SymbolTable symbolTable;
118  MinIndexSelection order{};
119  order.insertDefaultTotalIndex(1);

◆ TEST() [2/66]

souffle::interpreter::test::TEST ( Binary  ,
FloatAdd   
)

Definition at line 258 of file ram_arithmetic_test.cpp.

258  {
259  auto arg1 = vecArg1[i];
260  auto arg2 = vecArg2[i];
261  RamDomain result = evalBinary(functor, ramBitCast(arg1), ramBitCast(arg2));
262  EXPECT_EQ(ramBitCast<RamFloat>(result), arg1 + arg2);
263  }
264 }
265 
266 TEST(Binary, SignedSub) {
267  FunctorOp functor = FunctorOp::SUB;
268 
269  auto vecArg1 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);
270  auto vecArg2 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, i, and souffle::ramBitCast().

Here is the call graph for this function:

◆ TEST() [3/66]

souffle::interpreter::test::TEST ( Binary  ,
FloatDiv   
)

Definition at line 388 of file ram_arithmetic_test.cpp.

388  {
389  auto arg1 = vecArg1[i];
390  auto arg2 = vecArg2[i];
391  if (arg2 != 0) {
392  RamDomain result = evalBinary(functor, ramBitCast(arg1), ramBitCast(arg2));
393  EXPECT_EQ(ramBitCast<RamFloat>(result), arg1 / arg2);
394  }
395  }
396 }
397 
398 TEST(Binary, SignedExp) {
399  FunctorOp functor = FunctorOp::EXP;
400 
401  auto vecArg1 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);
402  auto vecArg2 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, i, and souffle::ramBitCast().

Here is the call graph for this function:

◆ TEST() [4/66]

souffle::interpreter::test::TEST ( Binary  ,
FloatExp   
)

Definition at line 432 of file ram_arithmetic_test.cpp.

432  {
433  auto arg1 = vecArg1[i];
434  auto arg2 = vecArg2[i];
435  auto result = ramBitCast<RamFloat>(evalBinary(functor, ramBitCast(arg1), ramBitCast(arg2)));
436  auto expected = static_cast<RamFloat>(std::pow(arg1, arg2));
437  EXPECT_TRUE((std::isnan(result) && std::isnan(expected)) || result == expected);
438  }
439 }
440 
441 TEST(Binary, SignedMod) {
442  FunctorOp functor = FunctorOp::MOD;
443 
444  auto vecArg1 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);
445  auto vecArg2 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_TRUE, i, and souffle::ramBitCast().

Here is the call graph for this function:

◆ TEST() [5/66]

souffle::interpreter::test::TEST ( Binary  ,
FloatMul   
)

Definition at line 342 of file ram_arithmetic_test.cpp.

342  {
343  auto arg1 = vecArg1[i];
344  auto arg2 = vecArg2[i];
345  RamDomain result = evalBinary(functor, ramBitCast(arg1), ramBitCast(arg2));
346  EXPECT_EQ(ramBitCast<RamFloat>(result), arg1 * arg2);
347  }
348 }
349 
350 TEST(Binary, SignedDiv) {
351  FunctorOp functor = FunctorOp::DIV;
352 
353  auto vecArg1 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);
354  auto vecArg2 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, i, and souffle::ramBitCast().

Here is the call graph for this function:

◆ TEST() [6/66]

souffle::interpreter::test::TEST ( Binary  ,
FloatSub   
)

Definition at line 300 of file ram_arithmetic_test.cpp.

300  {
301  auto arg1 = vecArg1[i];
302  auto arg2 = vecArg2[i];
303  RamDomain result = evalBinary(functor, ramBitCast(arg1), ramBitCast(arg2));
304  EXPECT_EQ(ramBitCast<RamFloat>(result), arg1 - arg2);
305  }
306 }
307 
308 TEST(Binary, SignedMul) {
309  FunctorOp functor = FunctorOp::MUL;
310 
311  auto vecArg1 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);
312  auto vecArg2 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, i, and souffle::ramBitCast().

Here is the call graph for this function:

◆ TEST() [7/66]

souffle::interpreter::test::TEST ( Binary  ,
SignedAdd   
)

Definition at line 230 of file ram_arithmetic_test.cpp.

230  {
231  RamDomain arg1 = vecArg1[i];
232  RamDomain arg2 = vecArg2[i];
233  RamDomain result = evalBinary(functor, arg1, arg2);
234  EXPECT_EQ(result, arg1 + arg2);
235  }
236 }
237 
238 TEST(Binary, UnsignedAdd) {
239  FunctorOp functor = FunctorOp::UADD;
240 
241  auto vecArg1 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);
242  auto vecArg2 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, and i.

Here is the call graph for this function:

◆ TEST() [8/66]

souffle::interpreter::test::TEST ( Binary  ,
SignedBinaryAnd   
)

Definition at line 475 of file ram_arithmetic_test.cpp.

475  {
476  auto arg1 = vecArg1[i];
477  auto arg2 = vecArg2[i];
478  RamDomain result = evalBinary(functor, arg1, arg2);
479  EXPECT_EQ(result, arg1 & arg2);
480  }
481 }
482 
483 TEST(Binary, UnsignedBinaryAnd) {
484  FunctorOp functor = FunctorOp::UBAND;
485 
486  auto vecArg1 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);
487  auto vecArg2 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, and i.

Here is the call graph for this function:

◆ TEST() [9/66]

souffle::interpreter::test::TEST ( Binary  ,
SignedBinaryOr   
)

Definition at line 503 of file ram_arithmetic_test.cpp.

503  {
504  auto arg1 = vecArg1[i];
505  auto arg2 = vecArg2[i];
506  RamDomain result = evalBinary(functor, arg1, arg2);
507  EXPECT_EQ(result, arg1 | arg2);
508  }
509 }
510 
511 TEST(Binary, UnsignedBinaryOr) {
512  FunctorOp functor = FunctorOp::UBOR;
513 
514  auto vecArg1 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);
515  auto vecArg2 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, and i.

Here is the call graph for this function:

◆ TEST() [10/66]

souffle::interpreter::test::TEST ( Binary  ,
SignedBinaryXor   
)

Definition at line 531 of file ram_arithmetic_test.cpp.

531  {
532  auto arg1 = vecArg1[i];
533  auto arg2 = vecArg2[i];
534  RamDomain result = evalBinary(functor, arg1, arg2);
535  EXPECT_EQ(result, arg1 ^ arg2);
536  }
537 }
538 
539 TEST(Binary, UnsignedBinaryXor) {
540  FunctorOp functor = FunctorOp::UBXOR;
541 
542  auto vecArg1 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);
543  auto vecArg2 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, and i.

Here is the call graph for this function:

◆ TEST() [11/66]

souffle::interpreter::test::TEST ( Binary  ,
SignedDiv   
)

Definition at line 356 of file ram_arithmetic_test.cpp.

356  {
357  auto arg1 = vecArg1[i];
358  auto arg2 = vecArg2[i];
359  if (arg2 != 0) {
360  RamDomain result = evalBinary(functor, arg1, arg2);
361  EXPECT_EQ(result, arg1 / arg2);
362  }
363  }
364 }
365 
366 TEST(Binary, UnsignedDiv) {
367  FunctorOp functor = FunctorOp::UDIV;
368 
369  auto vecArg1 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);
370  auto vecArg2 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, and i.

Here is the call graph for this function:

◆ TEST() [12/66]

souffle::interpreter::test::TEST ( Binary  ,
SignedExp   
)

Definition at line 404 of file ram_arithmetic_test.cpp.

404  {
405  auto arg1 = vecArg1[i];
406  auto arg2 = vecArg2[i];
407  RamDomain result = evalBinary(functor, arg1, arg2);
408  EXPECT_EQ(result, static_cast<RamDomain>(std::pow(arg1, arg2)));
409  }
410 }
411 
412 TEST(Binary, UnsignedExp) {
413  FunctorOp functor = FunctorOp::UEXP;
414 
415  auto vecArg1 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);
416  auto vecArg2 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, and i.

Here is the call graph for this function:

◆ TEST() [13/66]

souffle::interpreter::test::TEST ( Binary  ,
SignedLogicalAnd   
)

Definition at line 559 of file ram_arithmetic_test.cpp.

559  {
560  auto arg1 = vecArg1[i];
561  auto arg2 = vecArg2[i];
562  RamDomain result = evalBinary(functor, arg1, arg2);
563  EXPECT_EQ(result, arg1 || arg2);
564  }
565 }
566 
567 TEST(Binary, UnsignedLogicalAnd) {
568  FunctorOp functor = FunctorOp::ULAND;
569 
570  auto vecArg1 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);
571  auto vecArg2 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, and i.

Here is the call graph for this function:

◆ TEST() [14/66]

souffle::interpreter::test::TEST ( Binary  ,
SignedLogicalOr   
)

Definition at line 587 of file ram_arithmetic_test.cpp.

587  {
588  auto arg1 = vecArg1[i];
589  auto arg2 = vecArg2[i];
590  RamDomain result = evalBinary(functor, arg1, arg2);
591  EXPECT_EQ(result, arg1 || arg2);
592  }
593 }
594 
595 TEST(Binary, UnsignedLogicalOr) {
596  FunctorOp functor = FunctorOp::ULOR;
597 
598  auto vecArg1 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);
599  auto vecArg2 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, and i.

Here is the call graph for this function:

◆ TEST() [15/66]

souffle::interpreter::test::TEST ( Binary  ,
SignedMod   
)

Definition at line 447 of file ram_arithmetic_test.cpp.

447  {
448  auto arg1 = vecArg1[i];
449  auto arg2 = vecArg2[i];
450  RamDomain result = evalBinary(functor, arg1, arg2);
451  EXPECT_EQ(result, arg1 % arg2);
452  }
453 }
454 
455 TEST(Binary, UnsignedMod) {
456  FunctorOp functor = FunctorOp::UMOD;
457 
458  auto vecArg1 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);
459  auto vecArg2 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, and i.

Here is the call graph for this function:

◆ TEST() [16/66]

souffle::interpreter::test::TEST ( Binary  ,
SignedMul   
)

Definition at line 314 of file ram_arithmetic_test.cpp.

314  {
315  auto arg1 = vecArg1[i];
316  auto arg2 = vecArg2[i];
317  RamDomain result = evalBinary(functor, arg1, arg2);
318  EXPECT_EQ(result, arg1 * arg2);
319  }
320 }
321 
322 TEST(Binary, UnsignedMul) {
323  FunctorOp functor = FunctorOp::UMUL;
324 
325  auto vecArg1 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);
326  auto vecArg2 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, and i.

Here is the call graph for this function:

◆ TEST() [17/66]

souffle::interpreter::test::TEST ( Binary  ,
SignedSub   
)

Definition at line 272 of file ram_arithmetic_test.cpp.

272  {
273  auto arg1 = vecArg1[i];
274  auto arg2 = vecArg2[i];
275  RamDomain result = evalBinary(functor, arg1, arg2);
276  EXPECT_EQ(result, arg1 - arg2);
277  }
278 }
279 
280 TEST(Binary, UnsignedSub) {
281  FunctorOp functor = FunctorOp::USUB;
282 
283  auto vecArg1 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);
284  auto vecArg2 = testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, and i.

Here is the call graph for this function:

◆ TEST() [18/66]

souffle::interpreter::test::TEST ( Binary  ,
UnsignedAdd   
)

Definition at line 244 of file ram_arithmetic_test.cpp.

244  {
245  RamUnsigned arg1 = vecArg1[i];
246  RamUnsigned arg2 = vecArg2[i];
247  RamDomain result = evalBinary(functor, ramBitCast(arg1), ramBitCast(arg2));
248  EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 + arg2);
249  }
250 }
251 
252 TEST(Binary, FloatAdd) {
253  FunctorOp functor = FunctorOp::FADD;
254 
255  auto vecArg1 = testutil::generateRandomVector<RamFloat>(TESTS_PER_OPERATION);
256  auto vecArg2 = testutil::generateRandomVector<RamFloat>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, i, and souffle::ramBitCast().

Here is the call graph for this function:

◆ TEST() [19/66]

souffle::interpreter::test::TEST ( Binary  ,
UnsignedBinaryAnd   
)

Definition at line 489 of file ram_arithmetic_test.cpp.

489  {
490  auto arg1 = vecArg1[i];
491  auto arg2 = vecArg2[i];
492  RamDomain result = evalBinary(functor, ramBitCast(arg1), ramBitCast(arg2));
493  EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 & arg2);
494  }
495 }
496 
497 TEST(Binary, SignedBinaryOr) {
498  FunctorOp functor = FunctorOp::BOR;
499 
500  auto vecArg1 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);
501  auto vecArg2 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, i, and souffle::ramBitCast().

Here is the call graph for this function:

◆ TEST() [20/66]

souffle::interpreter::test::TEST ( Binary  ,
UnsignedBinaryOr   
)

Definition at line 517 of file ram_arithmetic_test.cpp.

517  {
518  auto arg1 = vecArg1[i];
519  auto arg2 = vecArg2[i];
520  RamDomain result = evalBinary(functor, ramBitCast(arg1), ramBitCast(arg2));
521  EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 | arg2);
522  }
523 }
524 
525 TEST(Binary, SignedBinaryXor) {
526  FunctorOp functor = FunctorOp::BXOR;
527 
528  auto vecArg1 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);
529  auto vecArg2 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, i, and souffle::ramBitCast().

Here is the call graph for this function:

◆ TEST() [21/66]

souffle::interpreter::test::TEST ( Binary  ,
UnsignedBinaryXor   
)

Definition at line 545 of file ram_arithmetic_test.cpp.

545  {
546  auto arg1 = vecArg1[i];
547  auto arg2 = vecArg2[i];
548  RamDomain result = evalBinary(functor, ramBitCast(arg1), ramBitCast(arg2));
549  EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 ^ arg2);
550  }
551 }
552 
553 TEST(Binary, SignedLogicalAnd) {
554  FunctorOp functor = FunctorOp::LAND;
555 
556  auto vecArg1 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);
557  auto vecArg2 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, i, and souffle::ramBitCast().

Here is the call graph for this function:

◆ TEST() [22/66]

souffle::interpreter::test::TEST ( Binary  ,
UnsignedDiv   
)

Definition at line 372 of file ram_arithmetic_test.cpp.

372  {
373  auto arg1 = vecArg1[i];
374  auto arg2 = vecArg2[i];
375  if (arg2 != 0) {
376  RamDomain result = evalBinary(functor, ramBitCast(arg1), ramBitCast(arg2));
377  EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 / arg2);
378  }
379  }
380 }
381 
382 TEST(Binary, FloatDiv) {
383  FunctorOp functor = FunctorOp::FDIV;
384 
385  auto vecArg1 = testutil::generateRandomVector<RamFloat>(TESTS_PER_OPERATION);
386  auto vecArg2 = testutil::generateRandomVector<RamFloat>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, i, and souffle::ramBitCast().

Here is the call graph for this function:

◆ TEST() [23/66]

souffle::interpreter::test::TEST ( Binary  ,
UnsignedExp   
)

Definition at line 418 of file ram_arithmetic_test.cpp.

418  {
419  auto arg1 = vecArg1[i];
420  auto arg2 = vecArg2[i];
421  RamDomain result = evalBinary(functor, ramBitCast(arg1), ramBitCast(arg2));
422  EXPECT_EQ(ramBitCast<RamUnsigned>(result), static_cast<RamUnsigned>(std::pow(arg1, arg2)));
423  }
424 }
425 
426 TEST(Binary, FloatExp) {
427  FunctorOp functor = FunctorOp::FEXP;
428 
429  auto vecArg1 = testutil::generateRandomVector<RamFloat>(TESTS_PER_OPERATION);
430  auto vecArg2 = testutil::generateRandomVector<RamFloat>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, i, and souffle::ramBitCast().

Here is the call graph for this function:

◆ TEST() [24/66]

souffle::interpreter::test::TEST ( Binary  ,
UnsignedLogicalAnd   
)

Definition at line 573 of file ram_arithmetic_test.cpp.

573  {
574  auto arg1 = vecArg1[i];
575  auto arg2 = vecArg2[i];
576  RamDomain result = evalBinary(functor, ramBitCast(arg1), ramBitCast(arg2));
577  EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 || arg2);
578  }
579 }
580 
581 TEST(Binary, SignedLogicalOr) {
582  FunctorOp functor = FunctorOp::LOR;
583 
584  auto vecArg1 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);
585  auto vecArg2 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, i, and souffle::ramBitCast().

Here is the call graph for this function:

◆ TEST() [25/66]

souffle::interpreter::test::TEST ( Binary  ,
UnsignedLogicalOr   
)

Definition at line 601 of file ram_arithmetic_test.cpp.

601  {
602  auto arg1 = vecArg1[i];
603  auto arg2 = vecArg2[i];
604  RamDomain result = evalBinary(functor, ramBitCast(arg1), ramBitCast(arg2));
605  EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 || arg2);
606  }
607 }
608 
609 TEST(MultiArg, Max) {
610  FunctorOp functor = FunctorOp::MAX;
611  VecOwn<Expression> args;
612 
613  for (RamDomain i = 0; i <= 50; ++i) {

References evalBinary(), EXPECT_EQ, i, and souffle::ramBitCast().

Here is the call graph for this function:

◆ TEST() [26/66]

souffle::interpreter::test::TEST ( Binary  ,
UnsignedMod   
)

Definition at line 461 of file ram_arithmetic_test.cpp.

461  {
462  auto arg1 = vecArg1[i];
463  auto arg2 = vecArg2[i];
464  RamDomain result = evalBinary(functor, ramBitCast(arg1), ramBitCast(arg2));
465  EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 % arg2);
466  }
467 }
468 
469 TEST(Binary, SignedBinaryAnd) {
470  FunctorOp functor = FunctorOp::BAND;
471 
472  auto vecArg1 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);
473  auto vecArg2 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, i, and souffle::ramBitCast().

Here is the call graph for this function:

◆ TEST() [27/66]

souffle::interpreter::test::TEST ( Binary  ,
UnsignedMul   
)

Definition at line 328 of file ram_arithmetic_test.cpp.

328  {
329  auto arg1 = vecArg1[i];
330  auto arg2 = vecArg2[i];
331  RamDomain result = evalBinary(functor, ramBitCast(arg1), ramBitCast(arg2));
332  EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 * arg2);
333  }
334 }
335 
336 TEST(Binary, FloatMul) {
337  FunctorOp functor = FunctorOp::FMUL;
338 
339  auto vecArg1 = testutil::generateRandomVector<RamFloat>(TESTS_PER_OPERATION);
340  auto vecArg2 = testutil::generateRandomVector<RamFloat>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, i, and souffle::ramBitCast().

Here is the call graph for this function:

◆ TEST() [28/66]

souffle::interpreter::test::TEST ( Binary  ,
UnsignedSub   
)

Definition at line 286 of file ram_arithmetic_test.cpp.

286  {
287  auto arg1 = vecArg1[i];
288  auto arg2 = vecArg2[i];
289  RamDomain result = evalBinary(functor, ramBitCast(arg1), ramBitCast(arg2));
290  EXPECT_EQ(ramBitCast<RamUnsigned>(result), arg1 - arg2);
291  }
292 }
293 
294 TEST(Binary, FloatSub) {
295  FunctorOp functor = FunctorOp::FSUB;
296 
297  auto vecArg1 = testutil::generateRandomVector<RamFloat>(TESTS_PER_OPERATION);
298  auto vecArg2 = testutil::generateRandomVector<RamFloat>(TESTS_PER_OPERATION);

References evalBinary(), EXPECT_EQ, i, and souffle::ramBitCast().

Here is the call graph for this function:

◆ TEST() [29/66]

souffle::interpreter::test::TEST ( Independence  ,
Iteration   
)

Definition at line 121 of file interpreter_relation_test.cpp.

121  {"i"}, {"i"}, 0);
122 
123  // add a value
124  relInt.insert(tuple(&relInt, {1}));
125 
126  // Test a iterator returns the correct value
127  souffle::Relation::iterator it = relInt.begin();
128  EXPECT_EQ(1, (*it)[0]);
129 
130  // Copy the iterator and modify the copy
131  {
133  EXPECT_EQ(1, (*it2)[0]);
134  ++it2;
135  }
136  EXPECT_EQ(1, (*it)[0]);
137 
138  // Test that a new iterator is also valid
139  souffle::Relation::iterator it3 = relInt.begin();
140  EXPECT_EQ(1, (*it3)[0]);
141 }
142 
143 TEST(IndependentMoving, Iteration) {
144  // create a table
145  SymbolTable symbolTable;
146  MinIndexSelection order{};
147  order.insertDefaultTotalIndex(1);

◆ TEST() [30/66]

souffle::interpreter::test::TEST ( IndependentCopying  ,
Iteration   
)

Definition at line 172 of file interpreter_relation_test.cpp.

172  {"i"}, {"i"}, 0);
173 
174  // add a value
175  relInt.insert(tuple(&relInt, {1}));
176 
177  souffle::Relation::iterator it = relInt.begin();
178  EXPECT_EQ(1, (*it)[0]);
179 
180  // Make a new iterator, copy it to the first iterator, then let the new iterator go out of scope
181  {
182  souffle::Relation::iterator it2(relInt.begin());
183  EXPECT_EQ(1, (*it2)[0]);
184  it = it2;
185  }
186  EXPECT_EQ(1, (*it)[0]);
187 }
188 
189 TEST(Reordering, Iteration) {
190  // create a relation, with a non-default ordering.
191  SymbolTable symbolTable;
192 
193  // create an index of order {0, 2, 1}

◆ TEST() [31/66]

souffle::interpreter::test::TEST ( IndependentMoving  ,
Iteration   
)

Definition at line 149 of file interpreter_relation_test.cpp.

149  {"i"}, {"i"}, 0);
150 
151  // add a value
152  relInt.insert(tuple(&relInt, {1}));
153 
154  souffle::Relation::iterator it = relInt.begin();
155  EXPECT_EQ(1, (*it)[0]);
156 
157  // Make a new iterator, move it to the first iterator, then let the new iterator go out of scope
158  {
159  souffle::Relation::iterator it2(relInt.begin());
160  EXPECT_EQ(1, (*it2)[0]);
161  it = std::move(it2);
162  }
163  EXPECT_EQ(1, (*it)[0]);
164 }
165 
166 TEST(IndependentCopying, Iteration) {
167  // create a table
168  SymbolTable symbolTable;
169  MinIndexSelection order{};
170  order.insertDefaultTotalIndex(1);

◆ TEST() [32/66]

souffle::interpreter::test::TEST ( IO_load  ,
Float   
)

Definition at line 449 of file ram_relation_test.cpp.

452  {"a", "b"};
453  std::vector<std::string> attribsTypes = {"f", "f"};
454  Own<ram::Relation> myrel =
455  mk<ram::Relation>("test", 2, 0, attribs, attribsTypes, RelationRepresentation::BTREE);
456 
457  Json types = Json::object{
458  {"relation", Json::object{{"arity", static_cast<long long>(attribsTypes.size())},
459  {"auxArity", static_cast<long long>(0)},
460  {"types", Json::array(attribsTypes.begin(), attribsTypes.end())}}}};
461 
462  std::map<std::string, std::string> readDirs = {{"operation", "input"}, {"IO", "stdin"},
463  {"attributeNames", "x\ty"}, {"name", "test"}, {"types", types.dump()}};
464  std::map<std::string, std::string> readIoDirs = std::map<std::string, std::string>(readDirs);
465 
466  std::map<std::string, std::string> writeDirs = {{"operation", "output"}, {"IO", "stdout"},
467  {"attributeNames", "x\ty"}, {"name", "test"}, {"types", types.dump()}};
468  std::map<std::string, std::string> writeIoDirs = std::map<std::string, std::string>(writeDirs);
469 
470  Own<ram::Statement> main =
471  mk<ram::Sequence>(mk<ram::IO>("test", readIoDirs), mk<ram::IO>("test", writeIoDirs));
472 
473  rels.push_back(std::move(myrel));
474  std::map<std::string, Own<Statement>> subs;
475  Own<Program> prog = mk<Program>(std::move(rels), std::move(main), std::move(subs));
476 
477  SymbolTable symTab;
478  ErrorReport errReport;
479  DebugReport debugReport;
480 
481  TranslationUnit translationUnit(std::move(prog), symTab, errReport, debugReport);
482 
483  // configure and execute interpreter
484  Own<Engine> interpreter = mk<Engine>(translationUnit);
485 
486  std::streambuf* oldCoutStreambuf = std::cout.rdbuf();
487  std::ostringstream sout;
488  std::cout.rdbuf(sout.rdbuf());
489 
490  interpreter->executeMain();
491 
492  std::cout.rdbuf(oldCoutStreambuf);
493 
494  std::string expected = R"(---------------
495 test
496 ===============
497 0.5 0.5
498 ===============
499 )";
500  EXPECT_EQ(expected, sout.str());
501 
502  std::cin.rdbuf(backupCin);
503 }
504 
505 TEST(IO_load, Unsigned) {
506  std::streambuf* backupCin = std::cin.rdbuf();
507  std::istringstream testInput("6 6");
508  std::cin.rdbuf(testInput.rdbuf());
509 

◆ TEST() [33/66]

souffle::interpreter::test::TEST ( IO_load  ,
MixedTypesLoad   
)

Definition at line 573 of file ram_relation_test.cpp.

576  {"l", "u", "b", "a"};
577  std::vector<std::string> attribsTypes = {"s", "i", "u", "f"};
578  Own<ram::Relation> myrel =
579  mk<ram::Relation>("test", 4, 0, attribs, attribsTypes, RelationRepresentation::BTREE);
580 
581  Json types = Json::object{
582  {"relation", Json::object{{"arity", static_cast<long long>(attribsTypes.size())},
583  {"auxArity", static_cast<long long>(0)},
584  {"types", Json::array(attribsTypes.begin(), attribsTypes.end())}}}};
585 
586  std::map<std::string, std::string> readDirs = {{"operation", "input"}, {"IO", "stdin"},
587  {"attributeNames", "x\ty"}, {"name", "test"}, {"types", types.dump()}};
588  std::map<std::string, std::string> readIoDirs = std::map<std::string, std::string>(readDirs);
589 
590  std::map<std::string, std::string> writeDirs = {{"operation", "output"}, {"IO", "stdout"},
591  {"attributeNames", "x\ty"}, {"name", "test"}, {"types", types.dump()}};
592  std::map<std::string, std::string> writeIoDirs = std::map<std::string, std::string>(writeDirs);
593 
594  Own<ram::Statement> main =
595  mk<ram::Sequence>(mk<ram::IO>("test", readIoDirs), mk<ram::IO>("test", writeIoDirs));
596 
597  rels.push_back(std::move(myrel));
598  std::map<std::string, Own<Statement>> subs;
599  Own<Program> prog = mk<Program>(std::move(rels), std::move(main), std::move(subs));
600 
601  SymbolTable symTab;
602  ErrorReport errReport;
603  DebugReport debugReport;
604 
605  TranslationUnit translationUnit(std::move(prog), symTab, errReport, debugReport);
606 
607  // configure and execute interpreter
608  Own<Engine> interpreter = mk<Engine>(translationUnit);
609 
610  std::streambuf* oldCoutStreambuf = std::cout.rdbuf();
611  std::ostringstream sout;
612  std::cout.rdbuf(sout.rdbuf());
613 
614  interpreter->executeMain();
615 
616  std::cout.rdbuf(oldCoutStreambuf);
617 
618  std::string expected = R"(---------------
619 test
620 ===============
621 meow -3 3 0.5
622 ===============
623 )";
624 
625  EXPECT_EQ(expected, sout.str());
626 
627  std::cin.rdbuf(backupCin);
628 }
629 
630 } // namespace souffle::interpreter::test

◆ TEST() [34/66]

souffle::interpreter::test::TEST ( IO_load  ,
Signed   
)

Definition at line 387 of file ram_relation_test.cpp.

390  {"a", "b"};
391  std::vector<std::string> attribsTypes = {"i", "i"};
392  Own<ram::Relation> myrel =
393  mk<ram::Relation>("test", 2, 0, attribs, attribsTypes, RelationRepresentation::BTREE);
394 
395  Json types = Json::object{
396  {"relation", Json::object{{"arity", static_cast<long long>(attribsTypes.size())},
397  {"auxArity", static_cast<long long>(0)},
398  {"types", Json::array(attribsTypes.begin(), attribsTypes.end())}}}};
399 
400  std::map<std::string, std::string> readDirs = {{"operation", "input"}, {"IO", "stdin"},
401  {"attributeNames", "x\ty"}, {"name", "test"}, {"types", types.dump()}};
402  std::map<std::string, std::string> readIoDirs = std::map<std::string, std::string>(readDirs);
403 
404  std::map<std::string, std::string> writeDirs = {{"operation", "output"}, {"IO", "stdout"},
405  {"attributeNames", "x\ty"}, {"name", "test"}, {"types", types.dump()}};
406  std::map<std::string, std::string> writeIoDirs = std::map<std::string, std::string>(writeDirs);
407 
408  Own<ram::Statement> main =
409  mk<ram::Sequence>(mk<ram::IO>("test", readIoDirs), mk<ram::IO>("test", writeIoDirs));
410 
411  rels.push_back(std::move(myrel));
412  std::map<std::string, Own<Statement>> subs;
413  Own<Program> prog = mk<Program>(std::move(rels), std::move(main), std::move(subs));
414 
415  SymbolTable symTab;
416  ErrorReport errReport;
417  DebugReport debugReport;
418 
419  TranslationUnit translationUnit(std::move(prog), symTab, errReport, debugReport);
420 
421  // configure and execute interpreter
422  Own<Engine> interpreter = mk<Engine>(translationUnit);
423 
424  std::streambuf* oldCoutStreambuf = std::cout.rdbuf();
425  std::ostringstream sout;
426  std::cout.rdbuf(sout.rdbuf());
427 
428  interpreter->executeMain();
429 
430  std::cout.rdbuf(oldCoutStreambuf);
431 
432  std::string expected = R"(---------------
433 test
434 ===============
435 5 3
436 ===============
437 )";
438  EXPECT_EQ(expected, sout.str());
439 
440  std::cin.rdbuf(backupCin);
441 }
442 
443 TEST(IO_load, Float) {
444  std::streambuf* backupCin = std::cin.rdbuf();
445  std::istringstream testInput("0.5 0.5");
446  std::cin.rdbuf(testInput.rdbuf());
447 

◆ TEST() [35/66]

souffle::interpreter::test::TEST ( IO_load  ,
Unsigned   
)

Definition at line 511 of file ram_relation_test.cpp.

514  {"a", "b"};
515  std::vector<std::string> attribsTypes = {"u", "u"};
516  Own<ram::Relation> myrel =
517  mk<ram::Relation>("test", 2, 0, attribs, attribsTypes, RelationRepresentation::BTREE);
518 
519  Json types = Json::object{
520  {"relation", Json::object{{"arity", static_cast<long long>(attribsTypes.size())},
521  {"auxArity", static_cast<long long>(0)},
522  {"types", Json::array(attribsTypes.begin(), attribsTypes.end())}}}};
523 
524  std::map<std::string, std::string> readDirs = {{"operation", "input"}, {"IO", "stdin"},
525  {"attributeNames", "x\ty"}, {"name", "test"}, {"types", types.dump()}};
526  std::map<std::string, std::string> readIoDirs = std::map<std::string, std::string>(readDirs);
527 
528  std::map<std::string, std::string> writeDirs = {{"operation", "output"}, {"IO", "stdout"},
529  {"attributeNames", "x\ty"}, {"name", "test"}, {"types", types.dump()}};
530  std::map<std::string, std::string> writeIoDirs = std::map<std::string, std::string>(writeDirs);
531 
532  Own<ram::Statement> main =
533  mk<ram::Sequence>(mk<ram::IO>("test", readIoDirs), mk<ram::IO>("test", writeIoDirs));
534 
535  rels.push_back(std::move(myrel));
536  std::map<std::string, Own<Statement>> subs;
537  Own<Program> prog = mk<Program>(std::move(rels), std::move(main), std::move(subs));
538 
539  SymbolTable symTab;
540  ErrorReport errReport;
541  DebugReport debugReport;
542 
543  TranslationUnit translationUnit(std::move(prog), symTab, errReport, debugReport);
544 
545  // configure and execute interpreter
546  Own<Engine> interpreter = mk<Engine>(translationUnit);
547 
548  std::streambuf* oldCoutStreambuf = std::cout.rdbuf();
549  std::ostringstream sout;
550  std::cout.rdbuf(sout.rdbuf());
551 
552  interpreter->executeMain();
553 
554  std::cout.rdbuf(oldCoutStreambuf);
555 
556  std::string expected = R"(---------------
557 test
558 ===============
559 6 6
560 ===============
561 )";
562  EXPECT_EQ(expected, sout.str());
563 
564  std::cin.rdbuf(backupCin);
565 }
566 
567 TEST(IO_load, MixedTypesLoad) {
568  std::streambuf* backupCin = std::cin.rdbuf();
569  std::istringstream testInput("meow -3 3 0.5");
570  std::cin.rdbuf(testInput.rdbuf());
571 

◆ TEST() [36/66]

souffle::interpreter::test::TEST ( IO_store  ,
Float   
)

Definition at line 165 of file ram_relation_test.cpp.

171  : randomNumbers) {
172  exprs.push_back(mk<SignedConstant>(ramBitCast(f)));
173  }
174 
175  std::stringstream expected;
176  expected << std::setprecision(std::numeric_limits<RamFloat>::max_digits10);
177 
178  expected << "---------------"
179  << "\n"
180  << "test"
181  << "\n"
182  << "==============="
183  << "\n"
184  << randomNumbers[0];
185 
186  for (size_t i = 1; i < randomNumbers.size(); ++i) {
187  expected << "\t" << randomNumbers[i];
188  }
189  expected << "\n"
190  << "==============="
191  << "\n";
192 
193  auto result = testInterpreterStore(attribs, attribsTypes, std::move(exprs));
194  EXPECT_EQ(expected.str(), result);
195 }
196 
197 TEST(IO_store, Unsigned) {
198  std::vector<RamUnsigned> randomNumbers = testutil::generateRandomVector<RamUnsigned>(RANDOM_TESTS);
199 
200  // a0 a1 a2...
201  std::vector<std::string> attribs(RANDOM_TESTS, "a");

◆ TEST() [37/66]

souffle::interpreter::test::TEST ( IO_store  ,
FloatSimple   
)

Definition at line 110 of file ram_relation_test.cpp.

123  {
124  std::vector<RamDomain> randomNumbers = testutil::generateRandomVector<RamDomain>(RANDOM_TESTS);
125 
126  // a0 a1 a2...
127  std::vector<std::string> attribs(RANDOM_TESTS, "a");

◆ TEST() [38/66]

souffle::interpreter::test::TEST ( IO_store  ,
MixedTypes   
)

Definition at line 317 of file ram_relation_test.cpp.

318  {"i", "u", "f", "f", "s"};
319 
320  Own<ram::Relation> myrel =
321  mk<ram::Relation>("test", 5, 0, attribs, attribsTypes, RelationRepresentation::BTREE);
322 
323  Json types = Json::object{
324  {"relation", Json::object{{"arity", static_cast<long long>(attribsTypes.size())},
325  {"auxArity", static_cast<long long>(0)},
326  {"types", Json::array(attribsTypes.begin(), attribsTypes.end())}}}};
327 
328  std::map<std::string, std::string> dirs = {{"operation", "output"}, {"IO", "stdout"},
329  {"attributeNames", "x\ty"}, {"name", "test"}, {"types", types.dump()}};
330  std::map<std::string, std::string> ioDirs = std::map<std::string, std::string>(dirs);
331 
332  SymbolTable symbolTable;
333  ErrorReport errReport;
334  DebugReport debugReport;
335 
336  VecOwn<Expression> exprs;
337  RamFloat floatValue = 27.75;
338  exprs.push_back(mk<SignedConstant>(3));
339  exprs.push_back(mk<SignedConstant>(ramBitCast(static_cast<RamUnsigned>(27))));
340  exprs.push_back(mk<SignedConstant>(ramBitCast(static_cast<RamFloat>(floatValue))));
341  exprs.push_back(mk<SignedConstant>(ramBitCast(static_cast<RamFloat>(floatValue))));
342  exprs.push_back(mk<SignedConstant>(symbolTable.lookup("meow")));
343 
344  Own<ram::Statement> main = mk<ram::Sequence>(
345  mk<ram::Query>(mk<ram::Project>("test", std::move(exprs))), mk<ram::IO>("test", ioDirs));
346 
347  rels.push_back(std::move(myrel));
348  std::map<std::string, Own<Statement>> subs;
349  Own<Program> prog = mk<Program>(std::move(rels), std::move(main), std::move(subs));
350 
351  TranslationUnit translationUnit(std::move(prog), symbolTable, errReport, debugReport);
352 
353  // configure and execute interpreter
354  Own<Engine> interpreter = mk<Engine>(translationUnit);
355 
356  std::streambuf* oldCoutStreambuf = std::cout.rdbuf();
357  std::ostringstream sout;
358  std::cout.rdbuf(sout.rdbuf());
359 
360  interpreter->executeMain();
361 
362  std::cout.rdbuf(oldCoutStreambuf);
363 
364  std::stringstream expected;
365  expected << std::setprecision(std::numeric_limits<RamFloat>::max_digits10);
366  expected << "---------------"
367  << "\n"
368  << "test"
369  << "\n"
370  << "==============="
371  << "\n"
372  << 3 << "\t" << 27 << "\t" << floatValue << "\t" << floatValue << "\t"
373  << "meow"
374  << "\n"
375  << "==============="
376  << "\n";
377 
378  EXPECT_EQ(expected.str(), sout.str());
379 }
380 
381 TEST(IO_load, Signed) {
382  std::streambuf* backupCin = std::cin.rdbuf();
383  std::istringstream testInput("5 3");
384  std::cin.rdbuf(testInput.rdbuf());
385 

◆ TEST() [39/66]

souffle::interpreter::test::TEST ( IO_store  ,
Signed   
)

Definition at line 129 of file ram_relation_test.cpp.

135  : randomNumbers) {
136  exprs.push_back(mk<SignedConstant>(i));
137  }
138 
139  std::stringstream expected;
140  expected << "---------------"
141  << "\n"
142  << "test"
143  << "\n"
144  << "==============="
145  << "\n"
146  << randomNumbers[0];
147 
148  for (size_t i = 1; i < randomNumbers.size(); ++i) {
149  expected << "\t" << randomNumbers[i];
150  }
151  expected << "\n"
152  << "==============="
153  << "\n";
154 
155  auto result = testInterpreterStore(attribs, attribsTypes, std::move(exprs));
156  EXPECT_EQ(expected.str(), result);
157 }
158 
159 TEST(IO_store, Float) {
160  std::vector<RamFloat> randomNumbers = testutil::generateRandomVector<RamFloat>(RANDOM_TESTS);
161 
162  // a0 a1 a2...
163  std::vector<std::string> attribs(RANDOM_TESTS, "a");

◆ TEST() [40/66]

souffle::interpreter::test::TEST ( IO_store  ,
SignedChangedDelimiter   
)

Definition at line 240 of file ram_relation_test.cpp.

244  {
245  attribs[i].append(std::to_string(i));
246  }
247 
248  std::vector<std::string> attribsTypes(RANDOM_TESTS, "i");
249 
250  Own<ram::Relation> myrel =
251  mk<ram::Relation>("test", RANDOM_TESTS, 0, attribs, attribsTypes, RelationRepresentation::BTREE);
252 
253  Json types = Json::object{
254  {"relation", Json::object{{"arity", static_cast<long long>(attribsTypes.size())},
255  {"auxArity", static_cast<long long>(0)},
256  {"types", Json::array(attribsTypes.begin(), attribsTypes.end())}}}};
257 
258  std::map<std::string, std::string> dirs = {{"operation", "output"}, {"IO", "stdout"},
259  {"attributeNames", "x\ty"}, {"name", "test"}, {"delimiter", delimiter}, {"types", types.dump()}};
260 
261  std::map<std::string, std::string> ioDirs = std::map<std::string, std::string>(dirs);
262 
263  VecOwn<Expression> exprs;
264  for (RamDomain i : randomNumbers) {
265  exprs.push_back(mk<SignedConstant>(i));
266  }
267 
268  Own<ram::Statement> main = mk<ram::Sequence>(
269  mk<ram::Query>(mk<ram::Project>("test", std::move(exprs))), mk<ram::IO>("test", ioDirs));
270 
271  rels.push_back(std::move(myrel));
272  std::map<std::string, Own<Statement>> subs;
273  Own<Program> prog = mk<Program>(std::move(rels), std::move(main), std::move(subs));
274 
275  SymbolTable symTab;
276  ErrorReport errReport;
277  DebugReport debugReport;
278 
279  TranslationUnit translationUnit(std::move(prog), symTab, errReport, debugReport);
280 
281  // configure and execute interpreter
282  Own<Engine> interpreter = mk<Engine>(translationUnit);
283 
284  std::streambuf* oldCoutStreambuf = std::cout.rdbuf();
285  std::ostringstream sout;
286  std::cout.rdbuf(sout.rdbuf());
287 
288  interpreter->executeMain();
289 
290  std::cout.rdbuf(oldCoutStreambuf);
291 
292  std::stringstream expected;
293  expected << "---------------"
294  << "\n"
295  << "test"
296  << "\n"
297  << "==============="
298  << "\n"
299  << randomNumbers[0];
300 
301  for (size_t i = 1; i < randomNumbers.size(); ++i) {
302  expected << delimiter << randomNumbers[i];
303  }
304  expected << "\n"
305  << "==============="
306  << "\n";
307 
308  EXPECT_EQ(expected.str(), sout.str());
309 }
310 
311 TEST(IO_store, MixedTypes) {
312  Global::config().set("jobs", "1");
313 
314  VecOwn<ram::Relation> rels;
315 

◆ TEST() [41/66]

souffle::interpreter::test::TEST ( IO_store  ,
Unsigned   
)

Definition at line 203 of file ram_relation_test.cpp.

209  : randomNumbers) {
210  exprs.push_back(mk<SignedConstant>(ramBitCast(u)));
211  }
212 
213  std::stringstream expected;
214  expected << "---------------"
215  << "\n"
216  << "test"
217  << "\n"
218  << "==============="
219  << "\n"
220  << randomNumbers[0];
221 
222  for (size_t i = 1; i < randomNumbers.size(); ++i) {
223  expected << "\t" << randomNumbers[i];
224  }
225  expected << "\n"
226  << "==============="
227  << "\n";
228 
229  auto result = testInterpreterStore(attribs, attribsTypes, std::move(exprs));
230  EXPECT_EQ(expected.str(), result);
231 }
232 
233 // Test (store) with different delimiter
234 TEST(IO_store, SignedChangedDelimiter) {
235  std::vector<RamDomain> randomNumbers = testutil::generateRandomVector<RamDomain>(RANDOM_TESTS);
236  const std::string delimiter{", "};
237 

◆ TEST() [42/66]

souffle::interpreter::test::TEST ( MultiArg  ,
FloatMax   
)

Definition at line 641 of file ram_arithmetic_test.cpp.

648  {
649  FunctorOp functor = FunctorOp::SMAX;
650  VecOwn<Expression> args;
651 
652  SymbolTable symTab;

◆ TEST() [43/66]

souffle::interpreter::test::TEST ( MultiArg  ,
FloatMin   
)

Definition at line 695 of file ram_arithmetic_test.cpp.

702  {
703  FunctorOp functor = FunctorOp::SMIN;
704  VecOwn<Expression> args;
705 
706  SymbolTable symTab;

◆ TEST() [44/66]

souffle::interpreter::test::TEST ( MultiArg  ,
Max   
)

Definition at line 615 of file ram_arithmetic_test.cpp.

622  {
623  FunctorOp functor = FunctorOp::UMAX;
624  VecOwn<Expression> args;
625 
626  for (RamUnsigned i = 0; i <= 100; ++i) {

◆ TEST() [45/66]

souffle::interpreter::test::TEST ( MultiArg  ,
Min   
)

Definition at line 669 of file ram_arithmetic_test.cpp.

676  {
677  FunctorOp functor = FunctorOp::UMIN;
678  VecOwn<Expression> args;
679 
680  for (RamUnsigned i = 0; i <= 100; ++i) {

◆ TEST() [46/66]

souffle::interpreter::test::TEST ( MultiArg  ,
SymbolMax   
)

Definition at line 654 of file ram_arithmetic_test.cpp.

654  {
655  args.push_back(mk<SignedConstant>(symTab.lookup(std::to_string(i))));
656  }
657 
658  auto&& result = symTab.resolve(evalMultiArg(functor, std::move(args), symTab));
659 
660  EXPECT_EQ(result, "99");
661 }
662 
663 TEST(MultiArg, Min) {
664  FunctorOp functor = FunctorOp::MIN;
665  VecOwn<Expression> args;
666 
667  for (RamDomain i = 0; i <= 50; ++i) {

References i, and souffle::SymbolTable::lookup().

Here is the call graph for this function:

◆ TEST() [47/66]

souffle::interpreter::test::TEST ( MultiArg  ,
SymbolMin   
)

Definition at line 708 of file ram_arithmetic_test.cpp.

708  {
709  args.push_back(mk<SignedConstant>(symTab.lookup(std::to_string(i))));
710  }
711 
712  auto&& result = symTab.resolve(evalMultiArg(functor, std::move(args), symTab));
713 
714  EXPECT_EQ(result, "-1");
715 }
716 
717 } // namespace souffle::interpreter::test

References i, and souffle::SymbolTable::lookup().

Here is the call graph for this function:

◆ TEST() [48/66]

souffle::interpreter::test::TEST ( MultiArg  ,
UnsignedMax   
)

Definition at line 628 of file ram_arithmetic_test.cpp.

635  {
636  FunctorOp functor = FunctorOp::FMAX;
637  VecOwn<Expression> args;
638 
639  for (RamDomain i = -100; i <= 100; ++i) {

◆ TEST() [49/66]

souffle::interpreter::test::TEST ( MultiArg  ,
UnsignedMin   
)

Definition at line 682 of file ram_arithmetic_test.cpp.

689  {
690  FunctorOp functor = FunctorOp::FMIN;
691  VecOwn<Expression> args;
692 
693  for (RamDomain i = -100; i <= 100; ++i) {

◆ TEST() [50/66]

souffle::interpreter::test::TEST ( Relation0  ,
Construction   
)

Definition at line 38 of file interpreter_relation_test.cpp.

48  {
49  // create a nullary relation
50  SymbolTable symbolTable;
51  MinIndexSelection order{};
52  order.insertDefaultTotalIndex(0);

◆ TEST() [51/66]

souffle::interpreter::test::TEST ( Relation0  ,
Iteration   
)

Definition at line 54 of file interpreter_relation_test.cpp.

67  {
68  // create a single attribute relation
69  SymbolTable symbolTable;
70  MinIndexSelection order{};
71  order.insertDefaultTotalIndex(1);

◆ TEST() [52/66]

souffle::interpreter::test::TEST ( Relation1  ,
Construction   
)

Definition at line 73 of file interpreter_relation_test.cpp.

73  {"i"}, {"i"}, 0);
74 
75  tuple d1(&relInt, {1});
76  // add some values
77  EXPECT_EQ(0, rel.size());
78  relInt.insert(d1);
79  EXPECT_EQ(1, rel.size());
80  relInt.insert(tuple(&relInt, {2}));
81  EXPECT_EQ(2, rel.size());
82  relInt.insert(tuple(&relInt, {3}));
83  EXPECT_EQ(3, rel.size());
84  relInt.insert(tuple(&relInt, {4}));
85  EXPECT_EQ(4, rel.size());
86 }
87 
88 TEST(Basic, Iteration) {
89  // create a relation
90  SymbolTable symbolTable;
91  MinIndexSelection order{};
92  order.insertDefaultTotalIndex(1);

◆ TEST() [53/66]

souffle::interpreter::test::TEST ( Reordering  ,
Iteration   
)

Definition at line 195 of file interpreter_relation_test.cpp.

203  {0, 1, 2};
204  rel.insert(tuple);
205 
206  // Scan should give undecoded tuple.
207  {
208  const auto& t = *(rel.scan().begin());
210  }
211 
212  // For-each should give decoded tuple.
213  {
214  auto t = rel.begin();
215  EXPECT_EQ(0, (*t)[0]);
216  EXPECT_EQ(1, (*t)[1]);
217  EXPECT_EQ(2, (*t)[2]);
218  }
219 
220  RelInterface relInt(rel, symbolTable, "test", {"i", "i", "i"}, {"i", "i", "i"}, 3);
221 
222  // ProgInterface should give decoded tuple.
223  {
224  const auto it = relInt.begin();
225  EXPECT_EQ(0, (*it)[0]);
226  EXPECT_EQ(1, (*it)[1]);
227  EXPECT_EQ(2, (*it)[2]);
228  }
229 }
230 
231 } // namespace souffle::interpreter::test

◆ TEST() [54/66]

souffle::interpreter::test::TEST ( SignedConstant  ,
ArithmeticEvaluation   
)

Definition at line 120 of file ram_arithmetic_test.cpp.

121  {
122  for (RamDomain randomNumber : testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION)) {
123  EXPECT_EQ(evalUnary(FunctorOp::NEG, randomNumber), -randomNumber);
124  }
125 }

References evalUnary(), EXPECT_EQ, souffle::NEG, and TESTS_PER_OPERATION.

Here is the call graph for this function:

◆ TEST() [55/66]

souffle::interpreter::test::TEST ( Unary  ,
BinaryNot   
)

Definition at line 142 of file ram_arithmetic_test.cpp.

144  {
145  FunctorOp functor = FunctorOp::UBNOT;
146 
147  for (auto randomNumber : testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION)) {
148  RamDomain result = evalUnary(functor, ramBitCast(randomNumber));

◆ TEST() [56/66]

souffle::interpreter::test::TEST ( Unary  ,
FloatNeg   
)

Definition at line 133 of file ram_arithmetic_test.cpp.

136  {
137  FunctorOp functor = FunctorOp::BNOT;
138 
139  for (auto randomNumber : testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION)) {
140  EXPECT_EQ(evalUnary(functor, randomNumber), ~randomNumber);

◆ TEST() [57/66]

souffle::interpreter::test::TEST ( Unary  ,
FloatToSigned   
)

Definition at line 203 of file ram_arithmetic_test.cpp.

206  {
207  FunctorOp functor = FunctorOp::U2F;
208 
209  for (auto randomNumber : testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION)) {
210  RamDomain result = evalUnary(functor, ramBitCast(randomNumber));

◆ TEST() [58/66]

souffle::interpreter::test::TEST ( Unary  ,
FloatToUnsigned   
)

Definition at line 221 of file ram_arithmetic_test.cpp.

224  {
225  FunctorOp functor = FunctorOp::ADD;
226 
227  auto vecArg1 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);
228  auto vecArg2 = testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION);

◆ TEST() [59/66]

souffle::interpreter::test::TEST ( Unary  ,
LogicalNeg   
)

Definition at line 159 of file ram_arithmetic_test.cpp.

161  {
162  FunctorOp functor = FunctorOp::ULNOT;
163 
164  for (auto randomNumber : testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION)) {
165  RamDomain result = evalUnary(functor, ramBitCast(randomNumber));

◆ TEST() [60/66]

souffle::interpreter::test::TEST ( Unary  ,
Neg   
)

Definition at line 127 of file ram_arithmetic_test.cpp.

127  {
128  FunctorOp functor = FunctorOp::FNEG;
129 
130  for (auto randomNumber : testutil::generateRandomVector<RamFloat>(TESTS_PER_OPERATION)) {
131  auto result = evalUnary(functor, ramBitCast(randomNumber));

References evalUnary(), EXPECT_EQ, souffle::FNEG, souffle::ramBitCast(), and TESTS_PER_OPERATION.

Here is the call graph for this function:

◆ TEST() [61/66]

souffle::interpreter::test::TEST ( Unary  ,
SignedToFloat   
)

Definition at line 194 of file ram_arithmetic_test.cpp.

197  {
198  FunctorOp functor = FunctorOp::F2I;
199 
200  for (auto randomNumber : testutil::generateRandomVector<RamFloat>(TESTS_PER_OPERATION)) {
201  RamDomain result = evalUnary(functor, ramBitCast(randomNumber));

◆ TEST() [62/66]

souffle::interpreter::test::TEST ( Unary  ,
SingedTpUnsigned   
)

Definition at line 176 of file ram_arithmetic_test.cpp.

179  {
180  FunctorOp functor = FunctorOp::U2I;
181 
182  for (auto randomNumber : testutil::generateRandomVector<RamUnsigned>(TESTS_PER_OPERATION)) {
183  RamDomain result = evalUnary(functor, ramBitCast(randomNumber));

◆ TEST() [63/66]

souffle::interpreter::test::TEST ( Unary  ,
UnsignedBinaryNot   
)

Definition at line 150 of file ram_arithmetic_test.cpp.

153  {
154  FunctorOp functor = FunctorOp::LNOT;
155 
156  for (auto randomNumber : testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION)) {
157  EXPECT_EQ(evalUnary(functor, randomNumber), !randomNumber);

◆ TEST() [64/66]

souffle::interpreter::test::TEST ( Unary  ,
UnsignedLogicalNeg   
)

Definition at line 167 of file ram_arithmetic_test.cpp.

170  {
171  FunctorOp functor = FunctorOp::I2U;
172 
173  for (auto randomNumber : testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION)) {
174  RamDomain result = evalUnary(functor, randomNumber);

◆ TEST() [65/66]

souffle::interpreter::test::TEST ( Unary  ,
UnsignedToFloat   
)

Definition at line 212 of file ram_arithmetic_test.cpp.

215  {
216  FunctorOp functor = FunctorOp::F2U;
217 
218  for (auto randomNumber : testutil::generateRandomVector<RamFloat>(TESTS_PER_OPERATION)) {
219  RamDomain result = evalUnary(functor, ramBitCast(randomNumber));

◆ TEST() [66/66]

souffle::interpreter::test::TEST ( Unary  ,
UnsignedToSigned   
)

Definition at line 185 of file ram_arithmetic_test.cpp.

188  {
189  FunctorOp functor = FunctorOp::I2F;
190 
191  for (auto randomNumber : testutil::generateRandomVector<RamDomain>(TESTS_PER_OPERATION)) {
192  RamDomain result = evalUnary(functor, ramBitCast(randomNumber));

◆ testInterpreterStore()

const std::string souffle::interpreter::test::testInterpreterStore ( std::vector< std::string >  attribs,
std::vector< std::string >  attribsTypes,
VecOwn< Expression exprs 
)

Definition at line 64 of file ram_relation_test.cpp.

68  {{"relation",
69  Json::object{{"arity", static_cast<long long>(arity)}, {"auxArity", static_cast<long long>(0)},
70  {"types", Json::array(attribsTypes.begin(), attribsTypes.end())}}}};
71 
72  std::map<std::string, std::string> dirs = {{"operation", "output"}, {"IO", "stdout"},
73  {"attributeNames", "x\ty"}, {"name", "test"}, {"types", types.dump()}};
74 
75  std::map<std::string, std::string> ioDirs = std::map<std::string, std::string>(dirs);
76 
77  Own<ram::Statement> main = mk<ram::Sequence>(
78  mk<ram::Query>(mk<ram::Project>("test", std::move(exprs))), mk<ram::IO>("test", ioDirs));
79 
80  rels.push_back(std::move(myrel));
81  std::map<std::string, Own<Statement>> subs;
82  Own<ram::Program> prog = mk<Program>(std::move(rels), std::move(main), std::move(subs));
83 
84  SymbolTable symTab;
85  ErrorReport errReport;
86  DebugReport debugReport;
87 
88  TranslationUnit translationUnit(std::move(prog), symTab, errReport, debugReport);
89 
90  // configure and execute interpreter
91  Own<Engine> interpreter = mk<Engine>(translationUnit);
92 
93  std::streambuf* oldCoutStreambuf = std::cout.rdbuf();
94  std::ostringstream sout;
95  std::cout.rdbuf(sout.rdbuf());
96 
97  interpreter->executeMain();
98 
99  std::cout.rdbuf(oldCoutStreambuf);
100 
101  return sout.str();
102 }
103 
104 TEST(IO_store, FloatSimple) {
105  std::vector<std::string> attribs = {"a", "b"};
106  std::vector<std::string> attribsTypes = {"f", "f"};
107 
108  VecOwn<Expression> exprs;
souffle::RamUnsigned
uint32_t RamUnsigned
Definition: RamTypes.h:58
souffle::Relation::iterator
Wrapper class for abstract iterator.
Definition: SouffleInterface.h:158
EXPECT_TRUE
#define EXPECT_TRUE(a)
Definition: test.h:189
souffle::interpreter::test::testInterpreterStore
const std::string testInterpreterStore(std::vector< std::string > attribs, std::vector< std::string > attribsTypes, VecOwn< Expression > exprs)
Definition: ram_relation_test.cpp:64
souffle::RamDomain
int32_t RamDomain
Definition: RamTypes.h:56
souffle::interpreter::test::TEST
TEST(MultiArg, SymbolMin)
Definition: ram_arithmetic_test.cpp:708
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: test.h:191
souffle::RamFloat
float RamFloat
Definition: RamTypes.h:60
types
std::vector< Own< ast::Type > > types
Definition: ComponentInstantiation.cpp:64
RANDOM_TESTS
#define RANDOM_TESTS
Definition: ram_relation_test.cpp:62
TESTS_PER_OPERATION
#define TESTS_PER_OPERATION
Definition: ram_arithmetic_test.cpp:56
souffle::interpreter::test::evalExpression
RamDomain evalExpression(Own< Expression > expression)
Function to evaluate a single Expression.
Definition: ram_arithmetic_test.cpp:89
souffle::interpreter::test::evalMultiArg
RamDomain evalMultiArg(FunctorOp functor, VecOwn< Expression > args)
Definition: ram_arithmetic_test.cpp:98
i
size_t i
Definition: json11.h:663
souffle::interpreter::test::TEST
TEST(Reordering, Iteration)
Definition: interpreter_relation_test.cpp:195
souffle::main
int main(int argc, char **argv)
Definition: main.cpp:191
souffle::test::count
int count(const C &c)
Definition: table_test.cpp:40
souffle::Tuple
std::array< A, N > Tuple
Definition: RamTypes.h:36
souffle::FunctorOp
FunctorOp
Definition: FunctorOps.h:35
souffle::interpreter::test::TEST
TEST(IO_load, MixedTypesLoad)
Definition: ram_relation_test.cpp:573
souffle::interpreter::test::evalBinary
RamDomain evalBinary(FunctorOp functor, RamDomain arg1, RamDomain arg2)
Evaluate a binary operator.
Definition: ram_arithmetic_test.cpp:112
souffle::ramBitCast
To ramBitCast(From source)
In C++20 there will be a new way to cast between types by reinterpreting bits (std::bit_cast),...
Definition: RamTypes.h:87
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086
souffle::interpreter::test::evalUnary
RamDomain evalUnary(FunctorOp functor, RamDomain arg1)
Evaluate a single argument expression.
Definition: ram_arithmetic_test.cpp:104