Skip to content

Commit

Permalink
Merge pull request #81 from P4-ACMMMRW/fix_not_test
Browse files Browse the repository at this point in the history
Fix not test
  • Loading branch information
mtygesen authored May 28, 2024
2 parents 8cc0c15 + 4e8edc9 commit 3c7de49
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,13 @@ bool Value::operator!() const {
return true;
}
if (is<COLUMN>()) {
return !get<COLUMN>()->data->empty();
return get<COLUMN>()->data->empty(); // not "" : [] == true
}
if (is<TABLE>()) {
return !get<TABLE>()->second.empty();
return get<TABLE>()->second.empty(); // not {} == true
}

throw RuntimeException("Can not use NOT on this type");
throw InternalException("Can not use NOT on this type");
}

Value Value::operator+(const Value& other) const {
Expand Down
16 changes: 15 additions & 1 deletion tests/symbol-table/ValueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ VALUE_TEST("compare values") {
REQUIRE(!(col3 != col1));
REQUIRE(col3 != col2);

REQUIRE(!(col1) == false);
REQUIRE(!(col2) == false);
REQUIRE(!(col3) == false);

Value col4 = std::make_shared<Value::COL_STRUCT>();
std::cout << l4.toString() << '\n';
col4.get<Value::COLUMN>()->data = l4.get<Value::LIST>();
Expand All @@ -195,6 +199,10 @@ VALUE_TEST("compare values") {
REQUIRE(!(col6 > col4));
REQUIRE(!(col6 > col5));

REQUIRE(!(col4) == false);
REQUIRE(!(col5) == false);
REQUIRE(!(col6) == false);

// Tables
Value tab1 = std::make_shared<std::pair<std::vector<Value::STR>, std::unordered_map<Value::STR, Value::COLUMN>>>();
tab1.get<Value::TABLE>()->second.insert({"col", col1.get<Value::COLUMN>()});
Expand All @@ -219,6 +227,10 @@ VALUE_TEST("compare values") {
REQUIRE(!(tab3 != tab1));
REQUIRE(tab3 != tab2);

REQUIRE(!(tab1) == false);
REQUIRE(!(tab2) == false);
REQUIRE(!(tab3) == false);

Value tab4 = std::make_shared<std::pair<std::vector<Value::STR>, std::unordered_map<Value::STR, Value::COLUMN>>>();
REQUIRE(tab1 != tab4);

Expand All @@ -227,6 +239,9 @@ VALUE_TEST("compare values") {

REQUIRE(tab1 != tab5);
REQUIRE(tab4 < tab1);

REQUIRE(!(tab4) == true);
REQUIRE(!(tab5) == false);

}

Expand Down Expand Up @@ -660,7 +675,6 @@ VALUE_TEST("Arthrimetic values") {
Value colEmpty = std::make_shared<Value::COL_STRUCT>();
colEmpty.get<Value::COLUMN>()->data = lEmpty.get<Value::LIST>();

REQUIRE_THROWS_AS(!col1, dplsrc::RuntimeException);
REQUIRE_THROWS_AS(col1 + colEmpty, dplsrc::RuntimeException);
REQUIRE_THROWS_AS(colEmpty + col1 , dplsrc::RuntimeException);
REQUIRE_THROWS_AS(col1 - colEmpty, dplsrc::RuntimeException);
Expand Down

0 comments on commit 3c7de49

Please sign in to comment.