Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitacb4835

Browse files
authored
Merge pull request#4 from Z80coder/unit-test-variable
use a unit-testing framework
2 parentsdce418a +4161c6d commitacb4835

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 theproejct.
16+
Ensure you have built the makefiles as per above. Then holding`CTRL-SHIFT-B` in the IDE will automatically build theproject.
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_testPUBLIC${CMAKE_CURRENT_SOURCE_DIR})
2727
target_compile_definitions(types_testPUBLICUNIX)
28+
29+
# variable_test target
30+
add_executable(variable_test ../tests/variable_test.cpp)
31+
target_include_directories(variable_testPUBLIC${CMAKE_CURRENT_SOURCE_DIR})
32+
target_compile_definitions(variable_testPUBLICUNIX)

‎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+
#defineCATCH_CONFIG_MAIN
3+
4+
#include"catch.hpp"
5+
#include"Datalog.h"
26

37
usingnamespacedatalog;
48

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

112-
#if1
113116
boolpo1()
114117
{
115118
typedefunsignedint Number;
@@ -193,9 +196,9 @@ bool po1()
193196
constauto& 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
booltest4()
221223
{
@@ -312,21 +314,9 @@ bool test4()
312314
returntrue;
313315
}
314316

315-
intmain()
316-
{
317-
bool ok1 =test1();
318-
bool ok2 =test2();
319-
#if1
320-
bool ok3 =po1();
321-
bool ok4 =test4();
322-
323-
if (!(ok1and ok2and ok3and ok4)) {
324-
cout <<"FAIL" << endl;
325-
return1;
326-
}else {
327-
cout <<"PASSED" << endl;
328-
return0;
329-
}
330-
#endif
331-
return1;
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+
#defineCATCH_CONFIG_MAIN
3+
4+
#include"catch.hpp"
5+
#include"Variable.h"
6+
7+
usingnamespacedatalog;
8+
9+
boolfreeVariableTest() {
10+
Variable<int> intVar;
11+
return !intVar.isBound();
12+
}
13+
14+
boolboundVariableTest() {
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)

[8]ページ先頭

©2009-2025 Movatter.jp