Skip to content

Commit

Permalink
The iteration method tests in matrixtest.nqp were all silently failin…
Browse files Browse the repository at this point in the history
…g and I didn't know it. calling return() inside the -> lambda returns from the method, without ever hitting the assertions. Instead of -> lambdas, use nested subs, which handle return just fine. Also, avoid use of newclosure where not needed
  • Loading branch information
Whiteknight committed Aug 15, 2010
1 parent 695e0f6 commit 6a845b4
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions t/testlib/matrixtest.nqp
Expand Up @@ -386,12 +386,13 @@ class Pla::Matrix::Testcase is UnitTest::Testcase {
$n{Key.new(1,0)} := self.fancyvalue(2);
$n{Key.new(1,1)} := self.fancyvalue(3);
my $count := -1;
my $sub := pir::newclosure__PP(-> $matrix, $value, $x, $y {
my $sub := pir::newclosure__PP(sub ($matrix, $value, $x, $y) {
$count++;
return (self.fancyvalue($count));
return self.fancyvalue($count);
});
$m.iterate_function_inplace($sub);
assert_equal($count, 4, "iteration did not happen for all elements");
assert_equal($count, 3, "iteration did not happen for all elements");
assert_equal($m, $n, "iteration did not create the correct result");
}

# test that iterate_function_inplace calls the callback with the proper
Expand All @@ -401,7 +402,7 @@ class Pla::Matrix::Testcase is UnitTest::Testcase {
my $count := 0;
my $x_ords := [0, 0, 1, 1];
my $y_ords := [0, 1, 0, 1];
my $sub := pir::newclosure__PP(-> $matrix, $value, $x, $y {
my $sub := pir::newclosure__PP(sub ($matrix, $value, $x, $y) {
assert_equal($x, $x_ords[$count], "x coordinate is correct");
assert_equal($y, $y_ords[$count], "y coordinate is correct");
$count++;
Expand All @@ -417,7 +418,7 @@ class Pla::Matrix::Testcase is UnitTest::Testcase {
my $count := 0;
my $first := 5;
my $second := 2;
my $sub := pir::newclosure__PP(-> $matrix, $value, $x, $y, $a, $b {
my $sub := pir::newclosure__PP(sub ($matrix, $value, $x, $y, $a, $b) {
assert_equal($a, $first, "first arg is not equal: " ~ $x);
assert_equal($b, $second, "second arg is not equal: " ~ $y);
$count++;
Expand All @@ -434,19 +435,19 @@ class Pla::Matrix::Testcase is UnitTest::Testcase {
$m.transpose();
my $n := self.matrix2x2(self.fancyvalue(0) * 2, self.fancyvalue(2) * 2,
self.fancyvalue(1) * 2, self.fancyvalue(3) * 2);
my $sub := pir::newclosure__PP(-> $matrix, $value, $x, $y {
my $sub := sub ($matrix, $value, $x, $y) {
return ($value * 2);
});
};
$m.iterate_function_inplace($sub);
assert_equal($m, $n, "external iteration does not respect transpose");
}

# Test that we can iterate_function_external, and create a new matrix
method test_METHOD_iterate_function_external() {
my $m := self.fancymatrix2x2();
my $sub := pir::newclosure__PP(-> $matrix, $value, $x, $y {
return ($value);
});
my $sub := sub ($matrix, $value, $x, $y) {
return $value;
};
my $o := $m.iterate_function_external($sub);
assert_equal($o, $m, "Cannot copy by iterating external");
}
Expand All @@ -457,7 +458,7 @@ class Pla::Matrix::Testcase is UnitTest::Testcase {
self.nullvalue, self.nullvalue);
my $n := self.matrix2x2(self.fancyvalue(0), self.fancyvalue(1),
self.fancyvalue(1), self.fancyvalue(2));
my $sub := pir::newclosure__PP(-> $matrix, $value, $x, $y {
my $sub := pir::newclosure__PP(sub ($matrix, $value, $x, $y) {
return (self.fancyvalue($x + $y));
});
my $o := $m.iterate_function_external($sub);
Expand All @@ -470,7 +471,7 @@ class Pla::Matrix::Testcase is UnitTest::Testcase {
self.nullvalue, self.nullvalue);
my $n := self.matrix2x2(self.fancyvalue(3), self.fancyvalue(3),
self.fancyvalue(3), self.fancyvalue(3));
my $sub := pir::newclosure__PP(-> $matrix, $value, $x, $y, $a, $b {
my $sub := pir::newclosure__PP(sub ($matrix, $value, $x, $y, $a, $b) {
return (self.fancyvalue($a + $b));
});
my $o := $m.iterate_function_external($sub, 1, 2);
Expand All @@ -484,7 +485,9 @@ class Pla::Matrix::Testcase is UnitTest::Testcase {
$m.transpose();
my $n := self.matrix2x2(self.fancyvalue(0) * 2, self.fancyvalue(2) * 2,
self.fancyvalue(1) * 2, self.fancyvalue(3) * 2);
my $sub := -> $matrix, $value, $x, $y { $value * 2; };
my $sub := sub ($matrix, $value, $x, $y) {
return $value * 2;
};
my $o := $m.iterate_function_external($sub);
assert_equal($o, $n, "external iteration does not respect transpose");
}
Expand Down

0 comments on commit 6a845b4

Please sign in to comment.