History

testing number boundaries

mag committed 3 years ago

Commit e119dfa1 parent cabb1a11 file · +59 −0Browse files

Showing the changes to test (1 of 1 file). Show all

Unified · Split

test/number-boundaries.lsp+59−0
@@ -0,0 +1,59 @@
1
2; NUMBER BOUNDARIES ------------------------------------------------------------
3(define-macro (half-max-signed numtype)
4 (list 'ash (list numtype 1)
5 (list '- (list '* 8 (list 'sizeof (list 'quote numtype))) 2)))
6
7(define-macro (high-border-signed numtype)
8 (list '+ (list '- (list 'half-max-signed numtype) 1)
9 (list 'half-max-signed numtype)))
10
11(define-macro (low-border-signed numtype)
12 (list '- -1 (list 'high-border-signed numtype)))
13
14(define-macro (low-border numtype)
15 (list 'if (list '< (list numtype -1) 1)
16 (list 'low-border-signed numtype)
17 (list numtype 0)))
18
19(define-macro (high-border numtype)
20 (list 'lognot (list 'low-border numtype)))
21 ;(list numtype (list 'lognot (list 'low-border numtype))))
22
23(define-macro (number-borders numtype)
24 (list 'cons (list 'low-border numtype)
25 (list 'high-border numtype)))
26
27; TESTS ------------------------------------------------------------------------
28(princ "---\n")
29(princ "int8 : " (number-borders int8) "\n")
30(princ "int16 : " (number-borders int16) "\n")
31(princ "int32 : " (number-borders int32) "\n")
32(princ "int64 : " (number-borders int64) "\n")
33(princ "uint8 : " (number-borders uint8) "\n")
34(princ "uint16 : " (number-borders uint16) "\n")
35(princ "uint32 : " (number-borders uint32) "\n")
36(princ "uint64 : " (number-borders uint64) "\n")
37(princ "---\n")
38
39(assert (= 128 (+ (high-border int8) 1)))
40(assert (= -129 (- (low-border int8) 1)))
41(assert (= 32768 (+ (high-border int16) 1)))
42(assert (= -32769 (- (low-border int16) 1)))
43(assert (= 2147483648 (+ (high-border int32) 1)))
44(assert (= -2147483649 (- (low-border int32) 1)))
45(assert (= 9223372036854775808 (+ (high-border int64) 1)))
46;(assert (= -9223372036854775809 (- (low-border int64) 1))) ;OVERFLOW
47
48(assert (= 256 (+ (high-border uint8) 1)))
49(assert (= -1 (- (low-border uint8) 1)))
50(assert (= 65536 (+ (high-border uint16) 1)))
51(assert (= -1 (- (low-border uint16) 1)))
52(assert (= 4294967296 (+ (high-border uint32) 1)))
53(assert (= -1 (- (low-border uint32) 1)))
54;(assert (= 18446744073709551616 (+ (high-border uint64) 1))) ;OVERFLOW
55(assert (= -1 (- (low-border uint64) 1)))
56
57(princ "all tests pass\n\n")
58#t
59

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t