Skip to content

Commit

Permalink
Clean up register initialization helper; Fix typo.
Browse files Browse the repository at this point in the history
  • Loading branch information
SharafMohamed committed Dec 5, 2024
1 parent 6481e5f commit 6a9a4a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/test-prefix-tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ TEST_CASE("`PrefixTree` operations", "[PrefixTree]") {
PrefixTree tree;

// Test setting position before any insertions
REQUIRE_THROWS_AS(tree.set(cInvaidNodeId, cSetPos4), std::out_of_range);
REQUIRE_THROWS_AS(tree.set(cInvalidNodeId, cSetPos4), std::out_of_range);

// Test setting position just beyond valid range
auto const node_id_1{tree.insert(cRootId, cInsertPos1)};
Expand Down
12 changes: 9 additions & 3 deletions tests/test-register-handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ constexpr size_t cRegId3{2};
constexpr size_t cInvalidRegId{10};

namespace {
auto add_register_to_handler(RegisterHandler& handler) -> void {
for (size_t i{0}; i < cNumRegisters; ++i) {
/**
* @param handler The register handler that will contain the new registers.
* @param num_registers The number of registers to initialize.
*/
auto registers_init(RegisterHandler& handler, size_t num_registers) -> void;

auto registers_init(RegisterHandler& handler, size_t const num_registers) -> void {
for (size_t i{0}; i < num_registers; ++i) {
handler.add_register(i, cInitialPos);
}
}
Expand All @@ -37,7 +43,7 @@ TEST_CASE("`RegisterHandler` tests", "[RegisterHandler]") {
REQUIRE_THROWS_AS(handler.get_reversed_positions(cRegId1), std::out_of_range);
}

add_register_to_handler(handler);
registers_init(handler, cNumRegisters);

SECTION("Set register position correctly") {
handler.set_register(cRegId1, cSetPos1);
Expand Down

0 comments on commit 6a9a4a4

Please sign in to comment.