Skip to content

Commit

Permalink
Use mt19937 for reproducible CI
Browse files Browse the repository at this point in the history
  • Loading branch information
pinguin999 committed Jul 23, 2024
1 parent 5eb1a50 commit 9db8f42
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions test/test_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <jngl/message.hpp>
#include <jngl/input.hpp>
#include <jngl/job.hpp>
#include <random>

#include "../src/game.hpp"
#include "../src/interactable_object.hpp"
Expand All @@ -28,14 +29,17 @@ void pac_unload_file(const char* path)
}
#endif

const int SEED = 0;
const int MAX_STEPS = 3000;


using namespace boost::ut;
suite alpaca_test_suite = []
{
"game_play_test"_test = []
{
jngl::setVolume(0);
std::srand(std::time(nullptr));
std::mt19937 gen = std::mt19937(SEED);
#ifdef EMSCRIPTEN
chdir("data");
#elif !defined(ANDROID)
Expand Down Expand Up @@ -75,7 +79,7 @@ suite alpaca_test_suite = []

int i = 0;

while (!(*game->lua_state)["game_finished"] && i < 3000)
while (!(*game->lua_state)["game_finished"] && i < MAX_STEPS)
{
i++;
actions.clear();
Expand Down Expand Up @@ -111,7 +115,7 @@ suite alpaca_test_suite = []

int const min = 0;
int const max = actions.size() - 1;
int const randAction = std::rand() % (max - min + 1) + min;
int const randAction = std::abs(int(gen())) % (max - min + 1) + min;

jngl::debug("RUN: ");
jngl::debugLn(std::get<0>(actions.at(randAction)));
Expand All @@ -128,7 +132,7 @@ suite alpaca_test_suite = []
auto choices = game->getDialogManager()->getChoiceTextsSize();
int const min = 0;
int const max = choices - 1;
int const choice = std::rand() % (max - min + 1) + min;
int const choice = std::abs(int(gen())) % (max - min + 1) + min;
game->getDialogManager()->selectCurrentAnswer(choice);
}
else
Expand All @@ -145,14 +149,14 @@ suite alpaca_test_suite = []

jngl::hideWindow();

expect(neq(i, 3000));
expect(neq(i, MAX_STEPS));
};

"game_save_load_test"_test = []
{
// return; // DISABLED
return; // DISABLED
jngl::setVolume(0);
std::srand(std::time(nullptr));
std::mt19937 gen = std::mt19937(SEED);
#ifdef EMSCRIPTEN
chdir("data");
#elif !defined(ANDROID)
Expand Down Expand Up @@ -229,7 +233,7 @@ suite alpaca_test_suite = []

int const min = 0;
int const max = actions.size() - 1;
int const randAction = rand() % (max - min + 1) + min;
int const randAction = std::abs(int(gen())) % (max - min + 1) + min;

jngl::debug("RUN: ");
jngl::debugLn(std::get<0>(actions.at(randAction)));
Expand All @@ -246,7 +250,7 @@ suite alpaca_test_suite = []
auto choices = game->getDialogManager()->getChoiceTextsSize();
int const min = 0;
int const max = choices - 1;
int const choice = rand() % (max - min + 1) + min;
int const choice = std::abs(int(gen())) % (max - min + 1) + min;
game->getDialogManager()->selectCurrentAnswer(choice);
}
else
Expand All @@ -257,7 +261,7 @@ suite alpaca_test_suite = []
}

game->saveLuaState();
} while (!(*game->lua_state)["game_finished"] && i < 3000);
} while (!(*game->lua_state)["game_finished"] && i < MAX_STEPS);

// expect(eq(game->getInactivLayerBorder(), 2));
jngl::debug("Took: ");
Expand All @@ -266,6 +270,6 @@ suite alpaca_test_suite = []

jngl::hideWindow();

expect(neq(i, 3000));
expect(neq(i, MAX_STEPS));
};
};

0 comments on commit 9db8f42

Please sign in to comment.