Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add native tests for := , :delete and [*-1]
  • Loading branch information
lizmat committed Mar 16, 2015
1 parent 5e3f7bf commit 0bfd751
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 11 additions & 3 deletions S09-typed-arrays/native-int.t
Expand Up @@ -7,7 +7,7 @@ if $*KERNEL.bits == 64 {
@uint.push: uint64;
}

plan (@int + @uint) * 122;
plan (@int + @uint) * 126;

# Basic native int array tests.
for @int,@uint -> $T {
Expand Down Expand Up @@ -55,8 +55,9 @@ for @int,@uint -> $T {
nok @arr.infinite, "$t array with values is not infinite";

is (@arr[10] = 100), 100, "Can assign non-contiguously to $t array";
is @arr[9], 0, "Elems behind non-contiguous assign are 0 on $t array";
is @arr[10], 100, "Non-contiguous assignment works on $t array";
is @arr[ 9], 0, "Elems behind non-contiguous assign are 0 on $t array";
is @arr[ 10], 100, "Non-contiguous assignment works on $t array";
is @arr[*-1], 100, "Can also get last element on $t array";

is (@arr = ()), (), "Can clear $t array by assigning empty list";
is @arr.elems, 0, "Cleared $t array has no elems";
Expand Down Expand Up @@ -85,6 +86,7 @@ for @int,@uint -> $T {
is @arr[0], 10, "Correct elem value set by constructor of $t array (1)";
is @arr[1], 15, "Correct elem value set by constructor of $t array (2)";
is @arr[2], 12, "Correct elem value set by constructor of $t array (3)";
is @arr[*-1,*-2], (12,15), "Can also get last 2 elements on $t array";

ok @arr.flat === @arr, "$t array .flat returns identity";
ok @arr.list === @arr, "$t array .list returns identity";
Expand Down Expand Up @@ -123,6 +125,12 @@ for @int,@uint -> $T {
throws_like { @arr.push('it real good') }, X::AdHoc,
message => 'This type cannot unbox to a native integer',
"Cannot push non-int/Int to $t array";
throws_like { @arr[0] := my $a }, X::AdHoc,
message => 'Cannot bind to a natively typed array',
"Cannot push non-int/Int to $t array";
throws_like { @arr[0]:delete }, X::AdHoc,
message => 'Cannot delete from a natively typed array',
"Cannot push non-int/Int to $t array";

is (@arr.push(101, 105)), (42,101,105), "can push multiple to $t array";
is @arr.elems, 3, "push multiple to $t array works (1)";
Expand Down
14 changes: 11 additions & 3 deletions S09-typed-arrays/native-num.t
Expand Up @@ -5,7 +5,7 @@ if $*KERNEL.bits == 64 {
@num.push: num64;
}

plan @num * 112;
plan @num * 115;

# Basic native num array tests.
for @num -> $T {
Expand Down Expand Up @@ -54,8 +54,9 @@ for @num -> $T {

is_approx (@arr[10] = 10.0e0), 10.0e0,
"Can assign non-contiguously to $t array";
is @arr[9], 0e0, "Elems behind non-contiguous assign are 0 on $t array";
is @arr[10], 10.0e0, "Non-contiguous assignment works on $t array";
is_approx @arr[ 9], 0e0, "Elems non-contiguous assign 0 on $t array";
is_approx @arr[ 10], 10.0e0, "Non-contiguous assignment works on $t array";
is_approx @arr[*-1], 10.0e0, "Can also get last element on $t array";

is (@arr = ()), (), "Can clear $t array by assigning empty list";
is @arr.elems, 0, "Cleared $t array has no elems";
Expand All @@ -82,6 +83,7 @@ for @num -> $T {
is_approx @arr[0], 1.0e0, "Correct elem set by constructor of $t array (1)";
is_approx @arr[1], 1.5e0, "Correct elem set by constructor of $t array (2)";
is_approx @arr[2], 1.2e0, "Correct elem set by constructor of $t array (3)";
@arr[*-1,*-2]; # cannot approx test Parcels

ok @arr.flat === @arr, "$t array .flat returns identity";
ok @arr.list === @arr, "$t array .list returns identity";
Expand Down Expand Up @@ -116,6 +118,12 @@ for @num -> $T {
action => '.shift',
what => "array[$t]",
"Trying to shift an empty $t array dies";
throws_like { @arr[0] := my $a }, X::AdHoc,
message => 'Cannot bind to a natively typed array',
"Cannot push non-int/Int to $t array";
throws_like { @arr[0]:delete }, X::AdHoc,
message => 'Cannot delete from a natively typed array',
"Cannot push non-int/Int to $t array";

@arr.push(4.2e0); # cannot approx test Parcels
is @arr.elems, 1, "push to $t array works (1)";
Expand Down

0 comments on commit 0bfd751

Please sign in to comment.