Skip to content

complete the tests for Variable class #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions tests/variable_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,47 @@

using namespace datalog;

bool freeVariableTest() {
bool freeVariableTest()
{
Variable<int> intVar;
return !intVar.isBound();
}

bool boundVariableTest() {
bool boundVariableTest()
{
Variable<int> intVar;
intVar.bind(0);
return intVar.isBound();
}

TEST_CASE( "An new variable is unbound", "[variable]" ) {
REQUIRE( freeVariableTest() == true );
bool bindUnbindTest()
{
Variable<int> intVar;
intVar.bind(0);
intVar.unbind();
return !intVar.isBound();
}

bool storesValueTest()
{
Variable<int> intVar;
const int value = 100;
intVar.bind(value);
return intVar.isBound() and intVar.value() == value;
}

bool absentValueTest()
{
Variable<int> intVar;
const auto &val = intVar.value();
return true;
}

TEST_CASE( "A variable with a value is bound", "[variable]" ) {
REQUIRE( boundVariableTest() == true );
TEST_CASE("variable binding", "[variable]")
{
REQUIRE(freeVariableTest());
REQUIRE(boundVariableTest());
REQUIRE(bindUnbindTest());
REQUIRE(bindUnbindTest());
REQUIRE_THROWS_AS(absentValueTest(), std::bad_optional_access);
}