From 7c7a91599b33a9731612dce1f30901414539553c Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 4 Oct 2024 21:51:11 +0530 Subject: [PATCH 01/24] test: make math directory testable --- math/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/CMakeLists.txt b/math/CMakeLists.txt index 2b70b2d3101..bd6fcf50075 100644 --- a/math/CMakeLists.txt +++ b/math/CMakeLists.txt @@ -8,7 +8,7 @@ foreach( testsourcefile ${APP_SOURCES} ) # I used a simple string replace, to cut off .cpp. string( REPLACE ".cpp" "" testname ${testsourcefile} ) add_executable( ${testname} ${testsourcefile} ) - + add_test(NAME ${testname} COMMAND ${testname}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) From 84acc2766a35ffcb62330c11fd8ee85aecf26caf Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 4 Oct 2024 22:25:27 +0530 Subject: [PATCH 02/24] fix: add include for CTest --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cca1b54649b..516c120945b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,8 @@ project(Algorithms_in_C++ set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) +include(CTest) # for testing algorithms + if(MSVC) # set(CMAKE_CXX_STANDARD 14) add_compile_definitions(_CRT_SECURE_NO_WARNINGS) From 923635fef9fe3cb00e26f2c078313bbfc692f3d8 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 15 Aug 2025 11:59:34 +0530 Subject: [PATCH 03/24] feat: add testing and include all subdirs except graphics --- CMakeLists.txt | 16 +++++++++---- backtracking/CMakeLists.txt | 11 +++++---- bit_manipulation/CMakeLists.txt | 11 +++++---- ciphers/CMakeLists.txt | 11 +++++---- cpu_scheduling_algorithms/CMakeLists.txt | 11 +++++---- data_structures/CMakeLists.txt | 11 +++++---- divide_and_conquer/CMakeLists.txt | 11 +++++---- dynamic_programming/CMakeLists.txt | 11 +++++---- geometry/CMakeLists.txt | 11 +++++---- graph/CMakeLists.txt | 9 +++---- graphics/CMakeLists.txt | 26 ++++++++++----------- greedy_algorithms/CMakeLists.txt | 11 +++++---- hashing/CMakeLists.txt | 11 +++++---- machine_learning/CMakeLists.txt | 11 +++++---- math/CMakeLists.txt | 11 +++++---- numerical_methods/CMakeLists.txt | 11 +++++---- operations_on_datastructures/CMakeLists.txt | 11 +++++---- others/CMakeLists.txt | 11 +++++---- physics/CMakeLists.txt | 11 +++++---- probability/CMakeLists.txt | 11 +++++---- range_queries/CMakeLists.txt | 11 +++++---- search/CMakeLists.txt | 11 +++++---- sorting/CMakeLists.txt | 12 ++++++---- strings/CMakeLists.txt | 12 ++++++---- 24 files changed, 157 insertions(+), 127 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8545b1e3ec4..66aa3d6b2ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,12 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) include(CTest) # for testing algorithms +option(ENABLE_TESTING "flag to test the repo" OFF) +if(ENABLE_TESTING) + message(STATUS "Testing enabled") + enable_testing() +endif() + # Additional warnings and errors if(MSVC) add_compile_definitions(_CRT_SECURE_NO_WARNINGS) @@ -23,13 +29,13 @@ endif() option(USE_OPENMP "flag to use OpenMP for multithreading" ON) if(USE_OPENMP) find_package(OpenMP 3.0 COMPONENTS CXX) - if (OpenMP_CXX_FOUND) + if(OpenMP_CXX_FOUND) message(STATUS "Building with OpenMP Multithreading.") else() message(STATUS "No OpenMP found, no multithreading.") endif() endif() - + add_subdirectory(backtracking) add_subdirectory(bit_manipulation) add_subdirectory(ciphers) @@ -59,7 +65,7 @@ cmake_policy(SET CMP0054 NEW) cmake_policy(SET CMP0057 NEW) find_package(Doxygen OPTIONAL_COMPONENTS dot dia) -if(DOXYGEN_FOUND) +if(DOXYGEN_FOUND) if(MSVC) set(DOXYGEN_CPP_CLI_SUPPORT YES) endif() @@ -67,11 +73,11 @@ if(DOXYGEN_FOUND) if(Doxygen_dot_FOUND) set(DOXYGEN_HAVE_DOT YES) endif() - + if(OPENMP_FOUND) set(DOXYGEN_PREDEFINED "_OPENMP=1") endif() - + if(GLUT_FOUND) set(DOXYGEN_PREDEFINED ${DOXYGEN_PREDEFINED} "GLUT_FOUND=1") endif() diff --git a/backtracking/CMakeLists.txt b/backtracking/CMakeLists.txt index f636edae503..0e1d73cc4a4 100644 --- a/backtracking/CMakeLists.txt +++ b/backtracking/CMakeLists.txt @@ -1,18 +1,19 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/backtracking") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/bit_manipulation/CMakeLists.txt b/bit_manipulation/CMakeLists.txt index f5e304cfbd7..c09625aff6c 100644 --- a/bit_manipulation/CMakeLists.txt +++ b/bit_manipulation/CMakeLists.txt @@ -1,18 +1,19 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/bit_manipulation") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/ciphers/CMakeLists.txt b/ciphers/CMakeLists.txt index 1efde308787..8a6d485740e 100644 --- a/ciphers/CMakeLists.txt +++ b/ciphers/CMakeLists.txt @@ -1,18 +1,19 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/ciphers") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/cpu_scheduling_algorithms/CMakeLists.txt b/cpu_scheduling_algorithms/CMakeLists.txt index ce93cef26e3..d84247f2699 100644 --- a/cpu_scheduling_algorithms/CMakeLists.txt +++ b/cpu_scheduling_algorithms/CMakeLists.txt @@ -2,15 +2,16 @@ # with full pathname. The RELATIVE flag makes it easier to extract an executable's name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) -foreach( testsourcefile ${APP_SOURCES} ) - string( REPLACE ".cpp" "" testname ${testsourcefile} ) # File type. Example: `.cpp` - add_executable( ${testname} ${testsourcefile} ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) +foreach(testsourcefile ${APP_SOURCES}) + string(REPLACE ".cpp" "" testname ${testsourcefile}) # File type. Example: `.cpp` + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/cpu_scheduling_algorithms") # Folder name. Do NOT include `<>` -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/data_structures/CMakeLists.txt b/data_structures/CMakeLists.txt index 6c0555148be..51828d36e29 100644 --- a/data_structures/CMakeLists.txt +++ b/data_structures/CMakeLists.txt @@ -1,20 +1,21 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/data_structures") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) add_subdirectory(cll) diff --git a/divide_and_conquer/CMakeLists.txt b/divide_and_conquer/CMakeLists.txt index 4d6204325cb..ba6fc7abda6 100644 --- a/divide_and_conquer/CMakeLists.txt +++ b/divide_and_conquer/CMakeLists.txt @@ -1,18 +1,19 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/divide_and_conquer") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/dynamic_programming/CMakeLists.txt b/dynamic_programming/CMakeLists.txt index bcf0a990013..0e6efe6bc0b 100644 --- a/dynamic_programming/CMakeLists.txt +++ b/dynamic_programming/CMakeLists.txt @@ -1,18 +1,19 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/dynamic_programming") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/geometry/CMakeLists.txt b/geometry/CMakeLists.txt index 72655169aab..860d9a24621 100644 --- a/geometry/CMakeLists.txt +++ b/geometry/CMakeLists.txt @@ -1,18 +1,19 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/geometry") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/graph/CMakeLists.txt b/graph/CMakeLists.txt index 7f6ea0e69f5..23a9539e9b1 100644 --- a/graph/CMakeLists.txt +++ b/graph/CMakeLists.txt @@ -4,10 +4,10 @@ file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) #file(GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX @@ -15,6 +15,7 @@ foreach( testsourcefile ${APP_SOURCES} ) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/graph") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/graphics/CMakeLists.txt b/graphics/CMakeLists.txt index 23ffcfae179..2a7c831b843 100644 --- a/graphics/CMakeLists.txt +++ b/graphics/CMakeLists.txt @@ -4,17 +4,17 @@ if(OpenGL_FOUND) if(NOT GLUT_FOUND) message("FreeGLUT library will be downloaded and built.") include(ExternalProject) - ExternalProject_Add ( + ExternalProject_Add( FREEGLUT-PRJ URL https://github.com/FreeGLUTProject/freeglut/releases/download/v3.4.0/freeglut-3.4.0.tar.gz URL_MD5 f1621464e6525d0368976870cab8f418 CMAKE_GENERATOR ${CMAKE_GENERATOR} CMAKE_GENERATOR_TOOLSET ${CMAKE_GENERATOR_TOOLSET} CMAKE_GENERATOR_PLATFORM ${CMAKE_GENERATOR_PLATFORM} - CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release - -DFREEGLUT_BUILD_SHARED_LIBS=OFF - -DFREEGLUT_BUILD_STATIC_LIBS=ON - -DFREEGLUT_BUILD_DEMOS=OFF + CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release + -DFREEGLUT_BUILD_SHARED_LIBS=OFF + -DFREEGLUT_BUILD_STATIC_LIBS=ON + -DFREEGLUT_BUILD_DEMOS=OFF PREFIX ${CMAKE_CURRENT_BINARY_DIR}/freeglut # BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/freeglut-build # BUILD_IN_SOURCE ON @@ -44,19 +44,19 @@ endif(OpenGL_FOUND) # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} PRIVATE OpenMP::OpenMP_CXX) endif() - + if(OpenGL_FOUND) if(NOT GLUT_FOUND) add_dependencies(${testname} FREEGLUT-PRJ) @@ -73,11 +73,11 @@ foreach( testsourcefile ${APP_SOURCES} ) endif() target_compile_definitions(${testname} PRIVATE USE_GLUT) endif(OpenGL_FOUND) - + if(APPLE) target_compile_options(${testname} PRIVATE -Wno-deprecated) endif(APPLE) - + install(TARGETS ${testname} DESTINATION "bin/graphics") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/greedy_algorithms/CMakeLists.txt b/greedy_algorithms/CMakeLists.txt index bd45da6d4e9..fa5786b3738 100644 --- a/greedy_algorithms/CMakeLists.txt +++ b/greedy_algorithms/CMakeLists.txt @@ -1,18 +1,19 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/greedy_algorithms") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/hashing/CMakeLists.txt b/hashing/CMakeLists.txt index d8bad16c172..d54fd38ea66 100644 --- a/hashing/CMakeLists.txt +++ b/hashing/CMakeLists.txt @@ -1,18 +1,19 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/hash") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/machine_learning/CMakeLists.txt b/machine_learning/CMakeLists.txt index e6d8a9af405..76946fcd242 100644 --- a/machine_learning/CMakeLists.txt +++ b/machine_learning/CMakeLists.txt @@ -1,18 +1,19 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/machine_learning") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/math/CMakeLists.txt b/math/CMakeLists.txt index bd6fcf50075..33b5666ae25 100644 --- a/math/CMakeLists.txt +++ b/math/CMakeLists.txt @@ -1,18 +1,19 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) add_test(NAME ${testname} COMMAND ${testname}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname}_test ${testname}) install(TARGETS ${testname} DESTINATION "bin/math") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/numerical_methods/CMakeLists.txt b/numerical_methods/CMakeLists.txt index fc4c343de30..0dddab2cfb8 100644 --- a/numerical_methods/CMakeLists.txt +++ b/numerical_methods/CMakeLists.txt @@ -1,18 +1,19 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/numerical_methods") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/operations_on_datastructures/CMakeLists.txt b/operations_on_datastructures/CMakeLists.txt index 09119bc4300..2377d5d9f7f 100644 --- a/operations_on_datastructures/CMakeLists.txt +++ b/operations_on_datastructures/CMakeLists.txt @@ -1,15 +1,16 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/operations_on_datastructures") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/others/CMakeLists.txt b/others/CMakeLists.txt index f049b5f2d31..c83dc499da3 100644 --- a/others/CMakeLists.txt +++ b/others/CMakeLists.txt @@ -1,18 +1,19 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/others") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/physics/CMakeLists.txt b/physics/CMakeLists.txt index 4d33e8eec4c..d8b52961644 100644 --- a/physics/CMakeLists.txt +++ b/physics/CMakeLists.txt @@ -2,15 +2,16 @@ # with full pathname. The RELATIVE flag makes it easier to extract an executable's name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) -foreach( testsourcefile ${APP_SOURCES} ) - string( REPLACE ".cpp" "" testname ${testsourcefile} ) # File type. Example: `.cpp` - add_executable( ${testname} ${testsourcefile} ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) +foreach(testsourcefile ${APP_SOURCES}) + string(REPLACE ".cpp" "" testname ${testsourcefile}) # File type. Example: `.cpp` + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/physics") # Folder name. Do NOT include `<>` -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/probability/CMakeLists.txt b/probability/CMakeLists.txt index 0e0b7b7f04f..e90d82f071e 100644 --- a/probability/CMakeLists.txt +++ b/probability/CMakeLists.txt @@ -1,18 +1,19 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/probability") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/range_queries/CMakeLists.txt b/range_queries/CMakeLists.txt index c9f0c86f0a8..9fe5e5ffab1 100644 --- a/range_queries/CMakeLists.txt +++ b/range_queries/CMakeLists.txt @@ -1,18 +1,19 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/range_queries") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/search/CMakeLists.txt b/search/CMakeLists.txt index 5fd1ae59113..3e9a16246f2 100644 --- a/search/CMakeLists.txt +++ b/search/CMakeLists.txt @@ -1,18 +1,19 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/search") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/sorting/CMakeLists.txt b/sorting/CMakeLists.txt index 00877bb613a..58117c40573 100644 --- a/sorting/CMakeLists.txt +++ b/sorting/CMakeLists.txt @@ -1,13 +1,13 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX @@ -15,6 +15,8 @@ foreach( testsourcefile ${APP_SOURCES} ) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/sorting") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/strings/CMakeLists.txt b/strings/CMakeLists.txt index 3c15695cc6f..ec3be53858a 100644 --- a/strings/CMakeLists.txt +++ b/strings/CMakeLists.txt @@ -1,18 +1,20 @@ # If necessary, use the RELATIVE flag, otherwise each source file may be listed # with full pathname. RELATIVE may makes it easier to extract an executable name # automatically. -file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) # AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) -foreach( testsourcefile ${APP_SOURCES} ) +foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - add_executable( ${testname} ${testsourcefile} ) + string(REPLACE ".cpp" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() + + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/strings") -endforeach( testsourcefile ${APP_SOURCES} ) +endforeach(testsourcefile ${APP_SOURCES}) From 361e92a83a2ddb64577b2256789f10ae6cb41b29 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 15 Aug 2025 12:00:15 +0530 Subject: [PATCH 04/24] feat: rewrite decmial_to_hexadecimal and make it testable --- others/decimal_to_hexadecimal.cpp | 54 +++++++++++++++++++------------ 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/others/decimal_to_hexadecimal.cpp b/others/decimal_to_hexadecimal.cpp index a3e544f49f8..1cc551a1218 100644 --- a/others/decimal_to_hexadecimal.cpp +++ b/others/decimal_to_hexadecimal.cpp @@ -3,32 +3,46 @@ * @brief Convert decimal number to hexadecimal representation */ -#include +#include +#include +#include +#include /** - * Main program + * @brief converts a given decimal integer value to its equavalent hexadecimal + * string + * + * @param value the value to be converted + * @return std::string the hexadecimal string */ -int main(void) { - int valueToConvert = 0; // Holds user input - int hexArray[8]; // Contains hex values backwards - int i = 0; // counter - char HexValues[] = "0123456789ABCDEF"; - - std::cout << "Enter a Decimal Value" - << std::endl; // Displays request to stdout - std::cin >> - valueToConvert; // Stores value into valueToConvert via user input +std::string decimal_to_hexadecimal(std::uint32_t value) { + std::vector hexArray{}; + std::string ret = ""; + size_t i = 0; + const char HexValues[] = "0123456789ABCDEF"; - while (valueToConvert > 15) { // Dec to Hex Algorithm - hexArray[i++] = valueToConvert % 16; // Gets remainder - valueToConvert /= 16; - // valueToConvert >>= 4; // This will divide by 2^4=16 and is faster + while (value > 15) { + hexArray.at(i++) = value % 16; + value /= 16; } - hexArray[i] = valueToConvert; // Gets last value + while (i >= 0) ret.push_back(HexValues[i--]); + return ret; +} - std::cout << "Hex Value: "; - while (i >= 0) std::cout << HexValues[hexArray[i--]]; +/** + * @brief self test implementation + * @returns void + */ +static void tests() { + assert(decimal_to_hexadecimal(0) == "0"); + assert(decimal_to_hexadecimal(1) == "1"); + assert(decimal_to_hexadecimal(10) == "A"); +} - std::cout << std::endl; +/** + * Main program + */ +int main(void) { + tests(); // run self test imlementation return 0; } From ae06157cdd27d55aa96413db291fc4803b266ec4 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 10:42:33 +0530 Subject: [PATCH 05/24] chore: remove main from binary_search_tree.cpp --- data_structures/binary_search_tree.cpp | 51 +------------------------- 1 file changed, 1 insertion(+), 50 deletions(-) diff --git a/data_structures/binary_search_tree.cpp b/data_structures/binary_search_tree.cpp index 86057c6c507..a85ee1b3153 100644 --- a/data_structures/binary_search_tree.cpp +++ b/data_structures/binary_search_tree.cpp @@ -122,53 +122,4 @@ void Post(node *n) { } } -int main() { - queue.front = 0; - queue.rear = 0; - int value; - int ch; - node *root = new node; - std::cout << "\nEnter the value of root node :"; - std::cin >> value; - root->val = value; - root->left = NULL; - root->right = NULL; - do { - std::cout << "\n1. Insert" - << "\n2. Delete" - << "\n3. Breadth First" - << "\n4. Preorder Depth First" - << "\n5. Inorder Depth First" - << "\n6. Postorder Depth First"; - - std::cout << "\nEnter Your Choice : "; - std::cin >> ch; - int x; - switch (ch) { - case 1: - std::cout << "\nEnter the value to be Inserted : "; - std::cin >> x; - Insert(root, x); - break; - case 2: - std::cout << "\nEnter the value to be Deleted : "; - std::cin >> x; - Remove(root, root, x); - break; - case 3: - BFT(root); - break; - case 4: - Pre(root); - break; - case 5: - In(root); - break; - case 6: - Post(root); - break; - } - } while (ch != 0); - - return 0; -} +int main() { return 0; } From 62275b8749efae95c75cb0174c7e29c872ec8756 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 10:43:35 +0530 Subject: [PATCH 06/24] doc: add todo add tests --- data_structures/binary_search_tree.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data_structures/binary_search_tree.cpp b/data_structures/binary_search_tree.cpp index a85ee1b3153..66aa49c182f 100644 --- a/data_structures/binary_search_tree.cpp +++ b/data_structures/binary_search_tree.cpp @@ -122,4 +122,8 @@ void Post(node *n) { } } +static void tests() { + // TODO: add tests +} + int main() { return 0; } From e3252cb591ca3462750a9a6a9d229b3c34615580 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 11:09:41 +0530 Subject: [PATCH 07/24] chore: add a smaller timeout to ctest --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 66aa3d6b2ac..9d36bf431b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,10 @@ option(ENABLE_TESTING "flag to test the repo" OFF) if(ENABLE_TESTING) message(STATUS "Testing enabled") enable_testing() + + # 5 second timeout to weed out all the user input algorithms + # this should be eventually removed once all the files do not take user input anymore + set(CTEST_TEST_TIMEOUT 5) endif() # Additional warnings and errors From aee59a541356a4285eb9556de2a67773071b3985 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 11:15:58 +0530 Subject: [PATCH 08/24] chore: CTEST_TIMEOUT cannot be set? --- CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d36bf431b6..66aa3d6b2ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,10 +16,6 @@ option(ENABLE_TESTING "flag to test the repo" OFF) if(ENABLE_TESTING) message(STATUS "Testing enabled") enable_testing() - - # 5 second timeout to weed out all the user input algorithms - # this should be eventually removed once all the files do not take user input anymore - set(CTEST_TEST_TIMEOUT 5) endif() # Additional warnings and errors From 9ba72680294369116d626fada90e4b8e5996466e Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 11:32:17 +0530 Subject: [PATCH 09/24] ci: add ctest workflow --- .github/workflows/ctest.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/ctest.yml diff --git a/.github/workflows/ctest.yml b/.github/workflows/ctest.yml new file mode 100644 index 00000000000..3a91c18fc1d --- /dev/null +++ b/.github/workflows/ctest.yml @@ -0,0 +1,23 @@ +# Run unit tests using CTest +name: Tests + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + checkout-and-check-formatting: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Run unit tests + uses: HorstBaerbel/action-ctest@1.1 + # These are optional (defaults displayed) + with: + sourcedir: "." + builddir: "build" + cmakeoptions: "-DENABLE_TESTING ON" + ctestoptions: "--timeout 5" From 6a88f03bae34f0d382b93a24c83de2d9de0cca53 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 11:33:56 +0530 Subject: [PATCH 10/24] ci: renmae job --- .github/workflows/ctest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ctest.yml b/.github/workflows/ctest.yml index 3a91c18fc1d..a1702716f01 100644 --- a/.github/workflows/ctest.yml +++ b/.github/workflows/ctest.yml @@ -8,7 +8,7 @@ on: branches: [master] jobs: - checkout-and-check-formatting: + test: runs-on: ubuntu-latest steps: From 2fac5eb85f0c3f50123d41a04a3888f0f3149a7a Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 11:34:38 +0530 Subject: [PATCH 11/24] ci: update checkout --- .github/workflows/ctest.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ctest.yml b/.github/workflows/ctest.yml index a1702716f01..9e00be988e5 100644 --- a/.github/workflows/ctest.yml +++ b/.github/workflows/ctest.yml @@ -12,10 +12,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Run unit tests uses: HorstBaerbel/action-ctest@1.1 - # These are optional (defaults displayed) with: sourcedir: "." builddir: "build" From b812e2051789190cb915fd045f6df07c9ea583ca Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 11:37:17 +0530 Subject: [PATCH 12/24] ci: fix typo --- .github/workflows/ctest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ctest.yml b/.github/workflows/ctest.yml index 9e00be988e5..aa014425089 100644 --- a/.github/workflows/ctest.yml +++ b/.github/workflows/ctest.yml @@ -18,5 +18,5 @@ jobs: with: sourcedir: "." builddir: "build" - cmakeoptions: "-DENABLE_TESTING ON" + cmakeoptions: "-DENABLE_TESTING=ON" ctestoptions: "--timeout 5" From e41d0cb8b6a7017c448ba5c8967fc23d908a18ba Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 11:56:28 +0530 Subject: [PATCH 13/24] ci: move ctest.yml to awesome workflow --- .github/workflows/awesome_workflow.yml | 41 +++++++++++++++++++++----- .github/workflows/ctest.yml | 22 -------------- 2 files changed, 33 insertions(+), 30 deletions(-) delete mode 100644 .github/workflows/ctest.yml diff --git a/.github/workflows/awesome_workflow.yml b/.github/workflows/awesome_workflow.yml index 473d7940663..35277521c2f 100644 --- a/.github/workflows/awesome_workflow.yml +++ b/.github/workflows/awesome_workflow.yml @@ -63,14 +63,39 @@ jobs: - run: | cmake -B ./build -S . cmake --build build --parallel 4 + - name: Label on PR fail - uses: actions/github-script@v6 + uses: actions-ecosystem/action-add-labels@v1 if: ${{ failure() && matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request' }} with: - script: | - github.rest.issues.addLabels({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - labels: ['automated tests are failing'] - }) + labels: "automated build is failing" + + test: + name: Testing pullrequest + runs-on: ${{ matrix.os }} + needs: [build] + + permissions: + pull-requests: write + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: build + run: | + cmake -B build -S . -DBENABLE_TESTING=ON + cmake --build build --parallel 4 + + - name: test + run: | + ctest build --verbose --timeout 5 + + - name: Label on PR fail + uses: actions-ecosystem/action-add-labels + if: ${{ failure() && github.event_name == 'pull_request' }} + with: + labels: "automated tests are failing" diff --git a/.github/workflows/ctest.yml b/.github/workflows/ctest.yml deleted file mode 100644 index aa014425089..00000000000 --- a/.github/workflows/ctest.yml +++ /dev/null @@ -1,22 +0,0 @@ -# Run unit tests using CTest -name: Tests - -on: - push: - branches: [master] - pull_request: - branches: [master] - -jobs: - test: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Run unit tests - uses: HorstBaerbel/action-ctest@1.1 - with: - sourcedir: "." - builddir: "build" - cmakeoptions: "-DENABLE_TESTING=ON" - ctestoptions: "--timeout 5" From f664cd497f767066f1f70089fd65b3fb8df0a1ca Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 12:05:26 +0530 Subject: [PATCH 14/24] ci: add version to add-label --- .github/workflows/awesome_workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/awesome_workflow.yml b/.github/workflows/awesome_workflow.yml index 35277521c2f..a179cd765ca 100644 --- a/.github/workflows/awesome_workflow.yml +++ b/.github/workflows/awesome_workflow.yml @@ -95,7 +95,7 @@ jobs: ctest build --verbose --timeout 5 - name: Label on PR fail - uses: actions-ecosystem/action-add-labels + uses: actions-ecosystem/action-add-labels@v1 if: ${{ failure() && github.event_name == 'pull_request' }} with: labels: "automated tests are failing" From fc3dc0a31a013f992ba788587a49b2f276b193f9 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 12:15:47 +0530 Subject: [PATCH 15/24] ci: typo and fix path --- .github/workflows/awesome_workflow.yml | 4 ++-- .gitignore | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/awesome_workflow.yml b/.github/workflows/awesome_workflow.yml index a179cd765ca..36b743a989f 100644 --- a/.github/workflows/awesome_workflow.yml +++ b/.github/workflows/awesome_workflow.yml @@ -71,7 +71,7 @@ jobs: labels: "automated build is failing" test: - name: Testing pullrequest + name: Testing pull request runs-on: ${{ matrix.os }} needs: [build] @@ -92,7 +92,7 @@ jobs: - name: test run: | - ctest build --verbose --timeout 5 + ctest build/. --verbose --timeout 5 - name: Label on PR fail uses: actions-ecosystem/action-add-labels@v1 diff --git a/.gitignore b/.gitignore index c4951fe97b1..055b79929eb 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,6 @@ a.out # Build build/ git_diff.txt + +# Testing +Testing/ \ No newline at end of file From cb94e3348f246b3fcdb9b6eb6c8bf6bcbe524ef6 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 12:17:07 +0530 Subject: [PATCH 16/24] ci: explain the timeout --- .github/workflows/awesome_workflow.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/awesome_workflow.yml b/.github/workflows/awesome_workflow.yml index 36b743a989f..4d14f990eeb 100644 --- a/.github/workflows/awesome_workflow.yml +++ b/.github/workflows/awesome_workflow.yml @@ -90,6 +90,8 @@ jobs: cmake -B build -S . -DBENABLE_TESTING=ON cmake --build build --parallel 4 + # The timeout below is to catch the files with user input in their main function. + # It should be removed eventually when all the files are clear of user input. - name: test run: | ctest build/. --verbose --timeout 5 From e8258112b06008ec5645630aa7b37c58dd4e01e6 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 12:20:04 +0530 Subject: [PATCH 17/24] chore: newline in .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 055b79929eb..7556baacaca 100644 --- a/.gitignore +++ b/.gitignore @@ -42,4 +42,4 @@ build/ git_diff.txt # Testing -Testing/ \ No newline at end of file +Testing/ From 2bf00f5f76a799d16fe2b5da3eb4487ffeda968b Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 12:35:36 +0530 Subject: [PATCH 18/24] ci: add test-dir to ctest --- .github/workflows/awesome_workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/awesome_workflow.yml b/.github/workflows/awesome_workflow.yml index 4d14f990eeb..065570404d6 100644 --- a/.github/workflows/awesome_workflow.yml +++ b/.github/workflows/awesome_workflow.yml @@ -94,7 +94,7 @@ jobs: # It should be removed eventually when all the files are clear of user input. - name: test run: | - ctest build/. --verbose --timeout 5 + ctest --test-dir build --verbose --timeout 5 - name: Label on PR fail uses: actions-ecosystem/action-add-labels@v1 From 26ba07fc329046597f6ac2aee10c093f3de77cd1 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 12:53:46 +0530 Subject: [PATCH 19/24] ci: make tests parallel --- .github/workflows/awesome_workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/awesome_workflow.yml b/.github/workflows/awesome_workflow.yml index 065570404d6..468f9c60522 100644 --- a/.github/workflows/awesome_workflow.yml +++ b/.github/workflows/awesome_workflow.yml @@ -94,7 +94,7 @@ jobs: # It should be removed eventually when all the files are clear of user input. - name: test run: | - ctest --test-dir build --verbose --timeout 5 + ctest --test-dir build --verbose --timeout 5 --parallel 4 - name: Label on PR fail uses: actions-ecosystem/action-add-labels@v1 From 8a6597fa3b39079b14fb5db3f2e6dc33d5b1e7fa Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 12:58:45 +0530 Subject: [PATCH 20/24] ci: remove verbosity --- .github/workflows/awesome_workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/awesome_workflow.yml b/.github/workflows/awesome_workflow.yml index 468f9c60522..043ee72a869 100644 --- a/.github/workflows/awesome_workflow.yml +++ b/.github/workflows/awesome_workflow.yml @@ -94,7 +94,7 @@ jobs: # It should be removed eventually when all the files are clear of user input. - name: test run: | - ctest --test-dir build --verbose --timeout 5 --parallel 4 + ctest --test-dir build --timeout 5 --parallel 4 - name: Label on PR fail uses: actions-ecosystem/action-add-labels@v1 From ca2ba06ffc1806e522eb892dbec39df1ff202c3a Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 15:59:01 +0530 Subject: [PATCH 21/24] ci: try with issues write --- .github/workflows/awesome_workflow.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/awesome_workflow.yml b/.github/workflows/awesome_workflow.yml index 043ee72a869..c607821cafc 100644 --- a/.github/workflows/awesome_workflow.yml +++ b/.github/workflows/awesome_workflow.yml @@ -53,6 +53,7 @@ jobs: needs: [MainSequence] permissions: pull-requests: write + issues: write strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] @@ -77,6 +78,8 @@ jobs: permissions: pull-requests: write + issues: write + strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] From 67651e4936202862312ed54b7fa639a8622c8468 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 16:24:41 +0530 Subject: [PATCH 22/24] ci: use github script instead of action-label --- .github/workflows/awesome_workflow.yml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/awesome_workflow.yml b/.github/workflows/awesome_workflow.yml index c607821cafc..99cf1959080 100644 --- a/.github/workflows/awesome_workflow.yml +++ b/.github/workflows/awesome_workflow.yml @@ -66,11 +66,16 @@ jobs: cmake --build build --parallel 4 - name: Label on PR fail - uses: actions-ecosystem/action-add-labels@v1 + uses: actions/github-script@v4 if: ${{ failure() && matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request' }} with: - labels: "automated build is failing" - + script: | + await github.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + labels: ['automated build is failing'] + }) test: name: Testing pull request runs-on: ${{ matrix.os }} @@ -100,7 +105,13 @@ jobs: ctest --test-dir build --timeout 5 --parallel 4 - name: Label on PR fail - uses: actions-ecosystem/action-add-labels@v1 + uses: actions/github-script@v4 if: ${{ failure() && github.event_name == 'pull_request' }} with: - labels: "automated tests are failing" + script: | + await github.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + labels: ['automated tests are failing'] + }) From d3fc77e2ec36cf4566e3e26c09563bae2259ae42 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 16:38:36 +0530 Subject: [PATCH 23/24] fix: remove testing of math algorithms twice --- math/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/math/CMakeLists.txt b/math/CMakeLists.txt index 33b5666ae25..9be975b3f51 100644 --- a/math/CMakeLists.txt +++ b/math/CMakeLists.txt @@ -8,12 +8,11 @@ foreach(testsourcefile ${APP_SOURCES}) # I used a simple string replace, to cut off .cpp. string(REPLACE ".cpp" "" testname ${testsourcefile}) add_executable(${testname} ${testsourcefile}) - add_test(NAME ${testname} COMMAND ${testname}) set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) if(OpenMP_CXX_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_CXX) endif() - add_test(${testname}_test ${testname}) + add_test(${testname} ${testname}) install(TARGETS ${testname} DESTINATION "bin/math") endforeach(testsourcefile ${APP_SOURCES}) From 710f4361f9128112c5cf3ec1148dc1e087a602ca Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 27 Sep 2025 16:47:00 +0530 Subject: [PATCH 24/24] ci: remove labeling entirely --- .github/workflows/awesome_workflow.yml | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/.github/workflows/awesome_workflow.yml b/.github/workflows/awesome_workflow.yml index 99cf1959080..44511cab361 100644 --- a/.github/workflows/awesome_workflow.yml +++ b/.github/workflows/awesome_workflow.yml @@ -65,17 +65,6 @@ jobs: cmake -B ./build -S . cmake --build build --parallel 4 - - name: Label on PR fail - uses: actions/github-script@v4 - if: ${{ failure() && matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request' }} - with: - script: | - await github.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - labels: ['automated build is failing'] - }) test: name: Testing pull request runs-on: ${{ matrix.os }} @@ -103,15 +92,3 @@ jobs: - name: test run: | ctest --test-dir build --timeout 5 --parallel 4 - - - name: Label on PR fail - uses: actions/github-script@v4 - if: ${{ failure() && github.event_name == 'pull_request' }} - with: - script: | - await github.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - labels: ['automated tests are failing'] - })