Debian Codegraph @

test/include/fixnum-tests.scm

raw
1 ;;(import (scheme base)) (import (srfi-143)) (import (chibi test))
2 (test-group "fixnum"
3 (test-group "fixnum/arithmetic"
4 (test #t (fixnum? 32767))
5 (test #f (fixnum? 1.1))
6
7 (test #t (fx=? 1 1 1))
8 (test #f (fx=? 1 2 2))
9 (test #f (fx=? 1 1 2))
10 (test #f (fx=? 1 2 3))
11
12 (test #t (fx<? 1 2 3))
13 (test #f (fx<? 1 1 2))
14 (test #t (fx>? 3 2 1))
15 (test #f (fx>? 2 1 1))
16 (test #t (fx<=? 1 1 2))
17 (test #f (fx<=? 1 2 1))
18 (test #t (fx>=? 2 1 1))
19 (test #f (fx>=? 1 2 1))
20 (test '(#t #f) (list (fx<=? 1 1 2) (fx<=? 2 1 3)))
21
22 (test #t (fxzero? 0))
23 (test #f (fxzero? 1))
24
25 (test #f (fxpositive? 0))
26 (test #t (fxpositive? 1))
27 (test #f (fxpositive? -1))
28
29 (test #f (fxnegative? 0))
30 (test #f (fxnegative? 1))
31 (test #t (fxnegative? -1))
32
33 (test #f (fxodd? 0))
34 (test #t (fxodd? 1))
35 (test #t (fxodd? -1))
36 (test #f (fxodd? 102))
37
38 (test #t (fxeven? 0))
39 (test #f (fxeven? 1))
40 (test #t (fxeven? -2))
41 (test #t (fxeven? 102))
42
43 (test 4 (fxmax 3 4))
44 (test 5 (fxmax 3 5 4))
45 (test 3 (fxmin 3 4))
46 (test 3 (fxmin 3 5 4))
47
48 (test 7 (fx+ 3 4))
49 (test 12 (fx* 4 3))
50
51 (test -1 (fx- 3 4))
52 (test -3 (fxneg 3))
53
54 (test 7 (fxabs -7))
55 (test 7 (fxabs 7))
56
57 (test 1764 (fxsquare 42))
58 (test 4 (fxsquare 2))
59
60 (test 2 (fxquotient 5 2))
61 (test -2 (fxquotient -5 2))
62 (test -2 (fxquotient 5 -2))
63 (test 2 (fxquotient -5 -2))
64
65 (test 1 (fxremainder 13 4))
66 (test -1 (fxremainder -13 4))
67 (test 1 (fxremainder 13 -4))
68 (test -1 (fxremainder -13 -4))
69
70 (let*-values (((root rem) (fxsqrt 32)))
71 (test 35 (* root rem)))
72 )
73
74 (test-group "fixnum/bitwise"
75 (test "test-1" -1 (fxnot 0))
76 (test "test-2" 0 (fxand #b0 #b1))
77 (test "test-115" 6 (fxand 14 6))
78 (test "test-117" 14 (fxior 10 12))
79 (test "test-119" 6 (fxxor 10 12))
80 (test "test-122" 0 (fxnot -1))
81 (test "test-125" 9 (fxif 3 1 8))
82 (test "test-126" 0 (fxif 3 8 1))
83 (test "test-135" 2 (fxbit-count 12))
84 (test "test-137" 0 (fxlength 0))
85 (test "test-138" 8 (fxlength 128))
86 (test "test-139" 8 (fxlength 255))
87 (test "test-140" 9 (fxlength 256))
88 (test "test-141" -1 (fxfirst-set-bit 0))
89 (test "test-142" 0 (fxfirst-set-bit 1))
90 (test "test-143" 0 (fxfirst-set-bit 3))
91 (test "test-144" 2 (fxfirst-set-bit 4))
92 (test "test-145" 1 (fxfirst-set-bit 6))
93 (test "test-146" 0 (fxfirst-set-bit -1))
94 (test "test-147" 1 (fxfirst-set-bit -2))
95 (test "test-148" 0 (fxfirst-set-bit -3))
96 (test "test-149" 2 (fxfirst-set-bit -4))
97 (test "test-160" #t (fxbit-set? 0 1))
98 (test "test-161" #f (fxbit-set? 1 1))
99 (test "test-162" #f (fxbit-set? 1 8))
100 (test "test-163" #t (fxbit-set? 10000 -1))
101 (test "test-167" #t (fxbit-set? 1000 -1))
102 (test "test-168" 0 (fxcopy-bit 0 0 #f))
103 (test "test-174" -1 (fxcopy-bit 0 -1 #t))
104 (test "test-180" 1 (fxcopy-bit 0 0 #t))
105 (test "test-181" #x106 (fxcopy-bit 8 6 #t))
106 (test "test-182" 6 (fxcopy-bit 8 6 #f))
107 (test "test-183" -2 (fxcopy-bit 0 -1 #f))
108 (test "test-189" 0 (fxbit-field 6 0 1))
109 (test "test-190" 3 (fxbit-field 6 1 3))
110 (test "test-196" 2 (fxarithmetic-shift 1 1))
111 (test "test-197" 0 (fxarithmetic-shift 1 -1))
112 (test "test-200" #b110 (fxbit-field-rotate #b110 1 1 2))
113 (test "test-201" #b1010 (fxbit-field-rotate #b110 1 2 4))
114 (test "test-202" #b1011 (fxbit-field-rotate #b0111 -1 1 4))
115 (test "test-208" #b110 (fxbit-field-rotate #b110 0 0 10))
116 (test "test-211" 6 (fxbit-field-reverse 6 1 3))
117 (test "test-212" 12 (fxbit-field-reverse 6 1 4))
118 (test "test-248" -11 (fxnot 10))
119 (test "test-249" 36 (fxnot -37))
120 (test "test-250" 11 (fxior 3 10))
121 (test "test-251" 10 (fxand 11 26))
122 (test "test-252" 9 (fxxor 3 10))
123 (test "test-254" 4 (fxand 37 12))
124 (test "test-255" 32 (fxarithmetic-shift 8 2))
125 (test "test-256" 4 (fxarithmetic-shift 4 0))
126 (test "test-257" 4 (fxarithmetic-shift 8 -1))
127 (test "test-263" 0 (fxlength 0))
128 (test "test-264" 1 (fxlength 1))
129 (test "test-265" 0 (fxlength -1))
130 (test "test-266" 3 (fxlength 7))
131 (test "test-267" 3 (fxlength -7))
132 (test "test-268" 4 (fxlength 8))
133 (test "test-269" 3 (fxlength -8))
134 (test "test-272" #t (fxbit-set? 3 10))
135 (test "test-273" #t (fxbit-set? 2 6))
136 (test "test-274" #f (fxbit-set? 0 6))
137 (test "test-276" #b100 (fxcopy-bit 2 0 #t))
138 (test "test-277" #b1011 (fxcopy-bit 2 #b1111 #f))
139 (test "test-280" 1 (fxfirst-set-bit 2))
140 (test "test-282" 3 (fxfirst-set-bit 40))
141 (test "test-283" 2 (fxfirst-set-bit -28))
142 (test "test-288" 1 (fxand #b1 #b1))
143 (test "test-289" 0 (fxand #b1 #b10))
144 (test "test-290" #b10 (fxand #b11 #b10))
145 (test "test-291" #b101 (fxand #b101 #b111))
146 (test "test-292" #b111 (fxand -1 #b111))
147 (test "test-293" #b110 (fxand -2 #b111))
148 (test "test-331" 1 (fxarithmetic-shift 1 0))
149 (test "test-333" 4 (fxarithmetic-shift 1 2))
150 (test "test-334" 8 (fxarithmetic-shift 1 3))
151 (test "test-335" 16 (fxarithmetic-shift 1 4))
152 (test "test-346" -1 (fxarithmetic-shift -1 0))
153 (test "test-347" -2 (fxarithmetic-shift -1 1))
154 (test "test-348" -4 (fxarithmetic-shift -1 2))
155 (test "test-349" -8 (fxarithmetic-shift -1 3))
156 (test "test-350" -16 (fxarithmetic-shift -1 4))
157 (test "test-363" #b1010 (fxbit-field #b1101101010 0 4))
158 (test "test-364" #b101101 (fxbit-field #b1101101010 3 9))
159 (test "test-365" #b10110 (fxbit-field #b1101101010 4 9))
160 (test "test-366" #b110110 (fxbit-field #b1101101010 4 10))
161 (test "test-373" 3 (fxif 1 1 2))
162 (test "test-378" #b00110011 (fxif #b00111100 #b11110000 #b00001111))
163 (test "test-379" #b1 (fxcopy-bit 0 0 #t))
164 ))
165 (test-exit)