From e5ddd16da2f13f27d9d9d9851b8277840cf23c64 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 12 Mar 2022 10:46:23 +0100 Subject: [PATCH] tests: unit: add 'engine' suite --- tests/unit/CMakeLists.txt | 12 +++++ tests/unit/engine.cc | 99 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 tests/unit/engine.cc diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 0529460..57a31d0 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -25,4 +25,16 @@ target_link_libraries(parse_test PRIVATE gtest_discover_tests(parse_test) +add_executable(engine_test engine.cc) +target_link_libraries(engine_test PRIVATE common_options) + +target_link_libraries(engine_test PRIVATE + engine + parse + GTest::gtest + GTest::gtest_main +) + +gtest_discover_tests(engine_test) + endif (${GTest_FOUND}) diff --git a/tests/unit/engine.cc b/tests/unit/engine.cc new file mode 100644 index 0000000..9667aca --- /dev/null +++ b/tests/unit/engine.cc @@ -0,0 +1,99 @@ +#include + +#include + +#include "config.h" +#include "csv/read-csv.hh" +#include "engine/csv-engine-listener.hh" +#include "engine/engine.hh" +#include "parse/parse.hh" + +// Allow namespace pollution in tests for convenience +using namespace kraken; +using namespace kraken::csv; +using namespace kraken::engine; +using namespace kraken::parse; + +namespace { + +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); +} + +} // namespace + +TEST(engine, empty) { + compare("empty"); +} + +TEST(engine, only_one) { + compare("only-one"); +} + +TEST(engine, only_one_cancelled) { + compare("only-one-cancelled"); +} + +TEST(engine, two) { + compare("two"); +} + +TEST(engine, balanced_book_1) { + compare("balanced-book-1"); +} + +TEST(engine, balanced_book_2) { + compare("balanced-book-2"); +} + +TEST(engine, balanced_book_3) { + compare("balanced-book-3"); +} + +TEST(engine, balanced_book_4) { + compare("balanced-book-4"); +} + +TEST(engine, balanced_book_5) { + compare("balanced-book-5"); +} + +TEST(engine, balanced_book_6) { + compare("balanced-book-6"); +} + +TEST(engine, balanced_book_7) { + compare("balanced-book-7"); +} + +TEST(engine, balanced_book_8) { + compare("balanced-book-8"); +} + +TEST(engine, balanced_book_9) { + compare("balanced-book-9"); +} + +TEST(engine, shallow_ask) { + compare("shallow-ask"); +} + +TEST(engine, shallow_bid) { + compare("shallow-bid"); +} + +TEST(engine, tighten_spread_through_new_limit_orders) { + compare("tighten-spread-through-new-limit-orders"); +}