1 IN: specialized-arrays.tests
2 USING: tools.test alien.syntax specialized-arrays
3 specialized-arrays sequences alien.c-types accessors
4 kernel arrays combinators compiler classes.struct
5 combinators.smart compiler.tree.debugger math libc destructors
9 SPECIALIZED-ARRAY: bool
10 SPECIALIZED-ARRAY: ushort
11 SPECIALIZED-ARRAY: char
12 SPECIALIZED-ARRAY: uint
13 SPECIALIZED-ARRAY: float
15 [ t ] [ { 1 2 3 } >int-array int-array? ] unit-test
17 [ t ] [ int-array{ 1 2 3 } int-array? ] unit-test
19 [ 2 ] [ int-array{ 1 2 3 } second ] unit-test
22 { t f t } >bool-array underlying>>
23 { 1 0 1 } "bool" heap-size {
29 [ ushort-array{ 1234 } ] [
30 little-endian? B{ 210 4 } B{ 4 210 } ? byte-array>ushort-array
33 [ B{ 210 4 1 } byte-array>ushort-array ] must-fail
36 int-array{ 3 1 3 3 7 } malloc-byte-array 5 <direct-int-array> >array
39 [ f ] [ float-array{ 4 3 2 1 } dup clone [ underlying>> ] bi@ eq? ] unit-test
41 [ f ] [ [ float-array{ 4 3 2 1 } dup clone [ underlying>> ] bi@ eq? ] compile-call ] unit-test
43 [ ushort-array{ 0 0 0 } ] [
44 3 ALIEN: 123 100 <direct-ushort-array> new-sequence
45 dup [ drop 0 ] change-each
52 SPECIALIZED-ARRAY: test-struct
55 1 test-struct-array{ } new-sequence length
58 [ V{ test-struct } ] [
59 [ [ test-struct-array <struct> ] test-struct-array{ } output>sequence first ] final-classes
62 : make-point ( x y -- struct )
63 test-struct <struct-boa> ;
67 1 2 make-point over set-first
68 3 4 make-point over set-second
69 0 [ [ x>> ] [ y>> ] bi / + ] reduce
74 2 malloc-test-struct-array
76 1 2 make-point over set-first
77 3 4 make-point over set-second
78 0 [ [ x>> ] [ y>> ] bi / + ] reduce
82 [ ] [ ALIEN: 123 10 <direct-test-struct-array> drop ] unit-test
86 10 malloc-test-struct-array
91 [ 15 ] [ 15 10 <test-struct-array> resize length ] unit-test
93 [ S{ test-struct f 12 20 } ] [
95 S{ test-struct f 4 20 }
96 S{ test-struct f 12 20 }
97 S{ test-struct f 20 20 }
102 STRUCT: fixed-string { text char[100] } ;
104 SPECIALIZED-ARRAY: fixed-string
106 [ { ALIEN: 123 ALIEN: 223 ALIEN: 323 ALIEN: 423 } ] [
107 ALIEN: 123 4 <direct-fixed-string-array> [ (underlying)>> ] { } map-as