Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions sim_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <iostream>
#include <exception>
#include <sstream>
#include <regex>
#include "tyrant.h"
#include "tyrant_optimize.h"
#include "sim.h"
Expand Down Expand Up @@ -238,6 +239,17 @@ inline double time_ml(std::string gnt1, std::string gnt2)
return std::get<2>(result);
}

inline bool try_get_skipped_simulations(std::string const& output, unsigned long& skipped_simulations)
{
std::smatch matches;
if (std::regex_search(output, matches, std::regex("Evaluated [0-9]+ decks \\([0-9]+ \\+ ([0-9]+) simulations\\)\\.")))
{
skipped_simulations = std::stoul(matches[1].str());
return true;
}
return false;
}

inline void genetic(std::string gnt1, std::string gnt2)
{
string s = std::to_string(iter);
Expand Down Expand Up @@ -526,6 +538,24 @@ BOOST_AUTO_TEST_CASE(test_db_scaling)
BOOST_CHECK_MESSAGE(t1 > t2, "DB time improvement failed: " + std::to_string(t1) + " > " + std::to_string(t2));
}
BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(test_db_skipped_counter)
BOOST_AUTO_TEST_CASE(test_db_skipped_counter_on_hit)
{
iter = 1;
const char *warmup_argv[] = {"tuo", "Mission#134", "Mission#135", "climb", "1", "seed", "1", "prefix", "tests/db/", "db", "no-db-load"};
Result warmup(run_sim(sizeof(warmup_argv) / sizeof(*warmup_argv), warmup_argv));
unsigned long warmup_skipped{0};
BOOST_REQUIRE_MESSAGE(try_get_skipped_simulations(std::get<1>(warmup), warmup_skipped), "Failed to parse skipped simulations from warmup output");
BOOST_CHECK_MESSAGE(warmup_skipped == 0, "Expected zero skipped simulations for warmup no-db-load run, got " + std::to_string(warmup_skipped));

const char *cached_argv[] = {"tuo", "Mission#134", "Mission#135", "beam", "1", "seed", "1", "prefix", "tests/db/", "db"};
Result cached(run_sim(sizeof(cached_argv) / sizeof(*cached_argv), cached_argv));
unsigned long cached_skipped{0};
BOOST_REQUIRE_MESSAGE(try_get_skipped_simulations(std::get<1>(cached), cached_skipped), "Failed to parse skipped simulations from cached output");
BOOST_CHECK_MESSAGE(cached_skipped > 0, "Expected skipped simulations to include DB-hit results, got " + std::to_string(cached_skipped) + ". Warmup skipped: " + std::to_string(warmup_skipped));
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(test_ml)
Expand Down
Loading