source: project/release/5/bitwise-utils/trunk/tests/bitwise-utils-test.scm @ 38599

Last change on this file since 38599 was 38599, checked in by Kon Lovett, 6 months ago

add srfi-60 inspired routines

File size: 2.3 KB
Line 
1;;;; bitwise-utils-test  -*- Scheme -*-
2;;;; Kon Lovett, Apr '20
3
4(import test)
5
6(test-begin "Bitwise Utils")
7
8;;;
9
10(import bitwise-utils)
11(import (chicken bitwise))
12
13;(bitwise-join #t 23 '())
14
15(test #b+01111111 (bitwise-mask 7))
16(test #b+01111111 (bitwise-mask 7 #t))
17(test #b-10000000 (bitwise-mask 7 #f))
18
19(test #b-100 (logical-shift-right #b-1000 1))
20(test #b+100 (logical-shift-right #b+1000 1))
21
22(test #b-101 (logical-shift-right #b-1011 1))
23(test #b+101 (logical-shift-right #b+1011 1))
24
25(test #x-2c (logical-shift-right #x-b0 2))
26(test #x+2c (logical-shift-right #x+b0 2))
27
28(test #x-2c000000000000000000000000044000
29  (logical-shift-right #x-b0000000000000000000000000110000 2))
30(test #x+2c000000000000000000000000044000
31  (logical-shift-right #x+b0000000000000000000000000110000 2))
32
33(test #b+0111111100 (logical-shift-left (bitwise-mask 7) 2))
34(test #b+0111111100 (logical-shift-left (bitwise-mask 7 #t) 2))
35(test #b-1000000000 (logical-shift-left (bitwise-mask 7 #f) 2))
36
37(test 1023 (string-length (number->string (bitwise-mask 1023) 2)))
38
39(test #b101101 (bitwise-join #b10 #b0000001 #b101))
40(test #b110011000000001 (bitwise-join #b1100 #b1100000000 #b1))
41(test #xb0000000000000000000000000110000deadbeef
42  (bitwise-join #xb0000000000000000000000000110000 #xdeadbeef))
43
44;mask effectively #b1..11000000011 (#b-111111101)
45(test #b-111111101 (bitwise-join (bitwise-mask 7 #f) #b11))
46(test #b110011000000001 (bitwise-and #b110011010110101 (bitwise-join (bitwise-mask 7 #f) #b11)))
47(test #b110011000000001 (bitwise-and #b110011010110101 #b111111000000011))
48
49(test '(0) (bitwise-split 0 5))
50(test '(5) (bitwise-split 5 0))
51(test '(0) (bitwise-split 0 0))
52
53(test '("a" "b" "c" "d" "e" "f") (map (cut number->string <> 16) (bitwise-split #xabcdef 4)))
54(test '("-a" "-b" "-c" "-d" "-e" "-f") (map (cut number->string <> 16) (bitwise-split #x-abcdef 4)))
55
56(test '("b0000000" "0" "110000deadbeef") (map (cut number->string <> 16) (bitwise-split #xb0000000000000000000000000110000deadbeef 64)))
57(test '("-b0000000" "0" "-110000deadbeef") (map (cut number->string <> 16) (bitwise-split #x-b0000000000000000000000000110000deadbeef 64)))
58
59(test 29 (bitwise-count #xb0000000000000000000000000110000deadbeef))
60(test 28 (bitwise-count #x-b0000000000000000000000000110000deadbeef))
61
62;;;
63
64(test-end "Bitwise Utils")
65
66(test-exit)
Note: See TracBrowser for help on using the repository browser.