Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7c7a915
test: make math directory testable
realstealthninja Oct 4, 2024
84acc27
fix: add include for CTest
realstealthninja Oct 4, 2024
bb5b955
Merge branch 'master' into ctest
realstealthninja Nov 4, 2024
61c980d
Merge branch 'master' into ctest
realstealthninja Nov 23, 2024
488daec
Merge branch 'master' into ctest
realstealthninja Aug 15, 2025
24af4d6
Merge branch 'master' into ctest
realstealthninja Aug 15, 2025
72d94a3
Merge branch 'TheAlgorithms:master' into ctest
realstealthninja Aug 15, 2025
923635f
feat: add testing and include all subdirs except graphics
realstealthninja Aug 15, 2025
361e92a
feat: rewrite decmial_to_hexadecimal and make it testable
realstealthninja Aug 15, 2025
3863389
Merge branch 'master' into ctest
realstealthninja Aug 16, 2025
98d7352
Merge branch 'master' into ctest
realstealthninja Sep 27, 2025
ae06157
chore: remove main from binary_search_tree.cpp
realstealthninja Sep 27, 2025
62275b8
doc: add todo add tests
realstealthninja Sep 27, 2025
e3252cb
chore: add a smaller timeout to ctest
realstealthninja Sep 27, 2025
aee59a5
chore: CTEST_TIMEOUT cannot be set?
realstealthninja Sep 27, 2025
9ba7268
ci: add ctest workflow
realstealthninja Sep 27, 2025
6a88f03
ci: renmae job
realstealthninja Sep 27, 2025
2fac5eb
ci: update checkout
realstealthninja Sep 27, 2025
b812e20
ci: fix typo
realstealthninja Sep 27, 2025
e41d0cb
ci: move ctest.yml to awesome workflow
realstealthninja Sep 27, 2025
f664cd4
ci: add version to add-label
realstealthninja Sep 27, 2025
fc3dc0a
ci: typo and fix path
realstealthninja Sep 27, 2025
cb94e33
ci: explain the timeout
realstealthninja Sep 27, 2025
e825811
chore: newline in .gitignore
realstealthninja Sep 27, 2025
2bf00f5
ci: add test-dir to ctest
realstealthninja Sep 27, 2025
4485739
Merge branch 'master' into ctest
realstealthninja Sep 27, 2025
26ba07f
ci: make tests parallel
realstealthninja Sep 27, 2025
8a6597f
ci: remove verbosity
realstealthninja Sep 27, 2025
ca2ba06
ci: try with issues write
realstealthninja Sep 27, 2025
67651e4
ci: use github script instead of action-label
realstealthninja Sep 27, 2025
d3fc77e
fix: remove testing of math algorithms twice
realstealthninja Sep 27, 2025
710f436
ci: remove labeling entirely
realstealthninja Sep 27, 2025
7d1a4bd
Merge branch 'master' into ctest
realstealthninja Sep 28, 2025
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
40 changes: 29 additions & 11 deletions .github/workflows/awesome_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
needs: [MainSequence]
permissions:
pull-requests: write
issues: write
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
Expand All @@ -63,14 +64,31 @@ jobs:
- run: |
cmake -B ./build -S .
cmake --build build --parallel 4
- name: Label on PR fail
uses: actions/github-script@v6
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']
})

test:
name: Testing pull request
runs-on: ${{ matrix.os }}
needs: [build]

permissions:
pull-requests: write
issues: 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

# 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 --test-dir build --timeout 5 --parallel 4
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ a.out
# Build
build/
git_diff.txt

# Testing
Testing/
19 changes: 14 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ project(TheAlgorithms/C++
set(CMAKE_CXX_STANDARD 17)
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)
Expand All @@ -20,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)
Expand Down Expand Up @@ -56,19 +65,19 @@ 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()

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()
Expand Down
11 changes: 6 additions & 5 deletions backtracking/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
11 changes: 6 additions & 5 deletions bit_manipulation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
11 changes: 6 additions & 5 deletions ciphers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
11 changes: 6 additions & 5 deletions cpu_scheduling_algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
11 changes: 6 additions & 5 deletions data_structures/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
53 changes: 4 additions & 49 deletions data_structures/binary_search_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,53 +122,8 @@ 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;
static void tests() {
// TODO: add tests
}

int main() { return 0; }
11 changes: 6 additions & 5 deletions divide_and_conquer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
11 changes: 6 additions & 5 deletions dynamic_programming/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
11 changes: 6 additions & 5 deletions geometry/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
9 changes: 5 additions & 4 deletions graph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
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/graph")

endforeach( testsourcefile ${APP_SOURCES} )
endforeach(testsourcefile ${APP_SOURCES})
Loading
Loading