A placeholder for leetcode challenges that I have been solving.
The test reports could be found in: github actions
Index | Link | Status |
---|---|---|
1 | contains-duplicate | ✅ |
2 | contains-duplicate-ii | ✅ |
3 | contains-duplicate-iii | ❌ |
4 | valid-anagram | ✅ |
sudo apt-get install cmake
sudo apt-get install lcov
Fetch the submodules (googletest):
git submodule update --init --recursive
./autorun.sh
In the project root:
mkdir build
cd build
To prepare executable, run this:
cmake ..
To prepare all your tests, run this:
cmake .. -DBUILD_TESTS=ON
To setup target for coverage, run this:
cmake .. -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Coverage
By now Makefiles should be created.
Then, to build executables and do all that linking stuff, add (-j<number-of-thread>
) to speed up.
make -j8
./leetcode
Note: cmake -DBUILD_TESTS=ON
turns on the variable 'BUILD_TESTS', which is specified in the root
CMakeLists.txt file. This is handy if you want to build in certain ways. Clear
description
here.
and if you did cmake with BUILD_TESTS=ON:
./runUnitTests
or
GTEST_COLOR=1 ctest -V
code coverage if you have -DCMAKE_BUILD_TYPE=Coverage
lcov --directory . --capture --output-file coverage.info
lcov --remove coverage.info 'tests/*' '/usr/*' 'test-library*' '*modules/googletest*' '*MacOS*' --output-file coverage.info
lcov --list coverage.info
genhtml coverage.info --output-directory html-coverage
This repository is based on the works of Gunnar in this repository. He spent a lot of time figuring out all the details for cmake and gtest. Please refer to his repository README for more detail on his approach.
Some of the solutions are inspired from 🚀 NeetCode.io @ https://github.com/neetcode-gh/leetcode