Git Product home page Git Product logo

leetcodecxx's Introduction

LeetCodeCXX

This is a project for solving Leetcode problems with C++ and verifying multiple solutions with unit tests (GoogleTest). All solved questions are listed at include/questions/SOLVED.md.

Setup enviroments

./setup_env.sh
./config.sh

Create question

First, create a question by running command below, then the corresponding template of interfaces and implementations will be created and placed to proper folders:

./create_question.sh "Remove Duplicates from Sorted Array"

Second, declare pure virtual function according to question in include/questions/[questionname]/[QuestionName].hpp, redefine/override that pure virtual function in include/questions/[question name]/Solution.hpp and implement the function in src/[questionname]/Solution1.cpp. For example:

// include/questions/mergeintervals/MergeIntervals.hpp
...
class MergeIntervals : public Question 
{
public:
  virtual vector<vector<int>> merge(vector<vector<int>>& intervals) = 0;
};
...

// include/questions/mergeintervals/Solution.hpp
...
class Solution1 : MergeIntervals
{
public:
  vector<vector<int>> merge(vector<vector<int>>& intervals) override;
};
...

// src/mergeintervals/Solution.cpp
...
vector<vector<int>> Solution1::merge(vector<vector<int>>& intervals) {
    
}
...

Then, you can start to write your own unit tests in tests/[questionname]/[questionName]Test.cpp. For example, tests/mergeintervals/MergeIntervalsTest.cpp.

Build

./build.sh

Clean

./clean.sh

Test

Notice: Always build before testing

Run all test suites

./test.sh

Run single test suite

cd /build
make test MergeTwoSortedListsTest

List test cases in single test suite

cd build/tests
./MergeTwoSortedListsTest --gtest_list_tests

Run single test case in test suite (Prefered)

cd build/tests
./MergeTwoSortedListsTest --gtest_filter=MergeTwoSortedListsTest/MergeTwoSortedListsTestBase/Solution1.test11

Run a set of test case in test suite (Prefered)

cd build/tests
./MergeTwoSortedListsTest --gtest_filter=MergeTwoSortedListsTest/MergeTwoSortedListsTestBase/Solution1.test1

Log of test

Log locates at build/Testing/Temporary/LastTest.log

leetcodecxx's People

Contributors

chienkanglu avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.