summaryrefslogtreecommitdiff
path: root/tests/utils.cc
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-03-11 17:24:37 -0400
committerbd <bdunahu@operationnull.com>2025-03-11 17:24:37 -0400
commit282aff5a3d1b6f9678453dfa3e216849d5b1d954 (patch)
tree4de529c2e8a762503b99db77efc73cdc98104bb0 /tests/utils.cc
parentdef2338f8156281e776ec5d60769c3e64b88e65d (diff)
parentf208e63ce553c6144a672cd35da23425fa7f86d1 (diff)
Merge remote-tracking branch 'origin/master' into bdunahu
Diffstat (limited to 'tests/utils.cc')
-rw-r--r--tests/utils.cc42
1 files changed, 42 insertions, 0 deletions
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