source: project/release/5/bitwise-utils/trunk/tests/srfi-60-test.scm @ 38600

Last change on this file since 38600 was 38600, checked in by Kon Lovett, 8 months ago

add srfi-60 module

File size: 2.6 KB
Line 
1
2(import test)
3
4(import (srfi 60))
5
6(import (srfi 1))
7
8(test-group
9 "srfi-60"
10 (test
11  "logand/bitwise-and"
12  "1000"
13  (number->string (logand #b1100 #b1010) 2))
14 (test
15  "logior/bitwise-ior"
16  "1110"
17  (number->string (logior #b1100 #b1010) 2))
18 (test
19  "logxor/bitwise-xor"
20  "110"
21  (number->string (logxor #b1100 #b1010) 2))
22 (test
23  "lognot/bitwise-not"
24  "-10000001"
25  (number->string (lognot #b10000000) 2))
26 (test
27  "logtest/any-bit-set? no"
28  #f
29  (logtest #b0100 #b1011))
30 (test-assert
31  "logtest/any-bit-set? yes"
32  (logtest #b0100 #b0111))
33 (test
34  "logcount"
35  4
36  (logcount #b10101010))
37 (test
38  "logcount zero"
39  0
40  (logcount 0))
41 (test
42  "logcount negative"
43  1
44  (logcount -2))
45 (test
46  "integer-length"
47  8
48  (integer-length #b10101010))
49 (test
50  "integer-length zero"
51  0
52  (integer-length 0))
53 (test
54  "integer-length four"
55  4
56  (integer-length #b1111))
57 (test
58  "log2-binary-factors/first-set-bit"
59  '(4 0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 -1
60      0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 4)
61  (map log2-binary-factors (iota 33 -16)))
62 (test
63  "logbit?/bit-set?"
64  '(#t #f #t #t #f)
65  (map (lambda (n) (logbit? n #b1101)) (iota 5)))
66 (test
67  "copy-bit zero unary"
68  "1"
69  (number->string (copy-bit 0 0 #t) 2))
70 (test
71  "copy-bit zero centenial"
72  "100"
73  (number->string (copy-bit 2 0 #t) 2))
74 (test
75  "copy-bit negative"
76  "1011"
77  (number->string (copy-bit 2 #b1111 #f) 2))
78 (test
79  "bit-field first half"
80  "1010"
81  (number->string (bit-field #b1101101010 0 4) 2))
82 (test
83  "bit-field second half"
84  "10110"
85  (number->string (bit-field #b1101101010 4 9) 2))
86 (test
87  "copy-bit-field positive"
88  "1101100000"
89  (number->string (copy-bit-field #b1101101010 0 0 4) 2))
90 (test
91  "copy-bit-field negative"
92  "1101101111"
93  (number->string (copy-bit-field #b1101101010 -1 0 4) 2))
94 (test
95  "copy-bit-field long negative"
96  "110100111110000"
97  (number->string (copy-bit-field #b110100100010000 -1 5 9) 2))
98 (test
99  "ash/arithmetic-shift positive"
100  "1000"
101  (number->string (ash #b1 3) 2))
102 (test
103  "ash/arithmetic-shift negative"
104  "101"
105  (number->string (ash #b1010 -1) 2))
106 (test
107  "rotate-bit-field short positive"
108  "10"
109  (number->string (rotate-bit-field #b0100 3 0 4) 2))
110 (test
111  "rotate-bit-field short negative"
112  "10"
113  (number->string (rotate-bit-field #b0100 -1 0 4) 2))
114 (test
115  "rotate-bit-field long negative"
116  "110100010010000"
117  (number->string (rotate-bit-field #b110100100010000 -1 5 9) 2))
118 (test
119  "rotate-bit-field long positive"
120  "110100000110000"
121  (number->string (rotate-bit-field #b110100100010000 1 5 9) 2))
122 (test
123  "reverse-bit-field"
124  "e5"
125  (number->string (reverse-bit-field #xa7 0 8) 16)))
126
Note: See TracBrowser for help on using the repository browser.