Skip to content

Commit

Permalink
add common tests for initialize_from_array and initialize_from_args. …
Browse files Browse the repository at this point in the history
…I think only nummatrix2d has these methods right now, so tests for other types fail.
  • Loading branch information
Whiteknight committed Mar 15, 2010
1 parent 6140e52 commit 455f275
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 71 deletions.
39 changes: 33 additions & 6 deletions t/Testcase.nqp
Expand Up @@ -313,27 +313,54 @@ class Pla::Testcase is UnitTest::Testcase {
}

method test_METHOD_initialize_from_array() {
todo("Tests Needed!");
my $a := [self.fancyvalue(0), self.fancyvalue(1), self.fancyvalue(2), self.fancyvalue(3)];
my $m := self.matrix2x2(self.fancyvalue(0), self.fancyvalue(1), self.fancyvalue(2), self.fancyvalue(3));
my $n := self.matrix();
$n.initialize_from_array(2, 2, $a);
assert_equal($n, $m, "cannot initialize_from_array");
}

method test_METHOD_initialize_from_array_ZEROPAD() {
todo("Tests Needed!");
my $a := [self.fancyvalue(0), self.fancyvalue(1), self.fancyvalue(2), self.fancyvalue(3)];
my $m := self.matrix3x3(self.fancyvalue(0), self.fancyvalue(1), self.fancyvalue(2),
self.fancyvalue(3), 0, 0,
0, 0, 0);
my $n := self.matrix();
$n.initialize_from_array(3, 3, $a);
assert_equal($n, $m, "cannot initalize from array with zero padding");
}

method test_METHOD_initialize_from_array_UNDERSIZE() {
todo("Tests Needed!");
my $a := [self.fancyvalue(0), self.fancyvalue(1), self.fancyvalue(2), self.fancyvalue(3)];
my $m := self.matrix();
$m{Key.new(0,0)} := self.fancyvalue(0);
my $n := self.matrix();
$n.initialize_from_array(1, 1, $a);
assert_equal($n, $m, "cannot initialize from array undersized");
}

method test_METHOD_initialize_from_args() {
todo("Tests Needed!");
my $m := self.matrix2x2(self.fancyvalue(0), self.fancyvalue(1), self.fancyvalue(2), self.fancyvalue(3));
my $n := self.matrix();
$n.initialize_from_array(2, 2, self.fancyvalue(0), self.fancyvalue(1), self.fancyvalue(2), self.fancyvalue(3));
assert_equal($n, $m, "cannot initialize_from_args");
}

method test_METHOD_initialize_from_args_ZEROPAD() {
todo("Tests Needed!");
my $m := self.matrix3x3(self.fancyvalue(0), self.fancyvalue(1), self.fancyvalue(2),
self.fancyvalue(3), 0, 0,
0, 0, 0);
my $n := self.matrix();
$n.initialize_from_array(3, 3, self.fancyvalue(0), self.fancyvalue(1), self.fancyvalue(2), self.fancyvalue(3));
assert_equal($n, $m, "cannot initalize from args with zero padding");
}

method test_METHOD_initialize_from_args_UNDERSIZE() {
todo("Tests Needed!");
my $m := self.matrix();
$m{Key.new(0,0)} := self.fancyvalue(0);
my $n := self.matrix();
$n.initialize_from_array(1, 1, self.fancyvalue(0), self.fancyvalue(1), self.fancyvalue(2), self.fancyvalue(3));
assert_equal($n, $m, "cannot initialize from args undersized");
}

method test_METHOD_get_block() {
Expand Down
14 changes: 0 additions & 14 deletions t/pmc/complexmatrix2d.t
Expand Up @@ -100,20 +100,6 @@ method test_VTABLE_get_string() {
todo("Tests Needed!");
}
method test_METHOD_transpose() {
my $m := self.matrix2x2("1+1i", "2+2i", "3+3i", "4+4i");
my $n := self.matrix2x2("1+1i", "3+3i", "2+2i", "4+4i");
$m.transpose();
assert_equal($m, $n, "transpose does not work");
}

method test_METHOD_mem_transpose() {
my $m := self.matrix2x2("1+1i", "2+2i", "3+3i", "4+4i");
my $n := self.matrix2x2("1+1i", "3+3i", "2+2i", "4+4i");
$m.mem_transpose();
assert_equal($m, $n, "mem_transpose does not work");
}

method test_METHOD_conjugate() {
my $m := self.matrix2x2("1+1i", "2+2i", "3+3i", "4+4i");
my $n := self.matrix2x2("1-1i", "2-2i", "3-3i", "4-4i");
Expand Down
51 changes: 0 additions & 51 deletions t/pmc/nummatrix2d.t
Expand Up @@ -233,57 +233,6 @@ method test_VTABLE_multiply_FLOAT() {
assert_equal($n, $p, "multiply matrix * float");
}

method test_METHOD_transpose() {
my $m := self.matrix3x3(1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0);
my $n := self.matrix3x3(1.0, 4.0, 7.0,
2.0, 5.0, 8.0,
3.0, 6.0, 9.0);
$m.transpose();
assert_equal($m, $n, "transpose does not work");
}

method test_METHOD_mem_transpose() {
my $m := self.matrix3x3(1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0);
my $n := self.matrix3x3(1.0, 4.0, 7.0,
2.0, 5.0, 8.0,
3.0, 6.0, 9.0);
$m.mem_transpose();
assert_equal($m, $n, "transpose does not work");
}

method test_METHOD_initialize_from_array() {
my $m := self.matrix();
my $n := [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0];
my $o := self.matrix3x3(1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0);
$m.initialize_from_array(3, 3, $n);
assert_equal($m, $o, "array initialization does not work");
}

method test_METHOD_initialize_from_array_ZEROPAD() {
my $m := self.matrix();
my $n := [1.0, 2.0, 3.0, 4.0, 5.0];
my $o := self.matrix3x3(1.0, 2.0, 3.0,
4.0, 5.0, 0.0,
0.0, 0.0, 0.0);
$m.initialize_from_array(3, 3, $n);
assert_equal($m, $o, "array initialization zero-padding does not work");
}

method test_METHOD_initialize_from_array_UNDERSIZE() {
my $m := self.matrix();
my $n := [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0];
my $o := self.matrix2x2(1.0, 2.0,
3.0, 4.0);
$m.initialize_from_array(2, 2, $n);
assert_equal($m, $o, "array initialization does not work");
}

method test_METHOD_initialize_from_args() {
my $m := self.matrix();
my $n := self.matrix3x3(1.0, 2.0, 3.0,
Expand Down

0 comments on commit 455f275

Please sign in to comment.