Code Monkey home page Code Monkey logo

42_containator's Introduction

Containator

Alt text

Containator is a personnal project that I did with Hélène Herin (@hherin). It’s a tester for ft_containers, a 42 school project, where you have to reimplement some containers from the C++ STL. It will test the 5 following containers :

  • ➡️ Vector
  • ➡️ List
  • ➡️ Stack
  • ➡️ Queue
  • ➡️ Map

You can choose which containers and which methods you want to test. It’s running several hundreads of tests for each of your containers, then doing the same with the real STL containers and making a diff of the two outputs.
Each test on the output has a line number indicating where the test is situated in the test file. That way, you can easily find which test isn't working if an error occured.

How to run it

  1. Git clone the project into your ft_containers repository.

    git clone https://github.com/llefranc/42_Containator.git
  2. Open include_your_files.hpp at the root directory and includes your containers files. It's not a problem if you haven't done all containers, you can later choose which container you want to test. Just comment the container's includes you're missing. You have to include aswell your ft_pair. If you didn't implemented it, you can use my own version (includes_and_utils/my_ft_pair.hpp).

    #include "../42_ft_containers/pair.hpp"
    
    #include "../42_ft_containers/vector.hpp"   // Comment if you don't want to test VECTOR   
    // #include "../42_ft_containers/list.hpp"     // Comment if you don't want to test LIST
    #include "../42_ft_containers/stack.hpp"    // Comment if you don't want to test STACK
    // #include "../42_ft_containers/queue.hpp"    // Comment if you don't want to test QUEUE
    #include "../42_ft_containers/map.hpp"      // Comment if you don't want to test MAP
  3. In the file select_your_tests/select_containers.cpp, you can choose which containers you want to test by commenting the calls to the containers' test functions, and commenting also the code of the test function.

    // ---------------------------------------------------------------------------
    // CHOOSE HERE WHICH CONTAINERS YOU WANT TO TEST. YOU HAVE ALSO TO COMMENT
    // THE WHOLE FUNCTION BELOW.
      
    testVector(arrInt, arrString);  // Comment if you don't want to test VECTOR   
    // testList(arrInt, arrString);    // Comment if you don't want to test LIST   
    testStack(arrInt, arrString);   // Comment if you don't want to test STACK 
    // .... 
    
    // And then commenting the function below
    // ---------------------------------------------------------------------------
    // COMMENT THE WHOLE FUNCTION IF YOU DON'T WANT TO TEST LIST.
    // ---------------------------------------------------------------------------
    // void    testList(const int (&arrInt)[20], const std::string (&arrString)[20])
    // {
    //
    //     std::streambuf *coutbuf = std::cout.rdbuf();
    //     std::ofstream stdFile("results/list_std.txt");
    // ....
  4. In the five others files (select_your_tests/select_xxx_tests.hpp), you can choose for each containers with methods you want to test by commenting the calls to the methods' test functions.

    // In the file selecs_list_tests.hpp, not testing method empty.
    template <typename T>
    void    testNotConstList(T& l, int testNb)
    {
        printContainerInfo<T>("LIST", testNb);
        
        listTest_Size(l);                       //  size
        // listTest_Empty(l);                      //  empty
        listTest_Iterators(l);                  //  iterators / begin / end
        // ....
        ```
    
  5. Run then the shell script to launch the tester.

    ./testContainers.sh
  6. Result outputs of the STL containers and yours will be created in results/ directory. If your output for a container differs from STL container, a diff file will be also created.

    cat results/list_diff.txt

I got some differences with STL containers, how to check my errors more precisely ?

In the files created in results/ directory, line numbers of each test are indicated (+ the name of the method tested). You just have to open the xxx_diff.txt file and look for the line number of the failed test, and then looks directly to the test in the each_tests/ directory.
For example, if you have failed iterators test for list container, diff file will look like this:

# the first result line is FT file, the other STL file
13c13
< line 42: iterators: operator++:             589667777 | # << YOUR FT FILE
---
> line 42: iterators: operator++:             58966     | # << STL FILE (correct result)

You then just have to open each_tests/list_tests.hpp and jump to the line 42 to see the code that created a bug, and then use this piece of code to test it by yourself in order to solve the problem.

Some tips to help you to solve more easily the bugs

🆘 We know that it can be a little bit tricky to make the tester compile the first time. 🆘

It's using a lot of templates functions, and if you have something wrong in your code a lot of compilation error messages will appear. Don't be scared and take the time to look the error messages and find which method isn't compiling.
Try to do more testing by yourself on the errored method to find the problem, fix it and run the tester again.

If you're thinking that there is an error inside the tester, you can check that nothing is wrong by opening each_tests/exec_each_test.cpp file, and commenting all the calls to the FT test functions, and then run again the tester. You will see that with the STL, the tester is compiling normally, so you have something to fix in your code.

42_containator's People

Contributors

hherin avatar llefranc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

hugothms

42_containator's Issues

Unable to test ft::vector without ft::stack

Environment: MacOS Mojave (@42), clang++-9

include_your_files.hpp:

#ifndef INCLUDE_YOUR_FILES_HPP
#define INCLUDE_YOUR_FILES_HPP

// ---------------------------------------------------------------------------
// INSERT HERE THE PATH TO YOUR FILES. COMMENT THE CONTAINERS YOU DON'T WANT 
// TO TEST. FT_PAIR IS MANDATORY TESTER WON'T COMPILE OTHERWISE.

// Mandatory in order to compile the tester. If you don't already have it, 
// you can include my ft_pair ("./includes_and_utils/my_ft_pair.hpp").
#include "./includes_and_utils/my_ft_pair.hpp"

#include "../src/vector.hpp"   // Comment if you don't want to test VECTOR   
//#include "../42_ft_containers/stack.hpp"
//#include "../42_ft_containers/list.hpp"     // Comment if you don't want to test LIST
//#include "../42_ft_containers/stack.hpp"    // Comment if you don't want to test STACK
//#include "../42_ft_containers/queue.hpp"    // Comment if you don't want to test QUEUE
//#include "../42_ft_containers/map.hpp"      // Comment if you don't want to test MAP

// ---------------------------------------------------------------------------

#endif

Compilation error when making:

select_your_tests/select_containers.cpp:131:30: error: no template named 'stack' in namespace 'ft'; did you mean 'std::stack'?
    constructStackQueue<int, ft::stack<int, std::list<int> >, std::list<int> >(arrInt, testNonConstStack<ft::stack<int, std::list<int> > >);
                             ^~~~~~~~~
                             std::stack
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/stack:113:28: note: 'std::stack' declared here
class _LIBCPP_TEMPLATE_VIS stack
                           ^
select_your_tests/select_containers.cpp:131:106: error: no template named 'stack' in namespace 'ft'; did you mean 'std::stack'?
    constructStackQueue<int, ft::stack<int, std::list<int> >, std::list<int> >(arrInt, testNonConstStack<ft::stack<int, std::list<int> > >);
                                                                                                         ^~~~~~~~~
                                                                                                         std::stack
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/stack:113:28: note: 'std::stack' declared here
class _LIBCPP_TEMPLATE_VIS stack
                           ^
select_your_tests/select_containers.cpp:132:38: error: no template named 'stack' in namespace 'ft'; did you mean 'std::stack'?
    constructStackQueue<std::string, ft::stack<std::string, std::list<std::string> >, std::list<std::string> >(arrString, testNonConstStack<ft::stack<std::string, std::list<std::string> > >);
                                     ^~~~~~~~~
                                     std::stack
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/stack:113:28: note: 'std::stack' declared here
class _LIBCPP_TEMPLATE_VIS stack
                           ^
select_your_tests/select_containers.cpp:132:141: error: no template named 'stack' in namespace 'ft'; did you mean 'std::stack'?
    constructStackQueue<std::string, ft::stack<std::string, std::list<std::string> >, std::list<std::string> >(arrString, testNonConstStack<ft::stack<std::string, std::list<std::string> > >);
                                                                                                                                            ^~~~~~~~~
                                                                                                                                            std::stack
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/stack:113:28: note: 'std::stack' declared here
class _LIBCPP_TEMPLATE_VIS stack
                           ^
4 errors generated.
make: *** [select_your_tests/select_containers.o] Error 1

After quick investigation the problem is coming from select_your_tests/select_containers.cpp where most tests are commented except stack and vector. By commenting stack it works as expected. Maybe an issue with a shell script, did not take time to figure it out.

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.