]> gitweb.factorcode.org Git - factor.git/blob - basis/circular/circular-tests.factor
Append input history to ~/.factor-history upon UI Listener ending
[factor.git] / basis / circular / circular-tests.factor
1 ! Copyright (C) 2005, 2006 Alex Chapman, Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license
3 USING: arrays circular kernel 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 { "fob" } [ "foo" <circular> CHAR: b 2 pick set-nth >string ] unit-test
23 { "boo" } [ "foo" <circular> CHAR: b 3 pick set-nth-unsafe >string ] unit-test
24 { "ornact" } [ "factor" <circular> 4 over change-circular-start CHAR: n 2 pick set-nth >string ] unit-test
25
26 { "bcd" } [ 3 <circular-string> "abcd" [ over circular-push ] each >string ] unit-test
27
28 { { 0 0 } } [ { 0 0 } <circular> -1 over change-circular-start >array ] unit-test
29
30 ! This no longer fails
31 ! [ "test" <circular> 5 swap nth ] must-fail
32 ! [ "foo" <circular> CHAR: b 3 rot set-nth ] must-fail
33
34 { { } } [ 3 <growing-circular> >array ] unit-test
35 { { 1 2 } } [
36     3 <growing-circular>
37     [ 1 swap growing-circular-push ] keep
38     [ 2 swap growing-circular-push ] keep >array
39 ] unit-test
40 { { 3 4 5 } } [
41     3 <growing-circular> dup { 1 2 3 4 5 } [
42         swap growing-circular-push
43     ] with each >array
44 ] unit-test
45
46 { V{ 1 2 3 } } [
47     { 1 2 3 } <circular> V{ } [
48         [ push f ] curry circular-while
49     ] keep
50 ] unit-test
51
52 CONSTANT: test-sequence1 { t f f f }
53 { V{ 1 2 3 1 } } [
54     { 1 2 3 } <circular> V{ } [
55         [ [ push ] [ length 1 - test-sequence1 nth ] bi ] curry circular-while
56     ] keep
57 ] unit-test
58
59 CONSTANT: test-sequence2 { t f t t f f t t t f f f }
60 { V{ 1 2 3 1 2 3 1 2 3 1 2 3 } } [
61     { 1 2 3 } <circular> V{ } [
62         [ [ push ] [ length 1 - test-sequence2 nth ] bi ] curry circular-while
63     ] keep
64 ] unit-test
65
66 { V{ 1 2 3 1 2 } } [
67     { 1 2 3 } <circular> V{ } [
68         [ [ push ] [ length 5 < ] bi ] curry circular-loop
69     ] keep
70 ] unit-test
71
72 { V{ 1 } } [
73     { 1 2 3 } <circular> V{ } [
74         [ push f ] curry circular-loop
75     ] keep
76 ] unit-test