From bee5da18dc0bebb34a946b182f4148d936b1436b Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Mon, 15 Mar 2010 10:19:42 -0400 Subject: [PATCH] fix ComplexMatrix2D.fill() to work. Add a passing test for the behavior. Also, expand several other TODO tests --- src/pmc/complexmatrix2d.pmc | 2 +- t/pmc/complexmatrix2d.t | 55 ++++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/pmc/complexmatrix2d.pmc b/src/pmc/complexmatrix2d.pmc index 15cc573..e161ae7 100644 --- a/src/pmc/complexmatrix2d.pmc +++ b/src/pmc/complexmatrix2d.pmc @@ -420,7 +420,7 @@ sizes, growing the matrix if needed. for (rows = 0; rows < rows_size; ++rows) { for (cols = 0; cols < cols_size; ++cols) { - /*ITEM_XY_ROWMAJOR(s, rows_size, cols_size, rows, cols) = value;*/ + set_complex_pmc_at_xy(INTERP, SELF, value, rows, cols); } } } diff --git a/t/pmc/complexmatrix2d.t b/t/pmc/complexmatrix2d.t index 529e5f6..8fe3e13 100644 --- a/t/pmc/complexmatrix2d.t +++ b/t/pmc/complexmatrix2d.t @@ -60,7 +60,7 @@ method test_VTABLE_get_string_keyed() { method test_VTABLE_get_pmc_keyed() { my $m := Parrot::new("ComplexMatrix2D"); - my $a := Parrot::new__PSP("Complex", "1+1i); + my $a := pir::new__PSP("Complex", "1+1i"); $m{Key.new(0,0)} := $a; my $b := $m{Key.new(0,0)}; assert_equal($a, $b, "get_pmc_keyed doesn't work"); @@ -99,24 +99,65 @@ method test_VTABLE_get_string() { todo("Tests Needed!"); } -method test_VTABLE_get_attr_string() { - todo("Tests Needed!"); +method test_VTABLE_get_attr_str_EMPTY() { + my $m := Parrot::new("ComplexMatrix2D"); + assert_equal(pir::getattribute__PPS($m, "rows"), 0, "empty matrix has non-zero row count"); + assert_equal(pir::getattribute__PPS($m, "cols"), 0, "empty matrix has non-zero col count"); +} + +method test_VTABLE_get_attr_str() { + my $m := Parrot::new("ComplexMatrix2D"); + $m{Key.new(5,7)} := 1; + assert_equal(pir::getattribute__PPS($m, "rows"), 6, "matrix does not have right size"); + assert_equal(pir::getattribute__PPS($m, "cols"), 8, "matrix does not have right size"); } method test_VTABLE_clone() { - todo("Tests Needed!"); + my $m := matrix2x2("1+1i", "2+2i", "3+3i", "4+4i"); + my $n := pir::clone($m); + assert_equal($m, $n, "clones are not equal"); + assert_not_same($m, $n, "clones are the same PMC!"); } method test_VTABLE_is_equal() { - todo("Tests Needed!"); + my $m := matrix2x2("1+1i", "2+2i", "3+3i", "4+4i"); + my $n := matrix2x2("1+1i", "2+2i", "3+3i", "4+4i"); + assert_equal($m, $n, "equal matrices are not equal"); +} + +method test_VTABLE_is_equal_SIZEFAIL() { + my $m := matrix2x2("1+1i", "2+2i", "3+3i", "4+4i"); + my $n := matrix2x2("1+1i", "2+2i", "3+3i", "4+4i"); + $n{Key.new(2, 2)} := pir::new__PSP("Complex", "0+0i"); + assert_not_equal($m, $n, "different sized matrices are equal"); +} + +method test_VTABLE_is_equal_ELEMSFAIL() { + my $m := matrix2x2("1+1i", "2+2i", "3+3i", "4+4i"); + my $n := matrix2x2("1+1i", "2+2i", "3+3i", "5+5i"); + assert_not_equal($m, $n, "non-equal matrices are equal"); } method test_METHOD_resize() { - todo("Tests Needed!"); + my $m := Parrot::new("ComplexMatrix2D"); + $m.resize(3,3); + assert_equal(pir::getattribute__PPS($m, "rows"), 3, "matrix does not have right size"); + assert_equal(pir::getattribute__PPS($m, "cols"), 3, "matrix does not have right size"); +} + +method test_METHOD_resize_SHRINK() { + my $m := Parrot::new("ComplexMatrix2D"); + $m.resize(3,3); + $m.resize(1,1); + assert_equal(pir::getattribute__PPS($m, "rows"), 3, "matrix does not have right size"); + assert_equal(pir::getattribute__PPS($m, "cols"), 3, "matrix does not have right size"); } method test_METHOD_fill() { - todo("Tests Needed!"); + my $m := matrix2x2("1+1i", "1+1i", "1+1i", "1+1i"); + my $n := Parrot::new("ComplexMatrix2D"); + $n.fill(pir::new__PSP("Complex", "1+1i"), 2, 2); + assert_equal($n, $m, "Cannot fill"); } method test_METHOD_transpose() {