Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add test for iterating over a hash.
  • Loading branch information
pmurias committed Jul 8, 2013
1 parent b5d98d9 commit 063e151
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions t/nqp/68-associative-for.t
@@ -0,0 +1,35 @@
#!./parrot nqp.pbc

# check hash access methods

plan(6);

my %h;

%h<a> := 1000;
%h<b> := 200;
%h{1} := 30;
%h{'c'} := 4;

my $count := 0;
my $sum := 0;
for %h {
$count := $count + 1;
$sum := $sum + nqp::iterval($_);
if ($_.key eq 'a') {
ok(nqp::iterval($_) == 1000,'correct value for key a');
}
if ($_.key eq 'b') {
ok(nqp::iterval($_) == 200,'correct value for key b');
}
if ($_.key eq '1') {
ok(nqp::iterval($_) == 30,'correct value for key 1');
}
if ($_.key eq 'c') {
ok(nqp::iterval($_) == 4,'correct value for key 4');
}
}

ok($sum == 1234,"we iterate over the correct keys");
ok($count == 4,"we iterate the correct number of times");

0 comments on commit 063e151

Please sign in to comment.