]> gitweb.factorcode.org Git - factor.git/blob - basis/struct-arrays/struct-arrays-tests.factor
Merge branch 'master' into experimental (untested!)
[factor.git] / basis / struct-arrays / struct-arrays-tests.factor
1 IN: struct-arrays.tests
2 USING: struct-arrays tools.test kernel math sequences
3 alien.syntax alien.c-types destructors libc accessors ;
4
5 C-STRUCT: test-struct
6 { "int" "x" }
7 { "int" "y" } ;
8
9 : make-point ( x y -- struct )
10     "test-struct" <c-object>
11     [ set-test-struct-y ] keep
12     [ set-test-struct-x ] keep ;
13
14 [ 5/4 ] [
15     2 "test-struct" <struct-array>
16     1 2 make-point over set-first
17     3 4 make-point over set-second
18     0 [ [ test-struct-x ] [ test-struct-y ] bi / + ] reduce
19 ] unit-test
20
21 [ 5/4 ] [
22     [
23         2 "test-struct" malloc-struct-array
24         dup underlying>> &free drop
25         1 2 make-point over set-first
26         3 4 make-point over set-second
27         0 [ [ test-struct-x ] [ test-struct-y ] bi / + ] reduce
28     ] with-destructors
29 ] unit-test