#include "tapelib/filetape.h" #include "tapelib/tape.h" #include "tapelib/tape_util.h" #include #include #include #include using std::vector; using namespace tape; const static vector TEST_DATA = {123, 26, 87, 266, 111, 234, 6, 63, 28, 1, 90, 33}; const static vector TEST_DATA_SORTED = {1, 6, 26, 28, 33, 63, 87, 90, 111, 123, 234, 266}; vector read_from_tape_backwards(Tape &tape) { vector data; do { data.push_back(tape.read()); } while (tape.seek_backwards()); std::ranges::reverse(data); return data; } // NOLINTBEGIN TEST_CASE("Sorting FileTape with external sort", "[sort]") { FileTape input(TEST_DATA); FileTape output(input); SECTION("Sorting with no limitations") { external_sort(input, output, FILETAPE_FACTORY); REQUIRE(read_from_tape_backwards(output) == TEST_DATA_SORTED); } SECTION("Sorting with 4 elements in memory limit") { external_sort(input, output, FILETAPE_FACTORY, 4); REQUIRE(read_from_tape_backwards(output) == TEST_DATA_SORTED); } SECTION("Sorting with 9 elements in memory limit") { external_sort(input, output, FILETAPE_FACTORY, 9); REQUIRE(read_from_tape_backwards(output) == TEST_DATA_SORTED); } SECTION("Sorting with vector size elements in memory limit") { external_sort(input, output, FILETAPE_FACTORY, TEST_DATA.size()); REQUIRE(read_from_tape_backwards(output) == TEST_DATA_SORTED); } SECTION("Sorting with 1000 elements in memory limit") { external_sort(input, output, FILETAPE_FACTORY, 1000); REQUIRE(read_from_tape_backwards(output) == TEST_DATA_SORTED); } SECTION("Sorting with 1 elements in memory limit") { external_sort(input, output, FILETAPE_FACTORY, 1); REQUIRE(read_from_tape_backwards(output) == TEST_DATA_SORTED); } } // NOLINTEND