From 21187ae663a8450553881851e8450315c8d9ca1c Mon Sep 17 00:00:00 2001 From: Siddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com> Date: Tue, 11 Mar 2025 15:24:57 -0400 Subject: Tests for write line in Dram, memory address wrapping implementation and tests --- tests/utils.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'tests/utils.cc') diff --git a/tests/utils.cc b/tests/utils.cc index 5368204..f0e4c24 100644 --- a/tests/utils.cc +++ b/tests/utils.cc @@ -21,3 +21,45 @@ TEST_CASE("Parse arbitrary fields # two", "[cache]") CHECK(index == 0b01110); CHECK(offset == 0b11); } + +TEST_CASE("wrap address outside upper bound", "[utils]") +{ + int address = MEM_SIZE + 25; + int wrapped = wrap_address(address); + REQUIRE(wrapped == 25); +} + +TEST_CASE("wrap address inside upper bound", "[utils]") +{ + int address = MEM_SIZE - 25; + int wrapped = wrap_address(address); + REQUIRE(wrapped == MEM_SIZE - 25); +} + +TEST_CASE("wrap address at upper bound", "[utils]") +{ + int address = MEM_SIZE; + int wrapped = wrap_address(address); + REQUIRE(wrapped == 0); +} + +TEST_CASE("wrap address lower than 0 with magnitude lesser than mem size", "[utils]") +{ + int address = -10; + int wrapped = wrap_address(address); + REQUIRE(wrapped == MEM_SIZE - 10); +} + +TEST_CASE("wrap address lower than 0 but with magnitude greater than mem size", "[utils]") +{ + int address = -(MEM_SIZE + 10); + int wrapped = wrap_address(address); + REQUIRE(wrapped == MEM_SIZE - 10); +} + +TEST_CASE("wrap address at 0", "[utils]") +{ + int address = 0; + int wrapped = wrap_address(address); + REQUIRE(wrapped == 0); +} \ No newline at end of file -- cgit v1.2.3