yadro-task/tests/filetape_tests.cpp
erius f8bfc78cad Updated README.md to include additional info about this project
Implemented reading settings from config file
ftsort now outputs total runtime in ms and peak virtual memory usage
Added some error handling
Added documenation to tape_config.h
Changed catch2 cmake dependency to be resolved using FetchContent
Added generate_input test binary to generate big input tape data sets
Header inclusion path changed to _include_ directory, so that tapelib has to be explicitly specified in include directrives
2024-10-28 05:23:42 +03:00

86 lines
2.9 KiB
C++

#include "tapelib/filetape.h"
#include <catch2/catch_test_macros.hpp>
#include <vector>
const static std::vector<uint32_t> TEST_DATA = {1, 12345, 0, 2222222222,
4294967295};
// NOLINTBEGIN(readability-function-cognitive-complexity)
TEST_CASE("Reading data from a FileTape", "[filetape]") {
tape::FileTape tape(TEST_DATA);
SECTION("Read all data sequentially") {
REQUIRE(tape.read() == TEST_DATA[0]);
REQUIRE(tape.seek_forward() == true);
REQUIRE(tape.read() == TEST_DATA[1]);
REQUIRE(tape.seek_forward() == true);
REQUIRE(tape.read() == TEST_DATA[2]);
REQUIRE(tape.seek_forward() == true);
REQUIRE(tape.read() == TEST_DATA[3]);
REQUIRE(tape.seek_forward() == true);
REQUIRE(tape.read() == TEST_DATA[4]);
}
SECTION("Read data non-sequentially") {
REQUIRE(tape.read() == TEST_DATA[0]);
REQUIRE(tape.seek_forward() == true);
REQUIRE(tape.read() == TEST_DATA[1]);
REQUIRE(tape.seek_backwards() == true);
REQUIRE(tape.read() == TEST_DATA[0]);
REQUIRE(tape.seek_forward() == true);
REQUIRE(tape.seek_forward() == true);
REQUIRE(tape.seek_forward() == true);
REQUIRE(tape.read() == TEST_DATA[3]);
REQUIRE(tape.seek_backwards() == true);
REQUIRE(tape.seek_backwards() == true);
REQUIRE(tape.read() == TEST_DATA[1]);
}
}
TEST_CASE("Seeking forward and backwards", "[filetape]") {
tape::FileTape tape(TEST_DATA);
SECTION("Rewinding at the beginning of a file tape") {
REQUIRE(tape.seek_backwards() == false);
REQUIRE(tape.read() == TEST_DATA[0]);
REQUIRE(tape.seek_forward() == true);
REQUIRE(tape.read() == TEST_DATA[1]);
REQUIRE(tape.seek_backwards() == true);
REQUIRE(tape.seek_backwards() == false);
REQUIRE(tape.read() == TEST_DATA[0]);
}
SECTION("Seeking at the end of a file tape") {
const int size = 5;
// seek to end of a file tape
for (int i = 0; i < size - 1; i++) {
REQUIRE(tape.seek_forward() == true);
}
REQUIRE(tape.seek_forward() == false);
REQUIRE(tape.read() == TEST_DATA[4]);
REQUIRE(tape.seek_backwards() == true);
REQUIRE(tape.read() == TEST_DATA[3]);
REQUIRE(tape.seek_forward() == true);
REQUIRE(tape.seek_forward() == false);
REQUIRE(tape.read() == TEST_DATA[4]);
}
}
TEST_CASE("Writing to a file tape", "[filetape]") {
tape::FileTape tape(3);
tape.write(0);
REQUIRE(tape.read() == 0);
tape.seek_forward();
tape.write(1);
REQUIRE(tape.read() == 1);
tape.seek_forward();
tape.write(2);
REQUIRE(tape.read() == 2);
tape.write(3);
REQUIRE(tape.read() == 3);
tape.seek_backwards();
tape.write(4);
REQUIRE(tape.read() == 4);
}
// NOLINTEND(readability-function-cognitive-complexity)