PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/core/sorting/sorting-tests.factor

http://github.com/abeaumont/factor
Unknown | 28 lines | 21 code | 7 blank | 0 comment | 0 complexity | 9d717f229777b012379c013f544d5e7c MD5 | raw file
 1USING: sorting sequences kernel math math.order random
 2tools.test vectors sets vocabs grouping ;
 3IN: sorting.tests
 4
 5[ { } ] [ { } natural-sort ] unit-test
 6
 7[ { 270000000 270000001 } ]
 8[ T{ slice f 270000000 270000002 T{ iota f 270000002 } } natural-sort ]
 9unit-test
10
11[ t ] [
12    100 [
13        drop
14        100 [ 20 random [ 1000 random ] replicate ] replicate
15        dup natural-sort
16        [ set= ] [ nip [ before=? ] monotonic? ] 2bi and
17    ] all-integers?
18] unit-test
19
20[ ] [ { 1 2 } [ 2drop 1 ] sort drop ] unit-test
21
22! Is it a stable sort?
23[ t ] [ { { 1 "a" } { 1 "b" } { 1 "c" } } dup sort-keys = ] unit-test
24
25[ { { 1 "a" } { 1 "b" } { 1 "c" } { 1 "e" } { 2 "d" } } ]
26[ { { 1 "a" } { 1 "b" } { 1 "c" } { 2 "d" } { 1 "e" } } sort-keys ] unit-test
27
28[ ] [ all-words natural-sort drop ] unit-test