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

Skip to content

Commit acb4835

Browse files
authored
Merge pull request #4 from Z80coder/unit-test-variable
use a unit-testing framework
2 parents dce418a + 4161c6d commit acb4835

File tree

5 files changed

+47
-26
lines changed

5 files changed

+47
-26
lines changed

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{
77
"label": "build",
88
"type": "shell",
9-
"command": "mkdir -p build; cd build; cmake ../src; make",
9+
"command": "cd build; make",
1010
"problemMatcher": [
1111
"$gcc"
1212
],

docs/build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ make
1313

1414
Add the C/C++ extension for Visual Studio Code for IntelliSense configuration: in the IDE press `CTRL-P` and then paste the command `ext install ms-vscode.cpptools`.
1515

16-
Typping `CTRL-SHIFT-B` in the IDE will automatically build the proejct.
16+
Ensure you have built the makefiles as per above. Then holding `CTRL-SHIFT-B` in the IDE will automatically build the project.
1717

1818
# Building directly with CMake in Visual Studio 2019
1919
Visual Studio 2019 supports using CMake to manage the build directly by selecting File -> Open -> Cmake... and opening `src/CMakeLists.txt`. Then Visual Studio's normal build shortcuts will update the CMake configuration as well as building the project.

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ set(CMAKE_CXX_STANDARD 17)
2525
add_executable(types_test ../tests/types_test.cpp)
2626
target_include_directories(types_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
2727
target_compile_definitions(types_test PUBLIC UNIX)
28+
29+
# variable_test target
30+
add_executable(variable_test ../tests/variable_test.cpp)
31+
target_include_directories(variable_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
32+
target_compile_definitions(variable_test PUBLIC UNIX)

tests/types_test.cpp

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
#include <Datalog.h>
1+
// Let Catch provide main():
2+
#define CATCH_CONFIG_MAIN
3+
4+
#include "catch.hpp"
5+
#include "Datalog.h"
26

37
using namespace datalog;
48

@@ -109,7 +113,6 @@ bool test2()
109113
return true;
110114
}
111115

112-
#if 1
113116
bool po1()
114117
{
115118
typedef unsigned int Number;
@@ -193,9 +196,9 @@ bool po1()
193196
const auto& computedA = convert<A>(temp);
194197
//return convert<RELATION_TYPE>(getTrackedSet<RELATION_TYPE>());
195198

196-
cout << "result = ";
197-
operator<< <A>(cout, computedA);
198-
cout << endl;
199+
// cout << "result = ";
200+
// operator<< <A>(cout, computedA);
201+
// cout << endl;
199202

200203
delete a;
201204
delete b;
@@ -215,7 +218,6 @@ bool po1()
215218

216219
return computedA == aOut;
217220
}
218-
#endif
219221

220222
bool test4()
221223
{
@@ -312,21 +314,9 @@ bool test4()
312314
return true;
313315
}
314316

315-
int main()
316-
{
317-
bool ok1 = test1();
318-
bool ok2 = test2();
319-
#if 1
320-
bool ok3 = po1();
321-
bool ok4 = test4();
322-
323-
if (!(ok1 and ok2 and ok3 and ok4)) {
324-
cout << "FAIL" << endl;
325-
return 1;
326-
} else {
327-
cout << "PASSED" << endl;
328-
return 0;
329-
}
330-
#endif
331-
return 1;
332-
}
317+
TEST_CASE( "toy-examples", "[types-test]" ) {
318+
REQUIRE( test1() );
319+
REQUIRE( test2() );
320+
REQUIRE( po1() );
321+
REQUIRE( test4() );
322+
}

tests/variable_test.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Let Catch provide main():
2+
#define CATCH_CONFIG_MAIN
3+
4+
#include "catch.hpp"
5+
#include "Variable.h"
6+
7+
using namespace datalog;
8+
9+
bool freeVariableTest() {
10+
Variable<int> intVar;
11+
return !intVar.isBound();
12+
}
13+
14+
bool boundVariableTest() {
15+
Variable<int> intVar;
16+
intVar.bind(0);
17+
return intVar.isBound();
18+
}
19+
20+
TEST_CASE( "An new variable is unbound", "[variable]" ) {
21+
REQUIRE( freeVariableTest() );
22+
}
23+
24+
TEST_CASE( "A variable with a value is bound", "[variable]" ) {
25+
REQUIRE( freeVariableTest() );
26+
}

0 commit comments

Comments
 (0)
0