]> gitweb.factorcode.org Git - factor.git/blob - basis/circular/circular-tests.factor
Added unit tests
[factor.git] / basis / circular / circular-tests.factor
1 ! Copyright (C) 2005, 2006 Alex Chapman, Daniel Ehrenberg
2 ! See https://factorcode.org/license.txt for BSD license
3 USING: arrays circular kernel literals math sequences sequences.private
4 strings tools.test ;
5 IN: circular.tests
6
7 { 0 } [ { 0 1 2 3 4 } <circular> 0 swap virtual@ drop ] unit-test
8 { 2 } [ { 0 1 2 3 4 } <circular> 2 swap virtual@ drop ] unit-test
9
10 { CHAR: t } [ "test" <circular> 0 swap nth ] unit-test
11 { "test"  } [ "test" <circular> >string ] unit-test
12
13 { CHAR: e } [ "test" <circular> 5 swap nth-unsafe ] unit-test
14
15 { [ 1 2 3 ] } [ { 1 2 3 } <circular> [ ] like ] unit-test
16 { [ 2 3 1 ] } [ { 1 2 3 } <circular> [ rotate-circular ] keep [ ] like ] unit-test
17 { [ 3 1 2 ] } [ { 1 2 3 } <circular> [ rotate-circular ] keep [ rotate-circular ] keep [ ] like ] unit-test
18 { [ 2 3 1 ] } [ { 1 2 3 } <circular> 1 over change-circular-start [ ] like ] unit-test
19 { [ 3 1 2 ] } [ { 1 2 3 } <circular> 1 over change-circular-start 1 over change-circular-start [ ] like ] unit-test
20 { [ 3 1 2 ] } [ { 1 2 3 } <circular> -100 over change-circular-start [ ] like ] unit-test
21
22 { $[ { 1 2 3 } minimum ] } [ { 1 2 3 } <circular> minimum ] unit-test
23 { $[ { 1 2 3 } maximum ] } [ { 1 2 3 } <circular> maximum ] unit-test
24
25 { "fob" } [ "foo" <circular> CHAR: b 2 pick set-nth >string ] unit-test
26 { "boo" } [ "foo" <circular> CHAR: b 3 pick set-nth-unsafe >string ] unit-test
27 { "ornact" } [ "factor" <circular> 4 over change-circular-start CHAR: n 2 pick set-nth >string ] unit-test
28
29 { "bcd" } [ 3 <circular-string> "abcd" [ over circular-push ] each >string ] unit-test
30
31 { { 0 0 } } [ { 0 0 } <circular> -1 over change-circular-start >array ] unit-test
32
33 ! This no longer fails
34 ! [ "test" <circular> 5 swap nth ] must-fail
35 ! [ "foo" <circular> CHAR: b 3 rot set-nth ] must-fail
36
37 { { } } [ 3 <growing-circular> >array ] unit-test
38 { { 1 2 } } [
39     3 <growing-circular>
40     [ 1 swap growing-circular-push ] keep
41     [ 2 swap growing-circular-push ] keep >array
42 ] unit-test
43 { { 3 4 5 } } [
44     3 <growing-circular> dup { 1 2 3 4 5 } [
45         swap growing-circular-push
46     ] with each >array
47 ] unit-test
48
49 { V{ 1 2 3 } } [
50     { 1 2 3 } <circular> V{ } [
51         [ push f ] curry circular-while
52     ] keep
53 ] unit-test
54
55 CONSTANT: test-sequence1 { t f f f }
56 { V{ 1 2 3 1 } } [
57     { 1 2 3 } <circular> V{ } [
58         [ [ push ] [ length 1 - test-sequence1 nth ] bi ] curry circular-while
59     ] keep
60 ] unit-test
61
62 CONSTANT: test-sequence2 { t f t t f f t t t f f f }
63 { V{ 1 2 3 1 2 3 1 2 3 1 2 3 } } [
64     { 1 2 3 } <circular> V{ } [
65         [ [ push ] [ length 1 - test-sequence2 nth ] bi ] curry circular-while
66     ] keep
67 ] unit-test
68
69 { V{ 1 2 3 1 2 } } [
70     { 1 2 3 } <circular> V{ } [
71         [ [ push ] [ length 5 < ] bi ] curry circular-loop
72     ] keep
73 ] unit-test
74
75 { V{ 1 } } [
76     { 1 2 3 } <circular> V{ } [
77         [ push f ] curry circular-loop
78     ] keep
79 ] unit-test