This project is based on the book "Data Structures and Algorithms in C++", "Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and The Cloud".
This project uses GoogleTest and HippoMocks to create test codes (e.g., unit test). In this repository, GoogleTest and HippoMocks are included as the submodule. You can download the submodules with
$ git submodule update --initThen, please locate each submodule's directory and reference their README.md to install the related programs. For GoogleTest,
$ cd googletest # Main directory of the cloned GoogleTest repository.
$ mkdir build # Create a directory to hold the build output.
$ cd build
$ cmake .. # Generate native build scripts for GoogleTest.
$ make
$ sudo make install # Install GoogleTest in /usr/local/ by defaultFor HippoMocks,
$ cd hippomocks # Main directory of the cloned HippoMocks repository.
$ sudo make install # Install HippoMocks in /usr/include/ by default.Before starting to build or debug this project, you might need to be familiar with the visual studio code tutorial. Also, a C++11 compiler is required for compilation.
Build methods are explained below.
- You may need to modify the compiler's path in the
tasks.jsonfile in the.vscodedirectory. - Click
Run Build Taskin theTerminaltab.
By referring the contents of tasks.json file in the .vscode directory, input the below command,
$ g++ -O3 -g -Wall -Werror -fopenmp -I Cplusplus/include/ \
Cplusplus/source/*/*.cpp Cplusplus/source/*.cpp \
-o Cplusplus/bin/project_entryRun this from the workspace root. Cplusplus/source/*/*.cpp are all of the module sources, and Cplusplus/source/*.cpp is the entry point (Main.cpp) plus ProjectConfiguration.cpp. Any C++11 compiler can replace g++; -Werror turns warnings into errors, matching tasks.json.
Each test file compiles to its own executable, linking the module sources, ProjectConfiguration.cpp, the single test file, and the GoogleTest/HippoMocks libraries installed in the Download Submodules section above (there is no aggregate test runner). For example,
$ g++ -O0 -g -Wall -Werror -fopenmp -I Cplusplus/include/ \
Cplusplus/source/*/*.cpp Cplusplus/source/ProjectConfiguration.cpp \
Cplusplus/test/LinkedList/SinglyLinkedList_UnitTest.cpp \
-lgtest -lgtest_main -lgmock -lgmock_main \
-o Cplusplus/bin/SinglyLinkedList_UnitTest
$ ./Cplusplus/bin/SinglyLinkedList_UnitTestSwap in any file under Cplusplus/test/ to run a different suite. In VS Code, the equivalent is the Build active test by specified optimization task.
Debug methods are explained below.
- You may need to modify the debugger's path in the
launch.jsonfile in the.vscodedirectory. - Click
Start Debuggingin theRuntab.
By referring the contents of launch.json file in the .vscode directory, input the below command,
$ gdb --args ./Cplusplus/bin/project_entry --helpThe executable is compiled with -g, so it is ready for gdb (or load it through launch.json in VS Code).
According to the build setting in the /tasks.json file, input the command like,
$ Cplusplus/bin/project_entrywhere [project_entry] is the executable file's name.
...