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
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 [ "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
26 [ "bcd" ] [ 3 <circular-string> "abcd" [ over circular-push ] each >string ] unit-test
28 [ { 0 0 } ] [ { 0 0 } <circular> -1 over change-circular-start >array ] unit-test
30 ! This no longer fails
31 ! [ "test" <circular> 5 swap nth ] must-fail
32 ! [ "foo" <circular> CHAR: b 3 rot set-nth ] must-fail
34 [ { } ] [ 3 <growing-circular> >array ] unit-test
37 [ 1 swap growing-circular-push ] keep
38 [ 2 swap growing-circular-push ] keep >array
41 3 <growing-circular> dup { 1 2 3 4 5 } [
42 swap growing-circular-push
47 { 1 2 3 } <circular> V{ } [
48 [ push f ] curry circular-while
52 CONSTANT: test-sequence1 { t f f f }
54 { 1 2 3 } <circular> V{ } [
55 [ [ push ] [ length 1 - test-sequence1 nth ] bi ] curry circular-while
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
67 { 1 2 3 } <circular> V{ } [
68 [ [ push ] [ length 5 < ] bi ] curry circular-loop
73 { 1 2 3 } <circular> V{ } [
74 [ push f ] curry circular-loop