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 { 0 } [ PV{ } length ] unit-test
8 { 1 } [ 3 PV{ } ppush length ] unit-test
10 { 3 } [ 3 PV{ } ppush first ] unit-test
13 PV{ } { 3 1 3 3 7 } [ swap ppush ] each
17 PV{ } { 3 1 3 3 7 } [ swap ppush ] each >array
20 { 100 1060 2000 10000 100000 1000000 } [
21 [ t ] swap [ iota dup >persistent-vector sequence= ] curry unit-test
24 { } [ 10000 [ 16 random-bits ] PV{ } replicate-as "1" set ] unit-test
25 { } [ "1" get >vector "2" set ] unit-test
30 16 random-bits 10000 random
31 [ "1" [ new-nth ] change ]
32 [ "2" [ new-nth ] change ] 2bi
33 "1" get "2" get sequence=
37 [ PV{ } ppop ] [ empty-error? ] must-fail-with
39 { t } [ PV{ 3 } ppop empty? ] unit-test
41 { PV{ 3 7 } } [ PV{ 3 7 6 } ppop ] unit-test
43 { PV{ 3 7 6 5 } } [ 5 PV{ 3 7 6 } ppush ] unit-test
45 { } [ PV{ } "1" set ] unit-test
46 { } [ V{ } clone "2" set ] unit-test
48 : push/pop-test ( vec -- vec' ) 3 swap ppush 3 swap ppush ppop ;
50 { } [ PV{ } 10000 [ push/pop-test ] times drop ] unit-test
54 10000 [ 1 swap ppush ] times
59 10000 iota >persistent-vector 752 [ ppop ] times dup length iota sequence=
66 16 random-bits [ "1" [ ppush ] change ] [ "2" get push ] bi
68 100 random "1" get length min [
72 "1" get "2" get sequence=