forked from Raku/roast
/
rotate.t
74 lines (57 loc) · 2.5 KB
/
rotate.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use v6;
use Test;
plan 30;
# L<S32::Containers/Array/rotate>
{
my @a = <a b c d e>;
is ~@a.rotate, 'b c d e a', 'Array.rotate defaults to +1';
is ~@a, 'a b c d e', 'original array unmodified';
ok @a.rotate ~~ Positional, 'Array.rotate returns a Positional';
is ~@a.rotate(2), 'c d e a b', '.rotate(2)';
is ~@a, 'a b c d e', 'original array still unmodified';
is ~@a.rotate(-2), 'd e a b c', '.rotate(-2)';
is ~@a, 'a b c d e', 'original still unmodified (negative)';
is ~@a.rotate(0), 'a b c d e', '.rotate(0)';
is ~@a.rotate(5), 'a b c d e', '.rotate(5)';
is ~@a.rotate(15), 'a b c d e', '.rotate(15)';
is ~@a.rotate(7), 'c d e a b', '.rotate(7)';
is ~@a, 'a b c d e', 'original still unmodified (negative)';
is ~@a.rotate(-8), 'c d e a b', '.rotate(-8)';
is ~@a, 'a b c d e', 'original still unmodified (negative)';
} #14
# all the same but rotate() sub
{
my @a = <a b c d e>;
is ~rotate(@a), 'b c d e a', 'rotate(@a)';
is ~@a, 'a b c d e', 'original array unmodified';
is ~rotate(@a, 2), 'c d e a b', 'rotate(@a, 2)';
is ~@a, 'a b c d e', 'original array still unmodified';
is ~rotate(@a, -2), 'd e a b c', 'rotate(@a, -2)';
is ~@a, 'a b c d e', 'original still unmodified (negative)';
is ~rotate(@a, 0), 'a b c d e', 'rotate(@a, 0)';
is ~rotate(@a, 5), 'a b c d e', 'rotate(@a, 5)';
is ~rotate(@a, 15), 'a b c d e', 'rotate(@a, 15)';
is ~rotate(@a, 7), 'c d e a b', 'rotate(@a, 7)';
is ~@a, 'a b c d e', 'original still unmodified (negative)';
is ~rotate(@a, -8), 'c d e a b', 'rotate(@a, -8)';
is ~@a, 'a b c d e', 'original still unmodified (negative)';
} #13
# RT125677 Make sure rotate is Cool with stuff
{
my @a = <a b c d e>;
is ~@a.rotate('2'), 'c d e a b', '.rotate("2")';
is ~@a.rotate(2.5), 'c d e a b', '.rotate(2.5)';
}
# https://github.com/rakudo/rakudo/commit/f4cbdb64bc
subtest '.rotate can be used on empty List' => {
plan 8;
is-deeply () .rotate, (), 'List (1)';
is-deeply () .rotate(-1), (), 'List (-1)';
is-deeply [] .rotate, [], 'Array (1)';
is-deeply [] .rotate(-1), [], 'Array (-1)';
is-deeply ().Slip .rotate, ().Slip, 'Slip (1)';
is-deeply ().Slip .rotate(-1), ().Slip, 'Slip (-1)';
is-deeply ().Seq.cache.rotate, ().Seq.cache, ‘Seq's cache (1)’;
is-deeply ().Seq.cache.rotate(-1), ().Seq.cache, ‘Seq's cache (-1)’;
}
# vim: ft=perl6