Skip to content
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

make build and test work on linux, mac , windows. #452

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,22 @@ handle it from there. :smile:

## Compiling

To compile the source files, run **`make`** from the `C++` directory. Doing so will create executable binaries in the `bin` directory.
Test / demo applications are provided for each algorithm. To compile:

To compile and run all tests, run **`make test`**. This will compile all the tests (in the same way as described above) and will run them, displaying the results.
- navigate to the cpp directory
- initialize cmake with **`cmake --B build`**
- compile with **`cmake --build build`**
- run the tests with **`cmake --build build -t test`**. On windows **`cd build;ctest . -C Debug`**

In order to run a specific test and see its results, run it manually from the `bin` directory after calling `make`. For example, this command (executed from `bin`) would run only the unit tests for the N Queens algorithm:
In order to run a specific test and see its results, run it manually from the `bin`. For example, this command (executed from `bin`) would run only the unit tests for the N Queens algorithm:

```
$ ./n_queens
```

To remove all of the files created during compilation, run **`make clean`**. You need not do this every time you make some changes to a file and want to recompile it. Just run **`make`** and it will re-compile just those files whose contents have changed.
To remove all of the files created during compilation, run **`cmake --build build -t clean`**. You need not do this every time you make some changes to a file and want to recompile it. Just run **`cmake --build build`** and it will re-compile just those files whose contents have changed.

To see what happens in the background during compilation and testing, see the following files:

- [Makefile](cpp/Makefile)
- [CMakeLists.txt](cpp/CMakeLists.txt)
- [Testing script](cpp/scripts/run_tests.sh)

For more information on `make`, see the [GNU make Manual](https://www.gnu.org/software/make/manual/make.html). For more information on `CMake`, see the [CMake Tutorial](https://cmake.org/cmake/help/latest/guide/tutorial/index.html).
information on `CMake`, see the [CMake Tutorial](https://cmake.org/cmake/help/latest/guide/tutorial/index.html).

## Maintainers

Expand Down
41 changes: 40 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
include_directories(include)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "-g -O0 -Wall -Wextra -pedantic-errors")
if(MSVC)
set(CMAKE_CXX_FLAGS "/W3 /EHsc /permissive- -D_USE_MATH_DEFINES")
else()
set(CMAKE_CXX_FLAGS "-g -O0 -Wall -Wextra -pedantic-errors -fsanitize=address -fsanitize=undefined")
endif()


# Test runner
add_library(test_runner STATIC
Expand Down Expand Up @@ -226,3 +231,37 @@ add_executable(fenwick_tree
test/data_structure/tree/fenwick_tree.cpp)
target_link_libraries(fenwick_tree test_runner)

enable_testing()

add_test(NAME 0_1_knapsack COMMAND 0_1_knapsack)
add_test(NAME binary_search COMMAND binary_search)
add_test(NAME binary_search_tree COMMAND binary_search_tree)
add_test(NAME binomial_coefficient COMMAND binomial_coefficient)
add_test(NAME coin_change COMMAND coin_change)
add_test(NAME disjoint_set COMMAND disjoint_set)
add_test(NAME doubly_linked_list COMMAND doubly_linked_list)
add_test(NAME edit_distance COMMAND edit_distance)
add_test(NAME extended_euclidean COMMAND extended_euclidean)
add_test(NAME fast_exponentiation COMMAND fast_exponentiation)
add_test(NAME fenwick_tree COMMAND fenwick_tree)
add_test(NAME fibonacci COMMAND fibonacci)
add_test(NAME fibonacci_efficient COMMAND fibonacci_efficient)
add_test(NAME greatest_common_divisor COMMAND greatest_common_divisor)
add_test(NAME heaps_algorithm COMMAND heaps_algorithm)
add_test(NAME kadane COMMAND kadane)
add_test(NAME knuth_morris_pratt COMMAND knuth_morris_pratt)
add_test(NAME linear_search COMMAND linear_search)
add_test(NAME longest_common_subsequence COMMAND longest_common_subsequence)
add_test(NAME matrix_chain_multiplication COMMAND matrix_chain_multiplication)
add_test(NAME n_queens COMMAND n_queens)
add_test(NAME perfect_number_check COMMAND perfect_number_check)
add_test(NAME primorial COMMAND primorial)
add_test(NAME queue COMMAND queue)
add_test(NAME rod_cutting COMMAND rod_cutting)
add_test(NAME shunting_yard COMMAND shunting_yard)
add_test(NAME sieve_of_eratosthenes COMMAND sieve_of_eratosthenes)
add_test(NAME singly_linked_list COMMAND singly_linked_list)
add_test(NAME sorting COMMAND sorting)
add_test(NAME stack COMMAND stack)
add_test(NAME ternary_search COMMAND ternary_search)
add_test(NAME weighted_activity_selection COMMAND weighted_activity_selection)
Loading