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
commitd743af4b5df01e3a75725912bee1d00b8fe573dd (patch)
tree4de529c2e8a762503b99db77efc73cdc98104bb0 /tests/utils.cc
parent97173af3651138db50cc42df25b474af2b6ece43 (diff)
parent92e8c2583695a3bf652e0e8dedb79e7a99922f5f (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