tests: unit: engine: add 'engine_trade' suite

This commit is contained in:
Bruno BELANYI 2022-03-12 13:49:20 +01:00
parent ce9457fabd
commit bc20b1ee9a

View file

@ -16,20 +16,36 @@ using namespace kraken::parse;
namespace { namespace {
void do_compare(std::istream& input, std::istream& expected_output,
CrossBehaviour behaviour) {
auto listener = std::make_shared<CsvEngineListener>();
auto engine = Engine{listener, behaviour};
engine.process_orders(parse_orders(input));
auto expected = read_csv(expected_output, CsvHeader::KEEP);
ASSERT_EQ(listener->output(), expected);
}
void compare(std::string const& test_name) { void compare(std::string const& test_name) {
using namespace std::literals; using namespace std::literals;
auto input = std::ifstream{CMAKE_SOURCE_DIR + "/data/inputs/"s + test_name auto input = std::ifstream{CMAKE_SOURCE_DIR + "/data/inputs/"s + test_name
+ ".in.csv"}; + ".in.csv"};
auto listener = std::make_shared<CsvEngineListener>();
auto engine = Engine{listener};
engine.process_orders(parse_orders(input));
auto expected_output_file = std::ifstream{ auto expected_output_file = std::ifstream{
CMAKE_SOURCE_DIR + "/data/outputs/"s + test_name + ".out.csv"}; CMAKE_SOURCE_DIR + "/data/outputs/"s + test_name + ".out.csv"};
auto expected = read_csv(expected_output_file, CsvHeader::KEEP);
ASSERT_EQ(listener->output(), expected); do_compare(input, expected_output_file, CrossBehaviour::REJECT);
}
void compare_trades(std::string const& test_name) {
using namespace std::literals;
auto input = std::ifstream{CMAKE_SOURCE_DIR + "/data/inputs/"s + test_name
+ ".in.csv"};
auto expected_output_file = std::ifstream{
CMAKE_SOURCE_DIR + "/data/outputs/"s + test_name + ".trades.out.csv"};
do_compare(input, expected_output_file, CrossBehaviour::MATCH);
} }
} // namespace } // namespace
@ -97,3 +113,11 @@ TEST(engine, shallow_bid) {
TEST(engine, tighten_spread_through_new_limit_orders) { TEST(engine, tighten_spread_through_new_limit_orders) {
compare("tighten-spread-through-new-limit-orders"); compare("tighten-spread-through-new-limit-orders");
} }
TEST(engine_trade, balanced_book_3) {
compare_trades("balanced-book-3");
}
TEST(engine_trade, shallow_ask) {
compare_trades("shallow-ask");
}