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