File: rotate.t

package info (click to toggle)
rakudo 2016.12-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 19,200 kB
  • ctags: 1,323
  • sloc: perl: 45,091; java: 2,524; ansic: 1,761; cpp: 152; sh: 17; makefile: 15
file content (61 lines) | stat: -rw-r--r-- 1,898 bytes parent folder | download
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
use v6.c;
use Test;

plan 29;

# 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)';
}

# vim: ft=perl6