remove math.blas.syntax and merge parsing words into math.blas.vectors/matrices
[factor/jcg.git] / basis / persistent / vectors / vectors-tests.factor
blobc232db853339ced32223fcb3a223521b9b9b26ee
1 IN: persistent-vectors.tests
2 USING: accessors tools.test persistent.vectors
3 persistent.sequences sequences kernel arrays random namespaces
4 vectors math math.order ;
6 \ new-nth must-infer
7 \ ppush must-infer
8 \ ppop must-infer
10 [ 0 ] [ PV{ } length ] unit-test
12 [ 1 ] [ 3 PV{ } ppush length ] unit-test
14 [ 3 ] [ 3 PV{ } ppush first ] unit-test
16 [ PV{ 3 1 3 3 7 } ] [
17     PV{ } { 3 1 3 3 7 } [ swap ppush ] each
18 ] unit-test
20 [ { 3 1 3 3 7 } ] [
21     PV{ } { 3 1 3 3 7 } [ swap ppush ] each >array
22 ] unit-test
24 { 100 1060 2000 10000 100000 1000000 } [
25     [ t ] swap [ dup >persistent-vector sequence= ] curry unit-test
26 ] each
28 [ ] [ 10000 [ 16 random-bits ] PV{ } replicate-as "1" set ] unit-test
29 [ ] [ "1" get >vector "2" set ] unit-test
31 [ t ] [
32     3000 [
33         drop
34         16 random-bits 10000 random
35         [ "1" [ new-nth ] change ]
36         [ "2" [ new-nth ] change ] 2bi
37         "1" get "2" get sequence=
38     ] all?
39 ] unit-test
41 [ PV{ } ppop ] [ empty-error? ] must-fail-with
43 [ t ] [ PV{ 3 } ppop empty? ] unit-test
45 [ PV{ 3 7 } ] [ PV{ 3 7 6 } ppop ] unit-test
47 [ PV{ 3 7 6 5 } ] [ 5 PV{ 3 7 6 } ppush ] unit-test
49 [ ] [ PV{ } "1" set ] unit-test
50 [ ] [ V{ } clone "2" set ] unit-test
52 : push/pop-test ( vec -- vec' ) 3 swap ppush 3 swap ppush ppop ;
54 [ ] [ PV{ } 10000 [ push/pop-test ] times drop ] unit-test
56 [ PV{ } ] [
57     PV{ }
58     10000 [ 1 swap ppush ] times
59     10000 [ ppop ] times
60 ] unit-test
62 [ t ] [
63     10000 >persistent-vector 752 [ ppop ] times dup length sequence=
64 ] unit-test
66 [ t ] [
67     100 [
68         drop
69         100 random [
70             16 random-bits [ "1" [ ppush ] change ] [ "2" get push ] bi
71         ] times
72         100 random "1" get length min [
73             "1" [ ppop ] change
74             "2" get pop*
75         ] times
76         "1" get "2" get sequence=
77     ] all?
78 ] unit-test