Skip to content

Commit

Permalink
Add in a test class for subclassing behavior in ComplexMatrix2D. Also…
Browse files Browse the repository at this point in the history
…, I made a change to the init_from_pmc_array function, which I thought was necessary but turns out to not be (though I do prefer a solution of this form, for future reference). This is causing some test failures, so I need to debug that later
  • Loading branch information
Whiteknight committed Sep 9, 2010
1 parent ac8772b commit 73ed80c
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 18 deletions.
33 changes: 17 additions & 16 deletions src/pmc/complexmatrix2d.pmc
Expand Up @@ -112,22 +112,6 @@ resize_matrix(PARROT_INTERP, PMC * self, INTVAL row, INTVAL col)
mem_sys_free(old_s);
}

static void
init_from_pmc_array(PARROT_INTERP, PMC * self, INTVAL rows_size,
INTVAL cols_size, PMC * values)
{
DECLATTRS_ComplexMatrix2D(self, attrs);
INTVAL num = 0;
const INTVAL init_elems = VTABLE_elements(interp, values);
const INTVAL total_elems = rows_size * cols_size;
resize_matrix(interp, self, rows_size - 1, cols_size - 1);

for (; num < init_elems && num < total_elems ; num++) {
PMC * const value = VTABLE_get_pmc_keyed_int(interp, values, num);
VTABLE_set_pmc_keyed_int(interp, self, num, value);
}
}

static PMC *
get_complex_pmc_at_xy(PARROT_INTERP, PMC *self, INTVAL rows, INTVAL cols)
{
Expand Down Expand Up @@ -192,6 +176,23 @@ set_scalar_at_xy(PARROT_INTERP, PMC * self, FLOATVAL value, INTVAL row,
I_ITEM_XY(s, flags, rows_size, cols_size, row, col) = 0;
}

static void
init_from_pmc_array(PARROT_INTERP, PMC * self, INTVAL rows_size,
INTVAL cols_size, PMC * values)
{
DECLATTRS_ComplexMatrix2D(self, attrs);
INTVAL i, j, num = 0;
resize_matrix(interp, self, rows_size - 1, cols_size - 1);

for (i = 0; i < rows_size; i++) {
for (j = 0; j < cols_size; j++) {
PMC * const value = VTABLE_get_pmc_keyed_int(interp, values, num);
set_complex_pmc_at_xy(interp, self, value, i, j);
num++;
}
}
}

/* Add a scalar to every element of the matrix */
static void
add_scalar_float(PARROT_INTERP, PMC * self, FLOATVAL v)
Expand Down
4 changes: 2 additions & 2 deletions t/harness
Expand Up @@ -25,7 +25,7 @@ sub MAIN () {
't/methods/nummatrix2d',
't/methods/complexmatrix2d',
't/methods/pmcmatrix2d',
#'t/pir-subclass'
't/pir-subclass'
);
my %failures := {};

Expand Down Expand Up @@ -188,4 +188,4 @@ sub is_pir_test($filename) {
return 1;
}
return 0;
}
}
78 changes: 78 additions & 0 deletions t/pir-subclass/complexmatrix2d.t
@@ -0,0 +1,78 @@
#!parrot


.HLL 'ComplexMatrix2D_SUBCLASS_TEST'

.sub test
$P0 = get_class 'Complex'
$P1 = subclass $P0, 'TestComplex'
$P2 = getinterp
$P2.'hll_map'($P0, $P1)

$P0 = get_class 'Integer'
$P1 = subclass $P0, 'TestInteger'
$P2.'hll_map'($P0, $P1)

$P3 = box 0
set_hll_global ['Test'], '_count', $P3

say "1..5"
test_get_pmc_keyed()
#test_get_pmc_keyed_int()
test_get_attr_str()
.end

.sub is_TestComplex
.param pmc arg

$S0 = typeof arg
if $S0 == 'TestComplex' goto are_equal
print "not "
are_equal:
print "ok "
$P0 = get_hll_global ['Test'], '_count'
inc $P0
say $P0
.end

.sub is_TestInteger
.param pmc arg

$S0 = typeof arg
if $S0 == 'TestInteger' goto are_equal
print "not "
are_equal:
print "ok "
$P0 = get_hll_global ['Test'], '_count'
inc $P0
say $P0
.end

.sub test_get_pmc_keyed
$P0 = new ['ComplexMatrix2D']
$P0.'initialize_from_args'(2, 2, 1, 2, 3, 4)
$P1 = $P0[0;0]
is_TestComplex($P1)
.end

.sub test_get_pmc_keyed_int
$P0 = new ['ComplexMatrix2D']
$P0.'initialize_from_args'(2, 2, 1, 2, 3, 4)
$P1 = $P0[0]
is_TestComplex($P1)
.end

.sub test_get_attr_str
$P0 = new ['NumMatrix2D']
$P0.'initialize_from_args'(2, 2, 1, 2, 3, 4)

$P1 = getattribute $P0, 'rows'
is_TestInteger($P1)

$P1 = getattribute $P0, 'cols'
is_TestInteger($P1)

$P1 = getattribute $P0, 'size'
is_TestInteger($P1)
.end

0 comments on commit 73ed80c

Please sign in to comment.