8000 Merge pull request #6 from Z80coder/complete-variable-test · Z80coder/datalog-cpp@e1003a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit e1003a3

Browse files
authored
Merge pull request #6 from Z80coder/complete-variable-test
complete the tests for Variable class
2 parents f452d48 + 152a1e8 commit e1003a3

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

tests/variable_test.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line ch 10000 ange
@@ -3,21 +3,47 @@
33

44
using namespace datalog;
55

6-
bool freeVariableTest() {
6+
bool freeVariableTest()
7+
{
78
Variable<int> intVar;
89
return !intVar.isBound();
910
}
1011

11-
bool boundVariableTest() {
12+
bool boundVariableTest()
13+
{
1214
Variable<int> intVar;
1315
intVar.bind(0);
1416
return intVar.isBound();
1517
}
1618

17-
TEST_CASE( "An new variable is unbound", "[variable]" ) {
18-
REQUIRE( freeVariableTest() == true );
19+
bool bindUnbindTest()
20+
{
21+
Variable<int> intVar;
22+
intVar.bind(0);
23+
intVar.unbind();
24+
return !intVar.isBound();
25+
}
26+
27+
bool storesValueTest()
28+
{
29+
Variable<int> intVar;
30+
const int value = 100;
31+
intVar.bind(value);
32+
return intVar.isBound() and intVar.value() == value;
33+
}
34+
35+
bool absentValueTest()
36+
{
37+
Variable<int> intVar;
38+
const auto &val = intVar.value();
39+
return true;
1940
}
2041

21-
TEST_CASE( "A variable with a value is bound", "[variable]" ) {
22-
REQUIRE( boundVariableTest() == true );
42+
TEST_CASE("variable binding", "[variable]")
43+
{
44+
REQUIRE(freeVariableTest());
45+
REQUIRE(boundVariableTest());
46+
REQUIRE(bindUnbindTest());
47+
REQUIRE(bindUnbindTest());
48+
REQUIRE_THROWS_AS(absentValueTest(), std::bad_optional_access);
2349
}

0 commit comments

Comments
 (0)
0