From 9641ed14808bd5d2242f9baaebb806bbef49db74 Mon Sep 17 00:00:00 2001 From: Kwarde Date: Mon, 21 Jul 2025 16:23:40 +0200 Subject: [PATCH] TEST max,maxu (shameless copy,paste,replace) --- src/tests.asm | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/src/tests.asm b/src/tests.asm index 6e032a2..28f802b 100644 --- a/src/tests.asm +++ b/src/tests.asm @@ -157,6 +157,20 @@ section .rodata addTest(minu3, "minu(MIN_UINT64, MAX_UINT64)") addTest(minu4, "minu(-1, 0)") addTest(minu5, "minu(MIN_UINT64, MIN_INT8)") + ;max() + addTestHeader(_max, "max") + addTest(max1, "max(-1337, 1337)") + addTest(max2, "max(MIN_INT64, MAX_INT64)") + addTest(max3, "max(MIN_UINT64, MAX_UINT64)") + addTest(max4, "max(-1, 0)") + addTest(max5, "max(MIN_UINT64, MIN_INT8)") + ;maxu() + addTestHeader(_maxu, "maxu") + addTest(maxu1, "maxu(-1337, 1337)") + addTest(maxu2, "maxu(MIN_INT64, MAX_INT64)") + addTest(maxu3, "maxu(MIN_UINT64, MAX_UINT64)") + addTest(maxu4, "maxu(-1, 0)") + addTest(maxu5, "maxu(MIN_UINT64, MIN_INT8)") section .data @@ -334,6 +348,78 @@ _start: assert MIN_UINT64, je, testMsg_assertIEqual %endif +;--- 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 + +;--- maxu() +%if TEST_maxu + printTestHeader(_maxu) + + ; TEST 1: maxu(-1337, 1337) + printTest(maxu1) + mov rdi, -1337 + mov rsi, 1337 + call maxu + assert -1337, je, testMsg_assertIEqual + ; TEST 2: maxu(MIN_INT64, MAX_INT64) + printTest(maxu2) + mov rdi, MIN_INT64 + mov rsi, MAX_INT64 + call maxu + assert MIN_INT64, je, testMsg_assertIEqual + ; TEST 3: maxu(MIN_UINT64, MAX_UINT64) + printTest(maxu3) + mov rdi, MIN_UINT64 + mov rsi, MAX_UINT64 + call maxu + assert MAX_UINT64, je, testMsg_assertIEqual + ; TEST 4: maxu(-1, 0) + printTest(maxu4) + mov rdi, -1 + xor rsi, rsi + call maxu + assert -1, je, testMsg_assertIEqual + ; TEST 5: maxu(MIN_UINT64, MIN_INT8) + printTest(maxu5) + mov rdi, MIN_UINT64 + mov rsi, MIN_INT8 + call maxu + assert MIN_INT8, je, testMsg_assertIEqual +%endif + ;;; ;;; TEST RESULTS ;;;