From 1b3f4c1b99a5865d593bf783dcf09a60fddc62e1 Mon Sep 17 00:00:00 2001 From: Kwarde Date: Mon, 21 Jul 2025 16:29:22 +0200 Subject: [PATCH] TEST clamp() --- src/tests.asm | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/src/tests.asm b/src/tests.asm index 28f802b..e3cd7eb 100644 --- a/src/tests.asm +++ b/src/tests.asm @@ -171,6 +171,13 @@ section .rodata addTest(maxu3, "maxu(MIN_UINT64, MAX_UINT64)") addTest(maxu4, "maxu(-1, 0)") addTest(maxu5, "maxu(MIN_UINT64, MIN_INT8)") + ;clamp() + addTestHeader(_clamp, "clamp") + addTest(clamp1, "clamp(50, -1000, 1000)") + addTest(clamp2, "clamp(-1337, -1000, 1000)") + addTest(clamp3, "clamp(1337, -1000, 1000)") + addTest(clamp4, "clamp(MAX_INT64, -10, 10)") + addTest(clamp5, "clamp(-1, MIN_UINT32, MAX_UINT32)") section .data @@ -206,6 +213,42 @@ _start: ;--- isupper() %if TEST_isupper printTestHeader(_isupper) +;--- max() +%if TEST_max + printTestHeader(_max) + + ; TEST 1: max(-1337, 1337) + printTest(max1) + mov rdi, -1337 + mov rsi, 1337 + call max + assert 1337, je, testMsg_assertIEqual + ; TEST 2: max(MIN_INT64, MAX_INT64) + printTest(max2) + mov rdi, MIN_INT64 + mov rsi, MAX_INT64 + call max + assert MAX_INT64, je, testMsg_assertIEqual + ; TEST 3: max(MIN_UINT64, MAX_UINT64) + printTest(max3) + mov rdi, MIN_UINT64 + mov rsi, MAX_UINT64 + call max + assert MIN_UINT64, je, testMsg_assertIEqual + ; TEST 4: max(-1, 0) + printTest(max4) + mov rdi, -1 + xor rsi, rsi + call max + assert 0, je, testMsg_assertIEqual + ; TEST 5: max(MIN_UINT64, MIN_INT8) + printTest(max5) + mov rdi, MIN_UINT64 + mov rsi, MIN_INT8 + call max + assert MIN_UINT64, je, testMsg_assertIEqual +%endif + ; TEST 1: isupper('d') printTest(isupper_d) @@ -420,6 +463,47 @@ _start: assert MIN_INT8, je, testMsg_assertIEqual %endif +;--- clamp() +%if TEST_clamp + printTestHeader(_clamp) + + ; TEST 1: clamp(50, -1000, 1000) + printTest(clamp1) + mov rdi, 50 + mov rsi, -1000 + mov rdx, 1000 + call clamp + assert 50, je, testMsg_assertIEqual + ; TEST 2: clamp(-1337, -1000, 1000) + printTest(clamp2) + mov rdi, -1337 + mov rsi, -1000 + mov rdx, 1000 + call clamp + assert -1000, je, testMsg_assertIEqual + ; TEST 3: clamp(1337, -1000, 1000) + printTest(clamp3) + mov rdi, 1337 + mov rsi, -1000 + mov rdx, 1000 + call clamp + assert 1000, je, testMsg_assertIEqual + ; TEST 4: clamp(MAX_INT64, -10, 10) + printTest(clamp4) + mov rdi, MAX_INT64 + mov rsi, -10 + mov rdx, 10 + call clamp + assert 10, je, testMsg_assertIEqual + ; TEST 5: clamp(-1, MIN_UINT32, MAX_UINT32) + printTest(clamp5) + mov rdi, -1 + mov rsi, MIN_UINT32 + mov rdx, MAX_UINT32 + call clamp + assert MIN_UINT32, je, testMsg_assertIEqual +%endif + ;;; ;;; TEST RESULTS ;;;