From 455f2750c62fc894bdd80fc927e7d92489e1e234 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Mon, 15 Mar 2010 14:39:16 -0400 Subject: [PATCH] add common tests for initialize_from_array and initialize_from_args. I think only nummatrix2d has these methods right now, so tests for other types fail. --- t/Testcase.nqp | 39 ++++++++++++++++++++++++++----- t/pmc/complexmatrix2d.t | 14 ----------- t/pmc/nummatrix2d.t | 51 ----------------------------------------- 3 files changed, 33 insertions(+), 71 deletions(-) diff --git a/t/Testcase.nqp b/t/Testcase.nqp index b742471..44bf10b 100644 --- a/t/Testcase.nqp +++ b/t/Testcase.nqp @@ -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() { diff --git a/t/pmc/complexmatrix2d.t b/t/pmc/complexmatrix2d.t index e4aefa9..2e52bae 100644 --- a/t/pmc/complexmatrix2d.t +++ b/t/pmc/complexmatrix2d.t @@ -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"); diff --git a/t/pmc/nummatrix2d.t b/t/pmc/nummatrix2d.t index fd420b8..32cae84 100644 --- a/t/pmc/nummatrix2d.t +++ b/t/pmc/nummatrix2d.t @@ -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,