Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
change fancyvalue to take an index. This allows us to return an order…
…ed set of interesting values, which we can use to run interesting tests. Add common tests for transpose and mem_transpose.
  • Loading branch information
Whiteknight committed Mar 15, 2010
1 parent a4d0b23 commit 6140e52
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 18 deletions.
95 changes: 81 additions & 14 deletions t/Testcase.nqp
Expand Up @@ -22,8 +22,8 @@ class Pla::Testcase is UnitTest::Testcase {
}

# A novel value which can be used to flag interesting changes in tests.
method fancyvalue() {
return (2);
method fancyvalue($idx) {
return ([5, 6, 7, 8][$idx]);
}

# Create an empty matrix of the given type
Expand Down Expand Up @@ -52,6 +52,15 @@ class Pla::Testcase is UnitTest::Testcase {
);
}

method fancymatrix2x2() {
return self.matrix2x2(
self.fancyvalue(0),
self.fancyvalue(1),
self.fancyvalue(2),
self.fancyvalue(3)
);
}

# Create a 3x3 matrix of the type with given values row-first
method matrix3x3($aa, $ab, $ac, $ba, $bb, $bc, $ca, $cb, $cc) {
my $m := self.matrix();
Expand Down Expand Up @@ -124,7 +133,7 @@ class Pla::Testcase is UnitTest::Testcase {
method test_VTABLE_is_equal_ELEMSFAIL() {
my $m := self.defaultmatrix2x2();
my $n := self.defaultmatrix2x2();
$n{Key.new(1,1)} := self.fancyvalue();
$n{Key.new(1,1)} := self.fancyvalue(0);
assert_not_equal($m, $n, "non-equal matrices are equal");
}

Expand All @@ -141,6 +150,14 @@ class Pla::Testcase is UnitTest::Testcase {
assert_equal(pir::getattribute__PPS($m, "cols"), 0, "empty matrix has non-zero col count");
}

method test_VTABLE_freeze() {
todo("Tests Needed!");
}

method test_VTABLE_thaw() {
todo("Tests Needed!");
}

# TODO: Add tests that get_pmc_keyed_int and set_pmc_keyed_int share a
# correct linear relationship with get_pmc_keyed and set_pmc_keyed.

Expand Down Expand Up @@ -181,38 +198,88 @@ class Pla::Testcase is UnitTest::Testcase {
method test_METHOD_fill() {
my $m := self.defaultmatrix2x2();
my $n := self.matrix2x2(
self.fancyvalue(),
self.fancyvalue(),
self.fancyvalue(),
self.fancyvalue()
self.fancyvalue(0),
self.fancyvalue(0),
self.fancyvalue(0),
self.fancyvalue(0)
);
$m.fill(self.fancyvalue());
$m.fill(self.fancyvalue(0));
assert_equal($n, $m, "Cannot fill");
}


# Test transposing square matrices
method test_METHOD_transpose() {
todo("Tests Needed!");
my $m := self.matrix2x2(
self.fancyvalue(0),
self.fancyvalue(1),
self.fancyvalue(2),
self.fancyvalue(3)
);
my $n := self.matrix2x2(
self.fancyvalue(0),
self.fancyvalue(2),
self.fancyvalue(1),
self.fancyvalue(3)
);
$m.transpose();
assert_equal($n, $m, "cannot transpose matrix");
}

# Test transposing non-square matrices
method test_METHOD_transpose_DIMCHANGE() {
todo("Tests Needed!");
my $m := self.matrix();
$m{Key.new(0,0)} := self.fancyvalue(0);
$m{Key.new(0,1)} := self.fancyvalue(1);
$m{Key.new(0,2)} := self.fancyvalue(2);
$m{Key.new(0,3)} := self.fancyvalue(3);

my $n := self.matrix();
$n{Key.new(0,0)} := self.fancyvalue(0);
$n{Key.new(1,0)} := self.fancyvalue(1);
$n{Key.new(2,0)} := self.fancyvalue(2);
$n{Key.new(3,0)} := self.fancyvalue(3);

$m.transpose();
assert_equal($m, $n, "cannot transpose with non-square dimensions");
}

# Test transposing square matrices
method test_METHOD_mem_transpose() {
todo("Tests Needed!");
my $m := self.matrix2x2(
self.fancyvalue(0),
self.fancyvalue(1),
self.fancyvalue(2),
self.fancyvalue(3)
);
my $n := self.matrix2x2(
self.fancyvalue(0),
self.fancyvalue(2),
self.fancyvalue(1),
self.fancyvalue(3)
);
$m.mem_transpose();
assert_equal($n, $m, "cannot mem_transpose matrix");
}

# Test transposing non-square matrices
method test_METHOD_mem_transpose_DIMCHANGE() {
todo("Tests Needed!");
my $m := self.matrix();
$m{Key.new(0,0)} := self.fancyvalue(0);
$m{Key.new(0,1)} := self.fancyvalue(1);
$m{Key.new(0,2)} := self.fancyvalue(2);
$m{Key.new(0,3)} := self.fancyvalue(3);

my $n := self.matrix();
$n{Key.new(0,0)} := self.fancyvalue(0);
$n{Key.new(1,0)} := self.fancyvalue(1);
$n{Key.new(2,0)} := self.fancyvalue(2);
$n{Key.new(3,0)} := self.fancyvalue(3);

$m.mem_transpose();
assert_equal($m, $n, "cannot mem_transpose with non-square dimensions");
}

# TODO: Come up with a good way to test that we are iterating and all values
# are correct
method test_METHOD_iterate_function_inplace() {
todo("Tests Needed!");
}
Expand Down
4 changes: 2 additions & 2 deletions t/pmc/charmatrix2d.t
Expand Up @@ -33,8 +33,8 @@ method defaultvalue() {
method nullvalue() {
return " ";
}
method fancyvalue() {
return "Z";
method fancyvalue($idx) {
return ["W", "X", "Y", "Z"][$idx];
}

method test_VTABLE_set_string_keyed_int() {
Expand Down
8 changes: 6 additions & 2 deletions t/pmc/complexmatrix2d.t
Expand Up @@ -33,8 +33,12 @@ method nullvalue() {
return (pir::new__PSP("Complex", "0+0i"));
}

method fancyvalue() {
return (pir::new__PSP("Complex", "9+9i"));
method fancyvalue($idx) {
return (
pir::new__PSP("Complex",
["6+6i", "7+7i", "8+8i", "9+9i"][$idx]
)
);
}

method matrix() {
Expand Down

0 comments on commit 6140e52

Please sign in to comment.