Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Test both using ops and methods to get the key/value while iterating …
…a hash.
  • Loading branch information
pmurias committed Jul 8, 2013
1 parent 063e151 commit 8e3a39e
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions t/nqp/68-associative-for.t
Expand Up @@ -2,7 +2,7 @@

# check hash access methods

plan(6);
plan(10);

my %h;

Expand All @@ -16,18 +16,38 @@ 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 nqp::iterkey_s($_) eq 'a' {
ok(nqp::iterval($_) == 1000,'correct value for key a - lowlevel way');
}
if ($_.key eq 'b') {
ok(nqp::iterval($_) == 200,'correct value for key b');
elsif nqp::iterkey_s($_) eq 'b' {
ok(nqp::iterval($_) == 200,'correct value for key b - lowlevel way');
}
if ($_.key eq '1') {
ok(nqp::iterval($_) == 30,'correct value for key 1');
elsif nqp::iterkey_s($_) eq '1' {
ok(nqp::iterval($_) == 30,'correct value for key 1 - lowlevel way');
}
if ($_.key eq 'c') {
ok(nqp::iterval($_) == 4,'correct value for key 4');
elsif nqp::iterkey_s($_) eq 'c' {
ok(nqp::iterval($_) == 4,'correct value for key 4 - lowlevel way');
}
else {
ok(0);
}

if $_.key eq 'a' {
ok($_.value == 1000,'correct value for key a');
}
elsif $_.key eq 'b' {
ok($_.value == 200,'correct value for key b');
}
elsif $_.key eq '1' {
ok($_.value == 30,'correct value for key 1');
}
elsif $_.key eq 'c' {
ok($_.value == 4,'correct value for key 4');
}
else {
ok(0);
}

}

ok($sum == 1234,"we iterate over the correct keys");
Expand Down

0 comments on commit 8e3a39e

Please sign in to comment.