Skip to content

Commit 0244f6d

Browse files
committed
Add the header and start tests
1 parent ff55a1b commit 0244f6d

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
cmake_minimum_required(VERSION 3.10)
1+
cmake_minimum_required(VERSION 3.20)
22
project(astar-algorithm-cpp)
33

44
set(CMAKE_CXX_STANDARD 11)
55
set(CMAKE_CXX_STANDARD_REQUIRED True)
66

7-
# Header-only library interface (optional but good practice)
7+
include(FetchContent)
8+
FetchContent_Declare(
9+
doctest
10+
URL https://raw.githubusercontent.com/doctest/doctest/v2.4.11/doctest/doctest.h
11+
DOWNLOAD_NO_EXTRACT TRUE
12+
)
13+
FetchContent_MakeAvailable(doctest)
14+
15+
add_library(doctest INTERFACE)
16+
target_include_directories(doctest INTERFACE ${doctest_SOURCE_DIR})
17+
18+
# Header-only library interface
819
add_library(stlastar INTERFACE)
920
target_include_directories(stlastar INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
1021

11-
# Executables
1222
add_executable(8puzzle 8puzzle.cpp)
1323
target_link_libraries(8puzzle stlastar)
1424

@@ -18,8 +28,10 @@ target_link_libraries(findpath stlastar)
1828
add_executable(minpathbucharest min_path_to_Bucharest.cpp)
1929
target_link_libraries(minpathbucharest stlastar)
2030

21-
# Tests
2231
enable_testing()
2332
add_executable(tests tests.cpp)
24-
target_link_libraries(tests stlastar)
33+
34+
target_link_libraries(tests stlastar doctest)
35+
36+
# Register with CTest so you can run 'ctest' in the build folder
2537
add_test(NAME tests COMMAND tests)

‎tests.cpp‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
// A unit test suite
22

3+
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
4+
#include "doctest.h"
5+
#include "stlastar.h" // Assuming this is your header
6+
7+
TEST_CASE("Test A* Basic Functionality") {
8+
// Your test logic here
9+
CHECK(1 + 1 == 2);
10+
}
311
#include <assert.h>
412
#include <stdio.h>
513
#include <stdlib.h>
@@ -159,7 +167,7 @@ size_t MapSearchNode::Hash() {
159167
return h1 ^ (h2 << 1);
160168
}
161169

162-
int main(int argc, char* argv[]) {
170+
int main2(int argc, char* argv[]) {
163171
AStarSearch<MapSearchNode> astarsearch;
164172

165173
unsigned int SearchCount = 0;

0 commit comments

Comments
 (0)