56 #define RANDOM_TESTS 12
59 std::vector<std::string> attribs, std::vector<std::string> attribsTypes, VecOwn<Expression> exprs) {
62 const size_t arity = attribs.size();
69 Json::object{{
"arity",
static_cast<long long>(arity)}, {
"auxArity",
static_cast<long long>(0)},
70 {
"types",
Json::array(attribsTypes.begin(), attribsTypes.end())}}}};
72 std::map<std::string, std::string> dirs = {{
"operation",
"output"}, {
"IO",
"stdout"},
73 {
"attributeNames",
"x\ty"}, {
"name",
"test"}, {
"types",
types.dump()}};
75 std::map<std::string, std::string> ioDirs = std::map<std::string, std::string>(dirs);
77 Own<ram::Statement>
main = mk<ram::Sequence>(
78 mk<ram::Query>(mk<ram::Project>(
"test", std::move(exprs))), mk<ram::IO>(
"test", ioDirs));
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));
85 ErrorReport errReport;
86 DebugReport debugReport;
88 TranslationUnit translationUnit(std::move(prog), symTab, errReport, debugReport);
91 Own<Engine> interpreter = mk<Engine>(translationUnit);
93 std::streambuf* oldCoutStreambuf = std::cout.rdbuf();
94 std::ostringstream sout;
95 std::cout.rdbuf(sout.rdbuf());
97 interpreter->executeMain();
99 std::cout.rdbuf(oldCoutStreambuf);
104 TEST(IO_store, FloatSimple) {
105 std::vector<std::string> attribs = {
"a",
"b"};
106 std::vector<std::string> attribsTypes = {
"f",
"f"};
108 VecOwn<Expression> exprs;
112 std::string expected = R
"(---------------
123 TEST(IO_store, Signed) {
124 std::vector<RamDomain> randomNumbers = testutil::generateRandomVector<RamDomain>(
RANDOM_TESTS);
129 attribs[
i].append(std::to_string(
i));
132 std::vector<std::string> attribsTypes(
RANDOM_TESTS,
"i");
136 exprs.push_back(mk<SignedConstant>(
i));
139 std::stringstream expected;
140 expected <<
"---------------"
148 for (
size_t i = 1;
i < randomNumbers.size(); ++
i) {
149 expected <<
"\t" << randomNumbers[
i];
159 TEST(IO_store, Float) {
160 std::vector<RamFloat> randomNumbers = testutil::generateRandomVector<RamFloat>(
RANDOM_TESTS);
165 attribs[
i].append(std::to_string(
i));
168 std::vector<std::string> attribsTypes(
RANDOM_TESTS,
"f");
172 exprs.push_back(mk<SignedConstant>(
ramBitCast(f)));
175 std::stringstream expected;
176 expected << std::setprecision(std::numeric_limits<RamFloat>::max_digits10);
178 expected <<
"---------------"
186 for (
size_t i = 1;
i < randomNumbers.size(); ++
i) {
187 expected <<
"\t" << randomNumbers[
i];
197 TEST(IO_store, Unsigned) {
198 std::vector<RamUnsigned> randomNumbers = testutil::generateRandomVector<RamUnsigned>(
RANDOM_TESTS);
203 attribs[
i].append(std::to_string(
i));
206 std::vector<std::string> attribsTypes(
RANDOM_TESTS,
"u");
210 exprs.push_back(mk<SignedConstant>(
ramBitCast(u)));
213 std::stringstream expected;
214 expected <<
"---------------"
222 for (
size_t i = 1;
i < randomNumbers.size(); ++
i) {
223 expected <<
"\t" << randomNumbers[
i];
234 TEST(IO_store, SignedChangedDelimiter) {
235 std::vector<RamDomain> randomNumbers = testutil::generateRandomVector<RamDomain>(
RANDOM_TESTS);
236 const std::string delimiter{
", "};
245 attribs[
i].append(std::to_string(
i));
248 std::vector<std::string> attribsTypes(
RANDOM_TESTS,
"i");
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())}}}};
258 std::map<std::string, std::string> dirs = {{
"operation",
"output"}, {
"IO",
"stdout"},
259 {
"attributeNames",
"x\ty"}, {
"name",
"test"}, {
"delimiter", delimiter}, {
"types",
types.dump()}};
261 std::map<std::string, std::string> ioDirs = std::map<std::string, std::string>(dirs);
263 VecOwn<Expression> exprs;
265 exprs.push_back(mk<SignedConstant>(
i));
268 Own<ram::Statement>
main = mk<ram::Sequence>(
269 mk<ram::Query>(mk<ram::Project>(
"test", std::move(exprs))), mk<ram::IO>(
"test", ioDirs));
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));
276 ErrorReport errReport;
277 DebugReport debugReport;
279 TranslationUnit translationUnit(std::move(prog), symTab, errReport, debugReport);
282 Own<Engine> interpreter = mk<Engine>(translationUnit);
284 std::streambuf* oldCoutStreambuf = std::cout.rdbuf();
285 std::ostringstream sout;
286 std::cout.rdbuf(sout.rdbuf());
288 interpreter->executeMain();
290 std::cout.rdbuf(oldCoutStreambuf);
292 std::stringstream expected;
293 expected <<
"---------------"
301 for (
size_t i = 1;
i < randomNumbers.size(); ++
i) {
302 expected << delimiter << randomNumbers[
i];
311 TEST(IO_store, MixedTypes) {
314 VecOwn<ram::Relation> rels;
316 std::vector<std::string> attribs{
"t",
"o",
"s",
"i",
"a"};
318 std::vector<std::string> attribsTypes{
"i",
"u",
"f",
"f",
"s"};
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())}}}};
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);
332 SymbolTable symbolTable;
333 ErrorReport errReport;
334 DebugReport debugReport;
336 VecOwn<Expression> exprs;
338 exprs.push_back(mk<SignedConstant>(3));
342 exprs.push_back(mk<SignedConstant>(symbolTable.lookup(
"meow")));
344 Own<ram::Statement>
main = mk<ram::Sequence>(
345 mk<ram::Query>(mk<ram::Project>(
"test", std::move(exprs))), mk<ram::IO>(
"test", ioDirs));
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));
351 TranslationUnit translationUnit(std::move(prog), symbolTable, errReport, debugReport);
354 Own<Engine> interpreter = mk<Engine>(translationUnit);
356 std::streambuf* oldCoutStreambuf = std::cout.rdbuf();
357 std::ostringstream sout;
358 std::cout.rdbuf(sout.rdbuf());
360 interpreter->executeMain();
362 std::cout.rdbuf(oldCoutStreambuf);
364 std::stringstream expected;
365 expected << std::setprecision(std::numeric_limits<RamFloat>::max_digits10);
366 expected <<
"---------------"
372 << 3 <<
"\t" << 27 <<
"\t" << floatValue <<
"\t" << floatValue <<
"\t"
381 TEST(IO_load, Signed) {
382 std::streambuf* backupCin = std::cin.rdbuf();
383 std::istringstream testInput(
"5 3");
384 std::cin.rdbuf(testInput.rdbuf());
390 std::vector<std::string> attribs = {
"a",
"b"};
391 std::vector<std::string> attribsTypes = {
"i",
"i"};
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())}}}};
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);
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);
408 Own<ram::Statement>
main =
409 mk<ram::Sequence>(mk<ram::IO>(
"test", readIoDirs), mk<ram::IO>(
"test", writeIoDirs));
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));
416 ErrorReport errReport;
417 DebugReport debugReport;
419 TranslationUnit translationUnit(std::move(prog), symTab, errReport, debugReport);
422 Own<Engine> interpreter = mk<Engine>(translationUnit);
424 std::streambuf* oldCoutStreambuf = std::cout.rdbuf();
425 std::ostringstream sout;
426 std::cout.rdbuf(sout.rdbuf());
428 interpreter->executeMain();
430 std::cout.rdbuf(oldCoutStreambuf);
432 std::string expected = R
"(---------------
440 std::cin.rdbuf(backupCin);
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());
452 std::vector<std::string> attribs = {
"a",
"b"};
453 std::vector<std::string> attribsTypes = {
"f",
"f"};
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())}}}};
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);
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);
470 Own<ram::Statement>
main =
471 mk<ram::Sequence>(mk<ram::IO>(
"test", readIoDirs), mk<ram::IO>(
"test", writeIoDirs));
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));
478 ErrorReport errReport;
479 DebugReport debugReport;
481 TranslationUnit translationUnit(std::move(prog), symTab, errReport, debugReport);
484 Own<Engine> interpreter = mk<Engine>(translationUnit);
486 std::streambuf* oldCoutStreambuf = std::cout.rdbuf();
487 std::ostringstream sout;
488 std::cout.rdbuf(sout.rdbuf());
490 interpreter->executeMain();
492 std::cout.rdbuf(oldCoutStreambuf);
494 std::string expected = R
"(---------------
502 std::cin.rdbuf(backupCin);
505 TEST(IO_load, Unsigned) {
506 std::streambuf* backupCin = std::cin.rdbuf();
507 std::istringstream testInput("6 6");
508 std::cin.rdbuf(testInput.rdbuf());
514 std::vector<std::string> attribs = {
"a",
"b"};
515 std::vector<std::string> attribsTypes = {
"u",
"u"};
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())}}}};
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);
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);
532 Own<ram::Statement>
main =
533 mk<ram::Sequence>(mk<ram::IO>(
"test", readIoDirs), mk<ram::IO>(
"test", writeIoDirs));
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));
540 ErrorReport errReport;
541 DebugReport debugReport;
543 TranslationUnit translationUnit(std::move(prog), symTab, errReport, debugReport);
546 Own<Engine> interpreter = mk<Engine>(translationUnit);
548 std::streambuf* oldCoutStreambuf = std::cout.rdbuf();
549 std::ostringstream sout;
550 std::cout.rdbuf(sout.rdbuf());
552 interpreter->executeMain();
554 std::cout.rdbuf(oldCoutStreambuf);
556 std::string expected = R
"(---------------
564 std::cin.rdbuf(backupCin);
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());
576 std::vector<std::string> attribs = {
"l",
"u",
"b",
"a"};
577 std::vector<std::string> attribsTypes = {
"s",
"i",
"u",
"f"};
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())}}}};
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);
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);
594 Own<ram::Statement>
main =
595 mk<ram::Sequence>(mk<ram::IO>(
"test", readIoDirs), mk<ram::IO>(
"test", writeIoDirs));
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));
602 ErrorReport errReport;
603 DebugReport debugReport;
605 TranslationUnit translationUnit(std::move(prog), symTab, errReport, debugReport);
608 Own<Engine> interpreter = mk<Engine>(translationUnit);
610 std::streambuf* oldCoutStreambuf = std::cout.rdbuf();
611 std::ostringstream sout;
612 std::cout.rdbuf(sout.rdbuf());
614 interpreter->executeMain();
616 std::cout.rdbuf(oldCoutStreambuf);
618 std::string expected = R
"(---------------
627 std::cin.rdbuf(backupCin);