Skip to content

Commit

Permalink
Major refactor to the test suite. Break up the single matrixtest.nqp …
Browse files Browse the repository at this point in the history
…file into several smaller files for manageability. During the build we compile these files and merge them together into t/testlib/pla_test.pbc, which can be loaded for a modest startup time improvement. Break out a subclass NumericMatrixTest which I can use to test the Num and Complex matrices for common math operations
  • Loading branch information
Whiteknight committed Aug 17, 2010
1 parent f1eae20 commit 0fc9e91
Show file tree
Hide file tree
Showing 12 changed files with 262 additions and 177 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -8,3 +8,4 @@ Makefile
*_group.*
src/pmc/pmc_*.h
src/nqp/*.pir
t/testlib/*.pir
14 changes: 14 additions & 0 deletions setup.pir
Expand Up @@ -66,10 +66,24 @@ SOURCES

$P2 = new 'Hash'
$P2["src/nqp/pla.pir"] = "src/nqp/pla.nqp"
$P2["t/testlib/matrixtestbase.pir"] = "t/testlib/matrixtestbase.nqp"
$P2["t/testlib/matrixtest.pir"] = "t/testlib/matrixtest.nqp"
$P2["t/testlib/numericmatrixtest.pir"] = "t/testlib/numericmatrixtest.nqp"
$P2["t/testlib/loader.pir"] = "t/testlib/loader.nqp"
$P0["pir_nqp-rx"] = $P2

$P2 = new "ResizablePMCArray"
push $P2, "t/testlib/matrixtestbase.pir"
push $P2, "t/testlib/matrixtest.pir"
push $P2, "t/testlib/numericmatrixtest.pir"
push $P2, "t/testlib/loader.pir"
$P1 = new 'Hash'
$P1["t/testlib/pla_test.pir"] = $P2
$P0["pir_pir"] = $P1

$P2 = new 'Hash'
$P2["pla_nqp.pbc"] = "src/nqp/pla.pir"
$P2["t/testlib/pla_test.pbc"] = "t/testlib/pla_test.pir"
$P0["pbc_pir"] = $P2

$P2 = new 'ResizablePMCArray'
Expand Down
2 changes: 1 addition & 1 deletion t/harness
Expand Up @@ -2,7 +2,7 @@

INIT {
pir::load_bytecode('library/kakapo_full.pbc');
Nqp::compile_file('t/testlib/matrixtest.nqp');
pir::load_bytecode('t/testlib/pla_test.pbc');
}

MAIN();
Expand Down
2 changes: 1 addition & 1 deletion t/pmc/charmatrix2d.t
@@ -1,4 +1,4 @@
class Test::CharMatrix2D is Pla::Matrix::Testcase;
class Test::CharMatrix2D is Pla::Matrix::MatrixTest;

INIT {
use('UnitTest::Testcase');
Expand Down
6 changes: 3 additions & 3 deletions t/pmc/complexmatrix2d.t
@@ -1,4 +1,4 @@
class Test::ComplexMatrix2D is Pla::Matrix::Testcase;
class Test::ComplexMatrix2D is Pla::Matrix::NumericMatrixTest;

INIT {
use('UnitTest::Testcase');
Expand All @@ -13,7 +13,7 @@ sub MAIN() {
$proto.suite.run;
}

method defaultvalue() {
our method defaultvalue() {
return (pir::new__PSP("Complex", "1+1i"));
}

Expand All @@ -29,7 +29,7 @@ method fancyvalue($idx) {
);
}

method matrix() {
our method matrix() {
my $m := Parrot::new("ComplexMatrix2D");
return ($m);
}
Expand Down
8 changes: 7 additions & 1 deletion t/pmc/nummatrix2d.t
@@ -1,4 +1,4 @@
class Test::NumMatrix2D is Pla::Matrix::Testcase;
class Test::NumMatrix2D is Pla::Matrix::MatrixTest;

# Test boilerplate.

Expand All @@ -21,6 +21,12 @@ method matrix() {
return ($m);
}

method defaultvalue() { 1.0; }
method nullvalue() { 0.0; }
method fancyvalue($idx) {
[5.1, 6.2, 7.3, 8.4][$idx];
}

# TODO: Need to add lots more tests for is_equal. It uses a new float
# comparison algorithm that I want to really exercise.

Expand Down
8 changes: 5 additions & 3 deletions t/pmc/pmcmatrix2d.t
@@ -1,4 +1,4 @@
class Test::PmcMatrix2D is Pla::Matrix::Testcase;
class Test::PmcMatrix2D is Pla::Matrix::MatrixTest;

INIT {
use('UnitTest::Testcase');
Expand All @@ -15,8 +15,10 @@ method matrix() {
return (Parrot::new("PMCMatrix2D"));
}

method nullvalue() {
return (pir::null__P());
method defaultvalue() { 1; }
method nullvalue() { return (pir::null__P()); }
method fancyvalue($idx) {
[5, 6, 7, 8][$idx];
}

method test_VTABLE_get_integer_keyed() {
Expand Down
3 changes: 1 addition & 2 deletions t/run_test.pir
Expand Up @@ -2,8 +2,7 @@
.sub "" :load :init
load_bytecode "nqp-rx.pbc"
load_bytecode "./library/kakapo_full.pbc"
$P0 = get_hll_global ["Nqp"], "compile_file"
$P0("t/testlib/matrixtest.nqp")
load_bytecode "t/testlib/pla_test.pbc"
loadlib $P33, "./linalg_group"
.end

Expand Down
34 changes: 34 additions & 0 deletions t/testlib/loader.nqp
@@ -0,0 +1,34 @@

class Pla::Matrix::Loader is UnitTest::Loader {

method order_tests(@tests) {
my $test_method := 'test_ME';
my $test_op := 'test_OP';
my $test_vtable := 'test_VT';

my $len := $test_op.length; # The shortest

my %partition;
for <test_me test_op test_vt MISC> {
%partition{$_} := [ ];
}

for @tests -> $name {
my $name_lc := pir::downcase__SS($name).substr(0, $len);

if %partition.contains( $name_lc ) {
%partition{$name_lc}.push: $name;
}
else {
%partition<MISC>.push: $name;
}
}

my @result;
for <test_op test_vt MISC test_me> {
@result.append: %partition{$_}.unsort;
}

@result;
}
}

0 comments on commit 0fc9e91

Please sign in to comment.