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
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
10 { CHAR: t } [ "test" <circular> 0 swap nth ] unit-test
11 { "test" } [ "test" <circular> >string ] unit-test
13 { CHAR: e } [ "test" <circular> 5 swap nth-unsafe ] unit-test
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
22 { $[ { 1 2 3 } minimum ] } [ { 1 2 3 } <circular> minimum ] unit-test
23 { $[ { 1 2 3 } maximum ] } [ { 1 2 3 } <circular> maximum ] unit-test
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
29 { "bcd" } [ 3 <circular-string> "abcd" [ over circular-push ] each >string ] unit-test
31 { { 0 0 } } [ { 0 0 } <circular> -1 over change-circular-start >array ] unit-test
33 ! This no longer fails
34 ! [ "test" <circular> 5 swap nth ] must-fail
35 ! [ "foo" <circular> CHAR: b 3 rot set-nth ] must-fail
37 { { } } [ 3 <growing-circular> >array ] unit-test
40 [ 1 swap growing-circular-push ] keep
41 [ 2 swap growing-circular-push ] keep >array
44 3 <growing-circular> dup { 1 2 3 4 5 } [
45 swap growing-circular-push
50 { 1 2 3 } <circular> V{ } [
51 [ push f ] curry circular-while
55 CONSTANT: test-sequence1 { t f f f }
57 { 1 2 3 } <circular> V{ } [
58 [ [ push ] [ length 1 - test-sequence1 nth ] bi ] curry circular-while
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
70 { 1 2 3 } <circular> V{ } [
71 [ [ push ] [ length 5 < ] bi ] curry circular-loop
76 { 1 2 3 } <circular> V{ } [
77 [ push f ] curry circular-loop