From bc20b1ee9a9a0160c6342f214919cc8df6bb66bc Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 12 Mar 2022 13:49:20 +0100 Subject: [PATCH] tests: unit: engine: add 'engine_trade' suite --- tests/unit/engine.cc | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/tests/unit/engine.cc b/tests/unit/engine.cc index 9667aca..5fe2e8e 100644 --- a/tests/unit/engine.cc +++ b/tests/unit/engine.cc @@ -16,20 +16,36 @@ using namespace kraken::parse; namespace { +void do_compare(std::istream& input, std::istream& expected_output, + CrossBehaviour behaviour) { + auto listener = std::make_shared(); + 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) { using namespace std::literals; auto input = std::ifstream{CMAKE_SOURCE_DIR + "/data/inputs/"s + test_name + ".in.csv"}; - auto listener = std::make_shared(); - auto engine = Engine{listener}; - - engine.process_orders(parse_orders(input)); - auto expected_output_file = std::ifstream{ 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 @@ -97,3 +113,11 @@ TEST(engine, shallow_bid) { TEST(engine, 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"); +}