]> gitweb.factorcode.org Git - factor.git/blob - basis/bit-arrays/bit-arrays-tests.factor
factor: rename [ ] [ ] unit-test -> { } [ ] unit-test using a refactoring tool!
[factor.git] / basis / bit-arrays / bit-arrays-tests.factor
1 USING: alien sequences sequences.private arrays bit-arrays kernel
2 tools.test math random ;
3 IN: bit-arrays.tests
4
5 [ -1 <bit-array> ] [ T{ bad-array-length f -1 } = ] must-fail-with
6
7 { 100 } [ 100 <bit-array> length ] unit-test
8
9 {
10     { t f t }
11 } [
12     3 <bit-array> t 0 pick set-nth t 2 pick set-nth
13     >array
14 ] unit-test
15
16 {
17     { t f t }
18 } [
19     { t f t } >bit-array >array
20 ] unit-test
21
22 {
23     { t f t } { f t f }
24 } [
25     { t f t } >bit-array dup clone [ not ] map!
26     [ >array ] bi@
27 ] unit-test
28
29 {
30     { f f f f f }
31 } [
32     { t f t t f } >bit-array dup clear-bits >array
33 ] unit-test
34
35 {
36     { t t t t t }
37 } [
38     { t f t t f } >bit-array dup set-bits >array
39 ] unit-test
40
41 { t } [
42     100 [
43         drop 100 [ 2 random zero? ] replicate
44         dup >bit-array >array =
45     ] all-integers?
46 ] unit-test
47
48 { ?{ f } } [
49     1 2 { t f t f } <slice> >bit-array
50 ] unit-test
51
52 { ?{ f t } } [ 0 2 ?{ f t f } subseq ] unit-test
53
54 { ?{ t f t f f f } } [ 6 ?{ t f t } resize ] unit-test
55
56 { ?{ t t } } [ 2 ?{ t t f t f t f t t t f t } resize ] unit-test
57
58 [ -10 ?{ } resize ] must-fail
59
60 [ -1 integer>bit-array ] must-fail
61 { ?{ } } [ 0 integer>bit-array ] unit-test
62 { ?{ f t } } [ 2 integer>bit-array ] unit-test
63 { ?{ t t t t t t t t t } } [ 511 integer>bit-array ] unit-test
64 { ?{
65     t t t t t t t t   t t t t t t t t   t t t t t t t t  t t t t t t t t
66     t t t t t t t t   t t t t t t t t   t t t t t t t t  t t t t t t t t
67     t t t t t t t t   t t t t t t t t   t t t t t t t t  t t t t t t t t
68     t t t t t t t t   t t t t t t t t   t t t t t t t t  t t t t t t t t
69 } } [
70     0xffffffffffffffffffffffffffffffff integer>bit-array
71 ] unit-test
72
73 { 14 } [ ?{ f t t t } bit-array>integer ] unit-test
74 { 0 } [ ?{ } bit-array>integer ] unit-test
75 { 0xffffffffffffffffffffffffffffffff } [ ?{
76     t t t t t t t t   t t t t t t t t   t t t t t t t t  t t t t t t t t
77     t t t t t t t t   t t t t t t t t   t t t t t t t t  t t t t t t t t
78     t t t t t t t t   t t t t t t t t   t t t t t t t t  t t t t t t t t
79     t t t t t t t t   t t t t t t t t   t t t t t t t t  t t t t t t t t
80 } bit-array>integer ] unit-test
81
82 { 49 } [ 49 <bit-array> dup set-bits [ ] count ] unit-test
83
84 { 1 } [ ?{ f t f t } byte-length ] unit-test
85
86 { 0xa } [ ?{ f t f t } bit-array>integer ] unit-test
87
88 { 0x100 } [ ?{ f f f f f f f f t } bit-array>integer ] unit-test