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

Last change on this file since 38928 was 38928, checked in by Kon Lovett, 7 weeks ago

fix integer->list type

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