Wrappers (%define) for macro assert
This commit is contained in:
135
src/tests.asm
135
src/tests.asm
@@ -40,6 +40,19 @@
|
|||||||
nop
|
nop
|
||||||
%endmacro
|
%endmacro
|
||||||
|
|
||||||
|
%define assert_eq(val) assert val, je, testMsg_assertIEqual
|
||||||
|
%define assert_neq(val) assert val, jne, testMsg_assertINequal
|
||||||
|
%define assert_less(val) assert val, jl, testMsg_assertILess
|
||||||
|
%define assert_less_eq(val) assert val, jle, testMsg_assertILessE
|
||||||
|
%define assert_more(val) assert val, jg, testMsg_assertIMore
|
||||||
|
%define assert_more_eq(val) assert val, jge, testMsg_assertIMoreE
|
||||||
|
%define assert_u_eq(val) assert val, je, testMsg_assertUEqual
|
||||||
|
%define assert_u_neq(val) assert val, jne, testMsg_assertUNequal
|
||||||
|
%define assert_u_less(val) assert val, jb, testMsg_assertULess
|
||||||
|
%define assert_u_less_eq(val) assert val, jbe, testMsg_assertULessE
|
||||||
|
%define assert_u_more(val) assert val, ja, testMsg_assertUMore
|
||||||
|
%define assert_u_more_eq(val) assert val, jae, testMsg_assertUMoreE
|
||||||
|
|
||||||
;core.asm
|
;core.asm
|
||||||
extern exit
|
extern exit
|
||||||
extern islower
|
extern islower
|
||||||
@@ -203,74 +216,38 @@ _start:
|
|||||||
printTest(islower_d)
|
printTest(islower_d)
|
||||||
mov rdi, 'd'
|
mov rdi, 'd'
|
||||||
call islower
|
call islower
|
||||||
assert 1, je, testMsg_assertIEqual
|
assert_eq(1)
|
||||||
; TEST 2: islower('D')
|
; TEST 2: islower('D')
|
||||||
printTest(islower_D)
|
printTest(islower_D)
|
||||||
mov rdi, 'D'
|
mov rdi, 'D'
|
||||||
call islower
|
call islower
|
||||||
assert 0, je, testMsg_assertIEqual
|
assert_eq(0)
|
||||||
; TEST 3: islower('!')
|
; TEST 3: islower('!')
|
||||||
printTest(islower_em)
|
printTest(islower_em)
|
||||||
mov rdi, '!'
|
mov rdi, '!'
|
||||||
call islower
|
call islower
|
||||||
assert 0, je, testMsg_assertIEqual
|
assert_eq(0)
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
;--- isupper()
|
;--- isupper()
|
||||||
%if TEST_isupper
|
%if TEST_isupper
|
||||||
printTestHeader(_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')
|
; TEST 1: isupper('d')
|
||||||
printTest(isupper_d)
|
printTest(isupper_d)
|
||||||
mov rdi, 'd'
|
mov rdi, 'd'
|
||||||
call isupper
|
call isupper
|
||||||
assert 0, je, testMsg_assertIEqual
|
assert_eq(0)
|
||||||
; TEST 2: isupper('D')
|
; TEST 2: isupper('D')
|
||||||
printTest(isupper_D)
|
printTest(isupper_D)
|
||||||
mov rdi, 'D'
|
mov rdi, 'D'
|
||||||
call isupper
|
call isupper
|
||||||
assert 1, je, testMsg_assertIEqual
|
assert_eq(1)
|
||||||
; TEST 3: isupper('!')
|
; TEST 3: isupper('!')
|
||||||
printTest(isupper_em)
|
printTest(isupper_em)
|
||||||
mov rdi, '!'
|
mov rdi, '!'
|
||||||
call isupper
|
call isupper
|
||||||
assert 0, je, testMsg_assertIEqual
|
assert_eq(0)
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
;--- tolower()
|
;--- tolower()
|
||||||
@@ -281,22 +258,22 @@ _start:
|
|||||||
printTest(tolower_d)
|
printTest(tolower_d)
|
||||||
mov rdi, 'd'
|
mov rdi, 'd'
|
||||||
call tolower
|
call tolower
|
||||||
assert 'd', je, testMsg_assertIEqual
|
assert_eq('d')
|
||||||
; TEST 2: tolower('D')
|
; TEST 2: tolower('D')
|
||||||
printTest(tolower_D)
|
printTest(tolower_D)
|
||||||
mov rdi, 'D'
|
mov rdi, 'D'
|
||||||
call tolower
|
call tolower
|
||||||
assert 'd', je, testMsg_assertIEqual
|
assert_eq('d')
|
||||||
; TEST 3: tolower('!')
|
; TEST 3: tolower('!')
|
||||||
printTest(tolower_em)
|
printTest(tolower_em)
|
||||||
mov rdi, '!'
|
mov rdi, '!'
|
||||||
call tolower
|
call tolower
|
||||||
assert '!', je, testMsg_assertIEqual
|
assert_eq('!')
|
||||||
; TEST 4: tolower('}')
|
; TEST 4: tolower('}')
|
||||||
printTest(tolower_cb)
|
printTest(tolower_cb)
|
||||||
mov rdi, '}'
|
mov rdi, '}'
|
||||||
call tolower
|
call tolower
|
||||||
assert '}', je, testMsg_assertIEqual
|
assert_eq('}')
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
;--- toupper()
|
;--- toupper()
|
||||||
@@ -307,22 +284,22 @@ _start:
|
|||||||
printTest(toupper_d)
|
printTest(toupper_d)
|
||||||
mov rdi, 'd'
|
mov rdi, 'd'
|
||||||
call toupper
|
call toupper
|
||||||
assert 'D', je, testMsg_assertIEqual
|
assert_eq('D')
|
||||||
; TEST 2: toupper('D')
|
; TEST 2: toupper('D')
|
||||||
printTest(toupper_D)
|
printTest(toupper_D)
|
||||||
mov rdi, 'D'
|
mov rdi, 'D'
|
||||||
call toupper
|
call toupper
|
||||||
assert 'D', je, testMsg_assertIEqual
|
assert_eq('D')
|
||||||
; TEST 3: toupper('!')
|
; TEST 3: toupper('!')
|
||||||
printTest(toupper_em)
|
printTest(toupper_em)
|
||||||
mov rdi, '!'
|
mov rdi, '!'
|
||||||
call toupper
|
call toupper
|
||||||
assert '!', je, testMsg_assertIEqual
|
assert_eq('!')
|
||||||
; TEST 4: toupper('}')
|
; TEST 4: toupper('}')
|
||||||
printTest(toupper_cb)
|
printTest(toupper_cb)
|
||||||
mov rdi, '}'
|
mov rdi, '}'
|
||||||
call toupper
|
call toupper
|
||||||
assert '}', je, testMsg_assertIEqual
|
assert_eq('}')
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
;--- min()
|
;--- min()
|
||||||
@@ -334,31 +311,31 @@ _start:
|
|||||||
mov rdi, -1337
|
mov rdi, -1337
|
||||||
mov rsi, 1337
|
mov rsi, 1337
|
||||||
call min
|
call min
|
||||||
assert -1337, je, testMsg_assertIEqual
|
assert_eq(-1337)
|
||||||
; TEST 2: min(MIN_INT64, MAX_INT64)
|
; TEST 2: min(MIN_INT64, MAX_INT64)
|
||||||
printTest(min2)
|
printTest(min2)
|
||||||
mov rdi, MIN_INT64
|
mov rdi, MIN_INT64
|
||||||
mov rsi, MAX_INT64
|
mov rsi, MAX_INT64
|
||||||
call min
|
call min
|
||||||
assert MIN_INT64, je, testMsg_assertIEqual
|
assert_eq(MIN_INT64)
|
||||||
; TEST 3: min(MIN_UINT64, MAX_UINT64)
|
; TEST 3: min(MIN_UINT64, MAX_UINT64)
|
||||||
printTest(min3)
|
printTest(min3)
|
||||||
mov rdi, MIN_UINT64
|
mov rdi, MIN_UINT64
|
||||||
mov rsi, MAX_UINT64
|
mov rsi, MAX_UINT64
|
||||||
call min
|
call min
|
||||||
assert MAX_UINT64, je, testMsg_assertIEqual
|
assert_eq(MAX_UINT64)
|
||||||
; TEST 4: min(-1, 0)
|
; TEST 4: min(-1, 0)
|
||||||
printTest(min4)
|
printTest(min4)
|
||||||
mov rdi, -1
|
mov rdi, -1
|
||||||
xor rsi, rsi
|
xor rsi, rsi
|
||||||
call min
|
call min
|
||||||
assert -1, je, testMsg_assertIEqual
|
assert_eq(-1)
|
||||||
; TEST 5: min(MIN_UINT64, MIN_INT8)
|
; TEST 5: min(MIN_UINT64, MIN_INT8)
|
||||||
printTest(min5)
|
printTest(min5)
|
||||||
mov rdi, MIN_UINT64
|
mov rdi, MIN_UINT64
|
||||||
mov rsi, MIN_INT8
|
mov rsi, MIN_INT8
|
||||||
call min
|
call min
|
||||||
assert MIN_INT8, je, testMsg_assertIEqual
|
assert_eq(MIN_INT8)
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
;--- minu()
|
;--- minu()
|
||||||
@@ -370,31 +347,31 @@ _start:
|
|||||||
mov rdi, -1337
|
mov rdi, -1337
|
||||||
mov rsi, 1337
|
mov rsi, 1337
|
||||||
call minu
|
call minu
|
||||||
assert 1337, je, testMsg_assertUEqual
|
assert_u_eq(1337)
|
||||||
; TEST 2: minu(MIN_INT64, MAX_INT64)
|
; TEST 2: minu(MIN_INT64, MAX_INT64)
|
||||||
printTest(minu2)
|
printTest(minu2)
|
||||||
mov rdi, MIN_INT64
|
mov rdi, MIN_INT64
|
||||||
mov rsi, MAX_INT64
|
mov rsi, MAX_INT64
|
||||||
call minu
|
call minu
|
||||||
assert MAX_INT64, je, testMsg_assertUEqual
|
assert_u_eq(MAX_INT64)
|
||||||
; TEST 3: minu(MIN_UINT64, MAX_UINT64)
|
; TEST 3: minu(MIN_UINT64, MAX_UINT64)
|
||||||
printTest(minu3)
|
printTest(minu3)
|
||||||
mov rdi, MIN_UINT64
|
mov rdi, MIN_UINT64
|
||||||
mov rsi, MAX_UINT64
|
mov rsi, MAX_UINT64
|
||||||
call minu
|
call minu
|
||||||
assert MIN_UINT64, je, testMsg_assertUEqual
|
assert_u_eq(MIN_UINT64)
|
||||||
; TEST 4: minu(-1, 0)
|
; TEST 4: minu(-1, 0)
|
||||||
printTest(minu4)
|
printTest(minu4)
|
||||||
mov rdi, -1
|
mov rdi, -1
|
||||||
xor rsi, rsi
|
xor rsi, rsi
|
||||||
call minu
|
call minu
|
||||||
assert 0, je, testMsg_assertUEqual
|
assert_u_eq(0)
|
||||||
; TEST 5: minu(MIN_UINT64, MIN_INT8)
|
; TEST 5: minu(MIN_UINT64, MIN_INT8)
|
||||||
printTest(minu5)
|
printTest(minu5)
|
||||||
mov rdi, MIN_UINT64
|
mov rdi, MIN_UINT64
|
||||||
mov rsi, MIN_INT8
|
mov rsi, MIN_INT8
|
||||||
call minu
|
call minu
|
||||||
assert MIN_UINT64, je, testMsg_assertUEqual
|
assert_u_eq(MIN_UINT64)
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
;--- max()
|
;--- max()
|
||||||
@@ -406,31 +383,31 @@ _start:
|
|||||||
mov rdi, -1337
|
mov rdi, -1337
|
||||||
mov rsi, 1337
|
mov rsi, 1337
|
||||||
call max
|
call max
|
||||||
assert 1337, je, testMsg_assertIEqual
|
assert_eq(1337)
|
||||||
; TEST 2: max(MIN_INT64, MAX_INT64)
|
; TEST 2: max(MIN_INT64, MAX_INT64)
|
||||||
printTest(max2)
|
printTest(max2)
|
||||||
mov rdi, MIN_INT64
|
mov rdi, MIN_INT64
|
||||||
mov rsi, MAX_INT64
|
mov rsi, MAX_INT64
|
||||||
call max
|
call max
|
||||||
assert MAX_INT64, je, testMsg_assertIEqual
|
assert_eq(MAX_INT64)
|
||||||
; TEST 3: max(MIN_UINT64, MAX_UINT64)
|
; TEST 3: max(MIN_UINT64, MAX_UINT64)
|
||||||
printTest(max3)
|
printTest(max3)
|
||||||
mov rdi, MIN_UINT64
|
mov rdi, MIN_UINT64
|
||||||
mov rsi, MAX_UINT64
|
mov rsi, MAX_UINT64
|
||||||
call max
|
call max
|
||||||
assert MIN_UINT64, je, testMsg_assertIEqual
|
assert_eq(MIN_UINT64)
|
||||||
; TEST 4: max(-1, 0)
|
; TEST 4: max(-1, 0)
|
||||||
printTest(max4)
|
printTest(max4)
|
||||||
mov rdi, -1
|
mov rdi, -1
|
||||||
xor rsi, rsi
|
xor rsi, rsi
|
||||||
call max
|
call max
|
||||||
assert 0, je, testMsg_assertIEqual
|
assert_eq(0)
|
||||||
; TEST 5: max(MIN_UINT64, MIN_INT8)
|
; TEST 5: max(MIN_UINT64, MIN_INT8)
|
||||||
printTest(max5)
|
printTest(max5)
|
||||||
mov rdi, MIN_UINT64
|
mov rdi, MIN_UINT64
|
||||||
mov rsi, MIN_INT8
|
mov rsi, MIN_INT8
|
||||||
call max
|
call max
|
||||||
assert MIN_UINT64, je, testMsg_assertIEqual
|
assert_eq(MIN_UINT64)
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
;--- maxu()
|
;--- maxu()
|
||||||
@@ -442,31 +419,31 @@ _start:
|
|||||||
mov rdi, -1337
|
mov rdi, -1337
|
||||||
mov rsi, 1337
|
mov rsi, 1337
|
||||||
call maxu
|
call maxu
|
||||||
assert -1337, je, testMsg_assertUEqual
|
assert_u_eq(-1337)
|
||||||
; TEST 2: maxu(MIN_INT64, MAX_INT64)
|
; TEST 2: maxu(MIN_INT64, MAX_INT64)
|
||||||
printTest(maxu2)
|
printTest(maxu2)
|
||||||
mov rdi, MIN_INT64
|
mov rdi, MIN_INT64
|
||||||
mov rsi, MAX_INT64
|
mov rsi, MAX_INT64
|
||||||
call maxu
|
call maxu
|
||||||
assert MIN_INT64, je, testMsg_assertUEqual
|
assert_u_eq(MIN_INT64)
|
||||||
; TEST 3: maxu(MIN_UINT64, MAX_UINT64)
|
; TEST 3: maxu(MIN_UINT64, MAX_UINT64)
|
||||||
printTest(maxu3)
|
printTest(maxu3)
|
||||||
mov rdi, MIN_UINT64
|
mov rdi, MIN_UINT64
|
||||||
mov rsi, MAX_UINT64
|
mov rsi, MAX_UINT64
|
||||||
call maxu
|
call maxu
|
||||||
assert MAX_UINT64, je, testMsg_assertUEqual
|
assert_u_eq(MAX_UINT64)
|
||||||
; TEST 4: maxu(-1, 0)
|
; TEST 4: maxu(-1, 0)
|
||||||
printTest(maxu4)
|
printTest(maxu4)
|
||||||
mov rdi, -1
|
mov rdi, -1
|
||||||
xor rsi, rsi
|
xor rsi, rsi
|
||||||
call maxu
|
call maxu
|
||||||
assert -1, je, testMsg_assertUEqual
|
assert_u_eq(-1)
|
||||||
; TEST 5: maxu(MIN_UINT64, MIN_INT8)
|
; TEST 5: maxu(MIN_UINT64, MIN_INT8)
|
||||||
printTest(maxu5)
|
printTest(maxu5)
|
||||||
mov rdi, MIN_UINT64
|
mov rdi, MIN_UINT64
|
||||||
mov rsi, MIN_INT8
|
mov rsi, MIN_INT8
|
||||||
call maxu
|
call maxu
|
||||||
assert MIN_INT8, je, testMsg_assertUEqual
|
assert_u_eq(MIN_INT8)
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
;--- clamp()
|
;--- clamp()
|
||||||
@@ -479,35 +456,35 @@ _start:
|
|||||||
mov rsi, -1000
|
mov rsi, -1000
|
||||||
mov rdx, 1000
|
mov rdx, 1000
|
||||||
call clamp
|
call clamp
|
||||||
assert 50, je, testMsg_assertIEqual
|
assert_eq(50)
|
||||||
; TEST 2: clamp(-1337, -1000, 1000)
|
; TEST 2: clamp(-1337, -1000, 1000)
|
||||||
printTest(clamp2)
|
printTest(clamp2)
|
||||||
mov rdi, -1337
|
mov rdi, -1337
|
||||||
mov rsi, -1000
|
mov rsi, -1000
|
||||||
mov rdx, 1000
|
mov rdx, 1000
|
||||||
call clamp
|
call clamp
|
||||||
assert -1000, je, testMsg_assertIEqual
|
assert_eq(-1000)
|
||||||
; TEST 3: clamp(1337, -1000, 1000)
|
; TEST 3: clamp(1337, -1000, 1000)
|
||||||
printTest(clamp3)
|
printTest(clamp3)
|
||||||
mov rdi, 1337
|
mov rdi, 1337
|
||||||
mov rsi, -1000
|
mov rsi, -1000
|
||||||
mov rdx, 1000
|
mov rdx, 1000
|
||||||
call clamp
|
call clamp
|
||||||
assert 1000, je, testMsg_assertIEqual
|
assert_eq(1000)
|
||||||
; TEST 4: clamp(MAX_INT64, -10, 10)
|
; TEST 4: clamp(MAX_INT64, -10, 10)
|
||||||
printTest(clamp4)
|
printTest(clamp4)
|
||||||
mov rdi, MAX_INT64
|
mov rdi, MAX_INT64
|
||||||
mov rsi, -10
|
mov rsi, -10
|
||||||
mov rdx, 10
|
mov rdx, 10
|
||||||
call clamp
|
call clamp
|
||||||
assert 10, je, testMsg_assertIEqual
|
assert_eq(10)
|
||||||
; TEST 5: clamp(-1, MIN_UINT32, MAX_UINT32)
|
; TEST 5: clamp(-1, MIN_UINT32, MAX_UINT32)
|
||||||
printTest(clamp5)
|
printTest(clamp5)
|
||||||
mov rdi, -1
|
mov rdi, -1
|
||||||
mov rsi, MIN_UINT32
|
mov rsi, MIN_UINT32
|
||||||
mov rdx, MAX_UINT32
|
mov rdx, MAX_UINT32
|
||||||
call clamp
|
call clamp
|
||||||
assert MIN_UINT32, je, testMsg_assertIEqual
|
assert_eq(MIN_UINT32)
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
;--- clampu()
|
;--- clampu()
|
||||||
@@ -520,28 +497,28 @@ _start:
|
|||||||
mov rsi, 1
|
mov rsi, 1
|
||||||
mov rdx, 1000
|
mov rdx, 1000
|
||||||
call clampu
|
call clampu
|
||||||
assert 50, je, testMsg_assertUEqual
|
assert_u_eq(50)
|
||||||
; TEST 2: clampu(0, 1, 1000)
|
; TEST 2: clampu(0, 1, 1000)
|
||||||
printTest(clampu2)
|
printTest(clampu2)
|
||||||
xor rdi, rdi
|
xor rdi, rdi
|
||||||
mov rsi, 1
|
mov rsi, 1
|
||||||
mov rdx, 1000
|
mov rdx, 1000
|
||||||
call clampu
|
call clampu
|
||||||
assert 1, je, testMsg_assertUEqual
|
assert_u_eq(1)
|
||||||
; TEST 3: clampu(1337, 1, 1000)
|
; TEST 3: clampu(1337, 1, 1000)
|
||||||
printTest(clampu3)
|
printTest(clampu3)
|
||||||
mov rdi, 1337
|
mov rdi, 1337
|
||||||
mov rsi, 1
|
mov rsi, 1
|
||||||
mov rdx, 1000
|
mov rdx, 1000
|
||||||
call clampu
|
call clampu
|
||||||
assert 1000, je, testMsg_assertUEqual
|
assert_u_eq(1000)
|
||||||
; TEST 4: clampu(MAX_UINT64, 0, MAX_UINT32)
|
; TEST 4: clampu(MAX_UINT64, 0, MAX_UINT32)
|
||||||
printTest(clampu4)
|
printTest(clampu4)
|
||||||
mov rdi, MAX_UINT64
|
mov rdi, MAX_UINT64
|
||||||
xor rsi, rsi
|
xor rsi, rsi
|
||||||
mov rdx, MAX_UINT32
|
mov rdx, MAX_UINT32
|
||||||
call clampu
|
call clampu
|
||||||
assert MAX_UINT32, je, testMsg_assertUEqual
|
assert_u_eq(MAX_UINT32)
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
|
Reference in New Issue
Block a user