]> gitweb.factorcode.org Git - factor.git/blob - extra/arrays/shaped/shaped-tests.factor
f3369b6be0e92ca1a5c3531d573efb6e8c9e7052
[factor.git] / extra / arrays / shaped / shaped-tests.factor
1 ! Copyright (C) 2012 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays.shaped kernel tools.test math ;
4 IN: arrays.shaped.tests
5
6 [ t ] [
7     { 5 5 } increasing
8     {
9         { 0 1 2 3 4 }
10         { 5 6 7 8 9 }
11         { 10 11 12 13 14 }
12         { 15 16 17 18 19 }
13         { 20 21 22 23 24 }
14     } >shaped-array =
15 ] unit-test
16
17 [ { 5 5 } ] [
18     {
19         { 0 1 2 3 4 }
20         { 5 6 7 8 9 }
21         { 10 11 12 13 14 }
22         { 15 16 17 18 19 }
23         { 20 21 22 23 24 }
24     } >shaped-array shape>>
25 ] unit-test
26
27 [ { 5 5 } ] [
28     {
29         { 0 1 2 3 4 }
30         { 5 6 7 8 9 }
31         { 10 11 12 13 14 }
32         { 15 16 17 18 19 }
33         { 20 21 22 23 24 }
34     } >shaped-array shape
35 ] unit-test
36
37 { sa{ 1 } } [ { } ones ] unit-test
38 { sa{ 1 } } [ { 1 } ones ] unit-test
39
40 { sa{ 0 } } [ { } zeros ] unit-test
41 { sa{ 0 } } [ { 1 } zeros ] unit-test
42
43 ! Error on 0, negative shapes
44
45 [
46     sa{ { 1 3 3 } { 4 1 3 } { 4 4 1 } }
47 ] [
48     { 3 3 } 2 strict-lower
49     [ drop 3 ] map-strict-upper
50     [ drop 1 ] map-diagonal
51     [ sq ] map-strict-lower
52 ] unit-test