]> gitweb.factorcode.org Git - factor.git/blob - basis/persistent/vectors/vectors-tests.factor
core: Rename iota to <iota> so we can have TUPLE: iota ... ; instead of TUPLE: iota...
[factor.git] / basis / persistent / vectors / vectors-tests.factor
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 ;
5
6 { 0 } [ PV{ } length ] unit-test
7
8 { 1 } [ 3 PV{ } ppush length ] unit-test
9
10 { 3 } [ 3 PV{ } ppush first ] unit-test
11
12 { PV{ 3 1 3 3 7 } } [
13     PV{ } { 3 1 3 3 7 } [ swap ppush ] each
14 ] unit-test
15
16 { { 3 1 3 3 7 } } [
17     PV{ } { 3 1 3 3 7 } [ swap ppush ] each >array
18 ] unit-test
19
20 { 100 1060 2000 10000 100000 1000000 } [
21     [ t ] swap [ <iota> dup >persistent-vector sequence= ] curry unit-test
22 ] each
23
24 { } [ 10000 [ 16 random-bits ] PV{ } replicate-as "1" set ] unit-test
25 { } [ "1" get >vector "2" set ] unit-test
26
27 { t } [
28     3000 <iota> [
29         drop
30         16 random-bits 10000 random
31         [ "1" [ new-nth ] change ]
32         [ "2" [ new-nth ] change ] 2bi
33         "1" get "2" get sequence=
34     ] all?
35 ] unit-test
36
37 [ PV{ } ppop ] [ empty-error? ] must-fail-with
38
39 { t } [ PV{ 3 } ppop empty? ] unit-test
40
41 { PV{ 3 7 } } [ PV{ 3 7 6 } ppop ] unit-test
42
43 { PV{ 3 7 6 5 } } [ 5 PV{ 3 7 6 } ppush ] unit-test
44
45 { } [ PV{ } "1" set ] unit-test
46 { } [ V{ } clone "2" set ] unit-test
47
48 : push/pop-test ( vec -- vec' ) 3 swap ppush 3 swap ppush ppop ;
49
50 { } [ PV{ } 10000 [ push/pop-test ] times drop ] unit-test
51
52 { PV{ } } [
53     PV{ }
54     10000 [ 1 swap ppush ] times
55     10000 [ ppop ] times
56 ] unit-test
57
58 { t } [
59     10000 <iota> >persistent-vector 752 [ ppop ] times dup length iota sequence=
60 ] unit-test
61
62 { t } [
63     100 <iota> [
64         drop
65         100 random [
66             16 random-bits [ "1" [ ppush ] change ] [ "2" get push ] bi
67         ] times
68         100 random "1" get length min [
69             "1" [ ppop ] change
70             "2" get pop*
71         ] times
72         "1" get "2" get sequence=
73     ] all?
74 ] unit-test