Skip to content

Latest commit

 

History

History
156 lines (110 loc) · 5.78 KB

CONTRIBUTING.md

File metadata and controls

156 lines (110 loc) · 5.78 KB

Contribution Guidelines

Contents

Getting started

  • Start by exploring the repository. Take a look at how the algorithms and data structures are implemented, how tests are written, and which files go where.

  • Before beginning your contribution, create an issue. In your issue's description, please describe the addition or change you wish to make. This helps others guide your contribution, and it lets others know what you're working on.

  • Fork the repo, then clone your fork and configure the remotes:

    # Clone your fork of the repo into the current directory
    git clone https://github.com/<your-username>/ProAlgos-Cpp.git
    
    # Navigate to the newly cloned directory
    cd ProAlgos-Cpp
    
    # Assign the original repo to a remote called "upstream"
    git remote add upstream https://github.com/ProAlgos/ProAlgos-Cpp.git
  • If you cloned a while ago, get the latest changes from upstream:

    git checkout master
    git pull upstream master
  • Create a new branch (starting from the master branch) to contain your code for a specific algorithm or data structure:

    git checkout -b <branch-name>

Writing code

  • Start by reviewing our C++ coding guidelines.

  • Commit your changes in logical chunks. Use Git's interactive rebase feature to tidy up your commits before making them public. For more info, see the following interactive rebase guide.

  • For each algorithm, mention its time complexity and space complexity in the "description comment" of its implementation. In case the average-case and worst-case complexities are different, mention both of them.

    The format for the "description comment" (which is written at the beginning) should be:

    <Name of algorithm>
    -------------------
    <Brief description>
    
    Time complexity
    ---------------
    O(...), where <description of variable(s)>
    
    Space complexity
    ----------------
    O(...), where <description of variable(s)>
    
  • Before you push your changes to GitHub, make sure that your code compiles and runs without any errors or warnings.

Testing code

Algorithms and data structures are implemented as header files (.hpp) in the include directory and then verified via unit test files (.cpp) in the test directory. If you're adding an algorithm or data structure, you'll write both the implementation and the unit tests.

Adding unit tests

  1. Under test, locate (or create, if it doesn't exist) the directory having the same relative path from test as from include. For example, if you've created a header file in include/algorithm/searching, locate (or create) the directory test/algorithm/searching.

  2. Create a file with the same name as the corresponding header file for which you are writing tests, except that the extension should be .cpp.

  3. Add the following code to the test file:

    #include "third_party/catch.hpp"
    #include "path/to/header_file.hpp"

    The path to the header file is relative from the include directory. So, for instance, if you need to include the header file include/algorithm/searching/linear_search.hpp, you can write:

    #include "algorithm/searching/linear_search.hpp"
  4. After these lines you can add your test cases. For details regarding how to write test cases using the Catch test framework, I suggest you to go through this short tutorial. You can also take a look at the existing unit tests to get a clearer idea about how the tests are written.

  5. Add an entry for your unit test in CMakeLists.txt. For example, if your unit test is test/algorithm/searching/linear_search.cpp, add the following entry for it:

     add_executable(linear_search
            test/algorithm/searching/linear_search.cpp)
     target_link_libraries(linear_search test_runner)

That's it! Now you can compile the test using make test from the C++ directory, which will also run all of the tests for you. In order to run only a specific test and see its results, run it manually from the bin directory.

Opening a pull request

Follow these steps when you're ready to submit your code:

  1. Locally merge (or rebase) the upstream development branch into your branch:

    git pull [--rebase] upstream master
  2. Push your branch up to your fork:

    git push origin <branch-name>
  3. Open a pull request with a clear title and description against the master branch. Your pull request should reference the same issue you created above.

  4. Once your pull request has been opened, we'll review it and go from there. 😄

Code of Conduct

This project has a Code of Conduct. Please follow it in all your interactions with the project.