]> gitweb.factorcode.org Git - factor.git/blob - basis/specialized-arrays/specialized-arrays-tests.factor
19f98ff31f64cfe744333af9f84cad348946932e
[factor.git] / basis / specialized-arrays / specialized-arrays-tests.factor
1 IN: specialized-arrays.tests
2 USING: tools.test alien.syntax specialized-arrays sequences
3 specialized-arrays.int specialized-arrays.bool
4 specialized-arrays.ushort alien.c-types accessors kernel
5 specialized-arrays.char specialized-arrays.uint
6 specialized-arrays.float arrays combinators compiler ;
7
8 [ t ] [ { 1 2 3 } >int-array int-array? ] unit-test
9
10 [ t ] [ int-array{ 1 2 3 } int-array? ] unit-test
11
12 [ 2 ] [ int-array{ 1 2 3 } second ] unit-test
13
14 [ t ] [
15     { t f t } >bool-array underlying>>
16     { 1 0 1 } "bool" heap-size {
17         { 1 [ >char-array ] }
18         { 4 [ >uint-array ] }
19     } case underlying>> =
20 ] unit-test
21
22 [ ushort-array{ 1234 } ] [
23     little-endian? B{ 210 4 } B{ 4 210 } ? byte-array>ushort-array
24 ] unit-test
25
26 [ B{ 210 4 1 } byte-array>ushort-array ] must-fail
27
28 [ { 3 1 3 3 7 } ] [
29     int-array{ 3 1 3 3 7 } malloc-byte-array 5 <direct-int-array> >array
30 ] unit-test
31
32 [ f ] [ float-array{ 4 3 2 1 } dup clone [ underlying>> ] bi@ eq? ] unit-test
33
34 [ f ] [ [ float-array{ 4 3 2 1 } dup clone [ underlying>> ] bi@ eq? ] compile-call ] unit-test
35
36 [ ushort-array{ 0 0 0 } ] [
37     3 ALIEN: 123 100 <direct-ushort-array> new-sequence
38     dup [ drop 0 ] change-each
39 ] unit-test