8000 use a unit-testing framework by Z80coder · Pull Request #4 · Z80coder/datalog-cpp · GitHub
[go: up one dir, main page]

Skip to content

use a unit-testing framework #4

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
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"label": "build",
"type": "shell",
"command": "mkdir -p build; cd build; cmake ../src; make",
"command": "cd build; make",
"problemMatcher": [
"$gcc"
],
Expand Down
2 changes: 1 addition & 1 deletion docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ make

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`.

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

# Building directly with CMake in Visual Studio 2019
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.
Expand Down
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ set(CMAKE_CXX_STANDARD 17)
add_executable(types_test ../tests/types_test.cpp)
target_include_directories(types_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(types_test PUBLIC UNIX)

# variable_test target
add_executable(variable_test ../tests/variable_test.cpp)
target_include_directories(variable_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(variable_test PUBLIC UNIX)
38 changes: 14 additions & 24 deletions tests/types_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include <Datalog.h>
// Let Catch provide main():
#define CATCH_CONFIG_MAIN

#include "catch.hpp"
#include "Datalog.h"

using namespace datalog;

Expand Down Expand Up @@ -109,7 +113,6 @@ bool test2()
return true;
}

#if 1
bool po1()
{
typedef unsigned int Number;
Expand Down Expand Up @@ -193,9 +196,9 @@ bool po1()
const auto& computedA = convert<A>(temp);
//return convert<RELATION_TYPE>(getTrackedSet<RELATION_TYPE>());

cout << "result = ";
operator<< <A>(cout, computedA);
cout << endl;
// cout << "result = ";
// operator<< <A>(cout, computedA);
// cout << endl;

delete a;
delete b;
Expand All @@ -215,7 +218,6 @@ bool po1()

return computedA == aOut;
}
#endif

bool test4()
{
Expand Down Expand Up @@ -312,21 +314,9 @@ bool test4()
return true;
}

int main()
{
bool ok1 = test1();
bool ok2 = test2();
#if 1
bool ok3 = po1();
bool ok4 = test4();

if (!(ok1 and ok2 and ok3 and ok4)) {
cout << "FAIL" << endl;
return 1;
} else {
cout << "PASSED" << endl;
return 0;
}
#endif
return 1;
}
TEST_CASE( "toy-examples", "[types-test]" ) {
REQUIRE( test1() );
REQUIRE( test2() );
REQUIRE( po1() );
REQUIRE( test4() );
}
26 changes: 26 additions & 0 deletions tests/variable_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Let Catch provide main():
#define CATCH_CONFIG_MAIN

#include "catch.hpp"
#include "Variable.h"

using namespace datalog;

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

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

TEST_CASE( "An new variable is unbound", "[variable]" ) {
REQUIRE( freeVariableTest() );
}

TEST_CASE( "A variable with a value is bound", "[variable]" ) {
REQUIRE( freeVariableTest() );
}
0