Skip to content

Commit

Permalink
Update reg handler test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
SharafMohamed committed Mar 6, 2025
1 parent 250f173 commit db7bc11
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions tests/test-register-handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ TEST_CASE("`RegisterHandler` tests", "[RegisterHandler]") {
constexpr position_t cAppendPos2{10};
constexpr position_t cAppendPos3{15};

SECTION("Initial state is empty") {
RegisterHandler handler{handler_init(cNumRegisters)};

SECTION("Throws out of range correctly") {
constexpr size_t cInvalidRegId{10};
RegisterHandler const empty_handler{handler_init(0)};

REQUIRE_THROWS_AS(empty_handler.get_reversed_positions(cRegId1), std::out_of_range);
REQUIRE_THROWS_AS(handler.copy_register(cInvalidRegId, cRegId2), std::out_of_range);
REQUIRE_THROWS_AS(handler.copy_register(cRegId1, cInvalidRegId), std::out_of_range);
REQUIRE_THROWS_AS(handler.append_position(cInvalidRegId, cInitialPos1), std::out_of_range);
REQUIRE_THROWS_AS(handler.get_reversed_positions(cInvalidRegId), std::out_of_range);
}

RegisterHandler handler{handler_init(cNumRegisters)};

SECTION("Initial register is empty") {
auto positions{handler.get_reversed_positions(cRegId1)};
REQUIRE(handler.get_reversed_positions(cRegId1).empty());
Expand All @@ -60,15 +66,6 @@ TEST_CASE("`RegisterHandler` tests", "[RegisterHandler]") {
== handler.get_reversed_positions(cRegId2));
}

SECTION("Throws out of range correctly") {
constexpr size_t cInvalidRegId{10};

REQUIRE_THROWS_AS(handler.copy_register(cInvalidRegId, cRegId2), std::out_of_range);
REQUIRE_THROWS_AS(handler.copy_register(cRegId1, cInvalidRegId), std::out_of_range);
REQUIRE_THROWS_AS(handler.append_position(cInvalidRegId, cInitialPos1), std::out_of_range);
REQUIRE_THROWS_AS(handler.get_reversed_positions(cInvalidRegId), std::out_of_range);
}

SECTION("Handles negative position values correctly") {
constexpr size_t cRegId3{2};
constexpr position_t cNegativePos1{-1};
Expand Down

0 comments on commit db7bc11

Please sign in to comment.