Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
More comprehensive multi-dim tests
  • Loading branch information
Mouq committed Aug 8, 2014
1 parent 616587c commit fd29f2b
Showing 1 changed file with 42 additions and 10 deletions.
52 changes: 42 additions & 10 deletions S02-types/multi_dimensional_array.t
Expand Up @@ -7,7 +7,7 @@ Multi-Dimensional Arrays
=end pod

plan 41;
plan 53;

# multi-dimensional array
# L<S09/Multidimensional arrays/Perl 6 arrays are not restricted to being one-dimensional>
Expand Down Expand Up @@ -56,9 +56,9 @@ isa_ok($multi1[1], List);
# multi-dimensional array slices
# L<S09/"Subscript and slice notation"/index value to each slice>

is(EVAL('$multi1[1;0]'), 'foo', 'got the right value at multi1 index 1,0');
is(EVAL('$multi1[1;1]'), 'bar', 'got the right value at multi1 index 1,1');
is(EVAL('$multi1[1;2]'), 'baz', 'got the right value at multi1 index 1,2');
is($multi1[1;0], 'foo', 'got the right value at multi1 index 1,0');
is($multi1[1;1], 'bar', 'got the right value at multi1 index 1,1');
is($multi1[1;2], 'baz', 'got the right value at multi1 index 1,2');

# and the normal syntax

Expand All @@ -85,9 +85,9 @@ isa_ok($multi2[0], Parcel);

# slice

is(EVAL('$multi2[0;0]'), 1, 'got the right value at multi2 index 0,0');
is(EVAL('$multi2[0;1]'), 2, 'got the right value at multi2 index 0,1');
is(EVAL('$multi2[0;2]'), 3, 'got the right value at multi2 index 0,2');
is($multi2[0;0], 1, 'got the right value at multi2 index 0,0');
is($multi2[0;1], 2, 'got the right value at multi2 index 0,1');
is($multi2[0;2], 3, 'got the right value at multi2 index 0,2');

# normal

Expand All @@ -105,14 +105,46 @@ isa_ok($multi2[1], List);

# slice

is(EVAL('$multi2[1;0]'), 4, 'got the right value at multi2 index 1,0');
is(EVAL('$multi2[1;1]'), 5, 'got the right value at multi2 index 1,1');
is(EVAL('$multi2[1;2]'), 6, 'got the right value at multi2 index 1,2');
is($multi2[1;0], 4, 'got the right value at multi2 index 1,0');
is($multi2[1;1], 5, 'got the right value at multi2 index 1,1');
is($multi2[1;2], 6, 'got the right value at multi2 index 1,2');

# normal

is($multi2[1][0], 4, 'got the right value at multi2 index 1,0');
is($multi2[1][1], 5, 'got the right value at multi2 index 1,1');
is($multi2[1][2], 6, 'got the right value at multi2 index 1,2');

# explicit multi-slice

is($multi2[0,1;0], (1, 4), 'got the right values at multi2 index {0,1},0');
is($multi2[0,1;1], (2, 5), 'got the right values at multi2 index {0,1},1');
is($multi2[0,1;2], (3, 6), 'got the right values at multi2 index {0,1},2');

# whatever multi-slice

is($multi2[*;0], (1, 4), 'got the right values at multi2 index *,0');
is($multi2[*;1], (2, 5), 'got the right values at multi2 index *,1');
is($multi2[*;2], (3, 6), 'got the right values at multi2 index *,2');

my @multi3 =
[
[ <cats fuzzy-cats angry-cats> ],
[ <dogs wrinkly-dogs growly-dogs> ],
[ <squirrels squirrels angry-squirrels> ]
],
[
[ <cars SUVs tanks> ],
[ <boats freighters aircraft-carriers> ],
[ <planes satellites falcon-9s> ]
];

is @multi3[1; 0,1,2; 1], (<SUVs freighters satellites>), '[1 ; 0,1,2 ; 2]';
is @multi3[1; *; 1], (<SUVs freighters satellites>), '[1 ; * ; 2]';

is @multi3[0,1; 2; 2], (<angry-squirrels falcon-9s>), '[0,1 ; 2 ; 2]';
is @multi3[1; 0,2; 1], (<SUVs satellites>), '[1 ; 0,2 ; 1]';
is @multi3[1; 2; 1,2], (<satellites falcon-9s>), '[1 ; 2 ; 1,2]';
is @multi3[0,1; 0,2; 1,2], (<fuzzy-cats angry-cats squirrels angry-squirrels SUVs tanks satellites falcon-9s>), '[0,1 ; 0,2 ; 1,2]';

# vim: ft=perl6

0 comments on commit fd29f2b

Please sign in to comment.