Skip to content
Snippets Groups Projects
Select Git revision
  • main default protected
1 result

oop1ss24-a2-custom-testcases

  • Forked from an inaccessible project.
    Schwaiger, Simon Josef's avatar
    Schwaiger, Simon Josef authored
    Add tc 38
    
    See merge request B3D2209CD12BEAA2/oop1ss24-a2-custom-testcases!4
    a5d02d65
    History
    Name Last commit Last update
    tc-maker
    testcases
    .gitignore
    README.md

    Custom Testcases for OOP1 A2

    These testcases are from students for students. They should be correct, but that is never guaranteed. Feel free to question the testcases! Also feel free to add testcases if your program is somewhat good.

    The idea is that with enough testcases from different groups, we can eventually find all differences and correct possibly faulty testcases.

    Running these testcases

    To run these testcases, copy the content of the testcases folder into your a2 project folder. Then the folders 16, 17, ... in /tests/ should be where the other testcases are, and the test.toml file updates to include the new testcases.

    The new testcases will appear in the Testreport when you run make test.

    Debugging

    To debug these testcases you can run your program with the right configs and then you can just copy the whole content of input.txt of the corresponding testcase into your console.

    Debugging random number generation

    To test random numbers better, some testcases include prints of how random numbers are generated, like this:

    RANDOM: 6, Generated: 5
    [Dice Roll] 1 d6 resulting in a total value of 5.

    You can replace the following function in the Random.cpp file to also have these prints:

    size_t Random::getRandomNumber(size_t const upper_bound)
    {
      std::uniform_int_distribution<size_t> normal_distribution{1, upper_bound};
      size_t random_number = normal_distribution(mersenne_twister_);
      std::cout << "RANDOM: " << upper_bound << ", Generated: " << random_number << std::endl;
      return random_number;
    }

    Making your own testcases

    Since the a2 program features a random component, you need to set the seed to a fixed value to make the testcases deterministic. This is done by executing export RAND_SEED=1234 in your Linux/WSL/VM terminal once.

    To create a testcase, you run your program, do random stuff, and then "copy" the output into an io.txt file. BUT: spaces at the end of a line are ignored when copying from the terminal, therefore use the following command to execute your program:

    script -c "clear && ./a2 configs/dungeon_config.txt configs/story_config.txt" output.txt

    NOTE: This command should be executed in the tc-maker directory. Also, you may NEVER press backspace (löschen) as it messes the output up.

    This will then create a file called output.txt with the output of your program. After that, we need to bring the output into the correct format. For that, I created a python script format.py. You can run it with python3 format.py in the tc-maker directory. This will create 2 new files io.txt and input.txt with the correct format. There are example files for output.txt, io.txt and input.txt to get an idea of what it should look like.

    Now you can move the io.txt and input.txt files into the correct folder (e.g. testcases/tests/19/) and add the testcase to the test.toml file (just copy and paste an existing testcase and change the number+description).