From fd5542acb6b9f32db510896410e524df9fe47340 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Mon, 23 Nov 2009 13:04:31 -0500 Subject: [PATCH] start segregating test files --- config/makefiles/root.in | 2 +- t/functions/200-zeros.t | 13 ++++ t/functions/201-eye.t | 17 ++++ t/functions/202-isequal.t | 34 ++++++++ t/functions/203-sprintf.t | 10 +++ t/functions/204-arrayfun.t | 37 +++++++++ t/functions/205-ones.t | 11 +++ t/functions/206-computer.t | 17 ++++ t/functions/300-transpose.t | 45 +++++++++++ t/functions/301-mtimes.t | 17 ++++ t/functions/302-floor-ceil-round.t | 36 +++++++++ t/functions/303-matrix-operations.t | 117 ++++++++++++++++++++++++++++ t/functions/304-isscalar.t | 17 ++++ t/functions/306-inverse.t | 17 ++++ t/functions/307-abs-max-min.t | 21 +++++ t/functions/308-loadlibrary.t | 19 +++++ 16 files changed, 429 insertions(+), 1 deletion(-) create mode 100644 t/functions/200-zeros.t create mode 100644 t/functions/201-eye.t create mode 100644 t/functions/202-isequal.t create mode 100644 t/functions/203-sprintf.t create mode 100644 t/functions/204-arrayfun.t create mode 100644 t/functions/205-ones.t create mode 100644 t/functions/206-computer.t create mode 100644 t/functions/300-transpose.t create mode 100644 t/functions/301-mtimes.t create mode 100644 t/functions/302-floor-ceil-round.t create mode 100644 t/functions/303-matrix-operations.t create mode 100644 t/functions/304-isscalar.t create mode 100644 t/functions/306-inverse.t create mode 100644 t/functions/307-abs-max-min.t create mode 100644 t/functions/308-loadlibrary.t diff --git a/config/makefiles/root.in b/config/makefiles/root.in index 2d75836..3947ba9 100644 --- a/config/makefiles/root.in +++ b/config/makefiles/root.in @@ -89,7 +89,7 @@ help: @echo "" test: all - $(PERL) t/harness t/*t + $(PERL) t/harness t/*t t/syntax/*t t/functions/*t install: all # plaaceholder, we don't install yet. diff --git a/t/functions/200-zeros.t b/t/functions/200-zeros.t new file mode 100644 index 0000000..302b566 --- /dev/null +++ b/t/functions/200-zeros.t @@ -0,0 +1,13 @@ +plan(3); + +x = zeros(1, 1); +y = [0]; +ok(isequal(x,y), "zeros(1,1) works"); + +x = zeros(3, 3); +y = [0 0 0;0 0 0;0 0 0]; +ok(isequal(x,y), "zeros(3,3) works"); + +x = zeros(4, 7); +y = [ 0 0 0 0 0 0 0; 0 0 0 0 0 0 0; 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 ]; +ok(isequal(x,y), "zeros with non-same args returns what we expect"); diff --git a/t/functions/201-eye.t b/t/functions/201-eye.t new file mode 100644 index 0000000..9b48512 --- /dev/null +++ b/t/functions/201-eye.t @@ -0,0 +1,17 @@ +plan(3); + +X1 = eye(1); +Y1 = [1]; + +% Test that eye(1) does what we think it should +ok(isequal(X1, Y1), "eye(1) does what we want"); + +% Test that eye(3) does what we think it does +X2 = eye(3); +Y2 = [1,0,0;0,1,0;0,0,1]; +ok(isequal(X2, Y2), "eye(3) does what we think it does"); + +% Test eye(4) +X3 = eye(4); +Y3 = [1,0,0,0;0,1,0,0;0,0,1,0;0,0,0,1]; +ok(isequal(X3, Y3), "eye(4) does what we think it does"); diff --git a/t/functions/202-isequal.t b/t/functions/202-isequal.t new file mode 100644 index 0000000..d466c7b --- /dev/null +++ b/t/functions/202-isequal.t @@ -0,0 +1,34 @@ +plan(6) + +% Test inequality of same-sized matrices +A1 = [1,2;3,4]; +B1 = [5,6;7,8]; +nok(isequal(A1, B1), "isequal() fails on non-same matrices"); + +% Test equality of same-sized matrices +A2 = [1,2;3,4;5,6]; +B2 = [1,2;3,4;5,6]; +ok(isequal(A2, B2), "isequal() succeeds with two same matrices"); + +% Test equality of three matrices, each the same size and shape +A3 = [1,2;3,4;5,6]; +B3 = [1,2;3,4;5,6]; +C3 = [1,2;3,4;5,6]; +ok(isequal(A3, B3, C3), "isequal() succeeds on three same matrices"); + +% Test inequality of three matrices, each the same size and shape +A4 = [1,2;3,4;5,6]; +B4 = [1,2;0,0;5,6]; +C4 = [1,2;3,4;5,6]; +nok(isequal(A4, B4, C4), "isequal() fails on three non-same matrices"); + +% Test inequality of three matrices of different sizes +A5 = [1,2;3,4;5,6;7,8]; +B5 = [1,2;3,4;5,6]; +C5 = [1,2;3,4;5,6]; +nok(isequal(A5, B5, C5), "isequal() fails on three matrices of different sizes"); + +% Test inequality of two matrices of different sizes +A6 = [1,2;5,6;7,8]; +B6 = [1,2;5,6]; +nok(isequal(A6, B6), "isequal() fails on two matrices of different sizes"); diff --git a/t/functions/203-sprintf.t b/t/functions/203-sprintf.t new file mode 100644 index 0000000..1a7d2ae --- /dev/null +++ b/t/functions/203-sprintf.t @@ -0,0 +1,10 @@ +plan(3); + +a = sprintf("%d", 5); +ok(a == "5", "sprintf() with a %d"); + +a = sprintf("%s world", "hello"); +ok(a == "hello world", "sprinf() with a %s"); + +a = sprintf("%.2f", 123.456789); +is(a, "123.46", "sprintf() with %f and modifiers"); diff --git a/t/functions/204-arrayfun.t b/t/functions/204-arrayfun.t new file mode 100644 index 0000000..d6d49f4 --- /dev/null +++ b/t/functions/204-arrayfun.t @@ -0,0 +1,37 @@ +plan(6) + +function y = f(x) y=x+1; endfunction +A = [1 2 3; 4 5 6]; +B = [2,3,4; 5,6,7]; + +A1 = arrayfun(@(x)f(x), A); +is(A1, B, "arrayfun() with an anon func handle"); + +A2 = arrayfun("f", A); +is(A2, B, "arrayfun() with a function name and matrix arg"); + +A3 = arrayfun("f", 10); +ok(A3 == 11, "arrayfun() with a function name and scalar arg"); + +A = [1 2; 3 4]; +B = [2 2; 2 2]; +C = [2 4; 6 8]; +D = arrayfun(@(x,y) x*y, A, B); +is(C, D, "arrayfun() on two matrices with an anon func handle"); + +function y = f1(a,b,c) y = a+b+c; endfunction + +A = [1.1 2.2; 3.3 4.4]; +B = [2 2; 2 2]; +C = [0.01 0.002; 0.0003 0.0004]; +D = [3.11 4.2020; 5.3003 6.4004]; +E = arrayfun("f1", A, B, C); +is(D, E, "arrayfun() with three matrices and a named function"); + +A = 3; +B = 5; +C = 15; +D = 23; +E = arrayfun("f1", A, B, C); +is(D, E, "arrayfun() on three scalars and a named function"); + diff --git a/t/functions/205-ones.t b/t/functions/205-ones.t new file mode 100644 index 0000000..4e18326 --- /dev/null +++ b/t/functions/205-ones.t @@ -0,0 +1,11 @@ +plan(3); + +x = ones(1, 1); +is(x(1, 1), 1, "the first element is 1"); + +x = ones(3, 3); +ok(x(1, 1) + x(2, 2) + x(3, 3) == 3, "an assortment of values are 1"); + +x = ones(4, 7); +y = [ 1 1 1 1 1 1 1; 1 1 1 1 1 1 1; 1 1 1 1 1 1 1; 1 1 1 1 1 1 1 ]; +is(x, y, "ones() with arguments that aren't equal"); diff --git a/t/functions/206-computer.t b/t/functions/206-computer.t new file mode 100644 index 0000000..3440451 --- /dev/null +++ b/t/functions/206-computer.t @@ -0,0 +1,17 @@ +plan(1); + +support = 0; +comp = computer(); +if comp == "i386-MSWin32" + support = 1; +endif +if comp == "i386-linux" + support = 1; +endif +if comp == "amd64-linux" + support = 1; +endif + + +ok(support, "check we run on a supported platform"); + diff --git a/t/functions/300-transpose.t b/t/functions/300-transpose.t new file mode 100644 index 0000000..504babb --- /dev/null +++ b/t/functions/300-transpose.t @@ -0,0 +1,45 @@ +plan(9) + +A = [ 1, 2, 3, 4 + 5, 6, 7, 8 + 9, 10, 11, 12 + 13, 14, 15, 16]; +X = [1, 5, 9, 13 + 2, 6, 10, 14 + 3, 7, 11, 15 + 4, 8, 12, 16]; +Y = transpose(A); +is(X, Y, "transpose() on matrix"); + +% Make sure we aren't tranposing A in place +ok(Y != A, "We aren't just transposing A in place"); + +Y = A'; +is(X, Y, "transpose op ' on matrix"); + + + +A = [1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12; 13, 14, 15, 16; 17, 18, 19, 20]; +X = [1, 5, 9, 13, 17; 2, 6, 10, 14, 18; 3, 7, 11, 15, 19; 4, 8, 12, 16, 20]; +Y = transpose(A); +is(X, Y, "transpose() on non square matrix"); + +Y = A'; +is(X, Y, "transpose op ' on non square matrix"); + + +A = [ 1+2i 2+3i; 3+4i 4+5i]; +X = [ 1+2i 3+4i; 2+3i 4+5i]; +Y = transpose(A); +is(X, Y, "transpose() on complex matrix"); + +Y = A.'; +is(X, Y, "transpose op .' on complex matrix"); + +X = [ 1-2i 3-4i; 2-3i 4-5i]; +Y = ctranspose(A); +is(X, Y, "ctranspose() on complex matrix"); + +Y = A'; +is(X, Y, "ctranspose op ' on complex matrix"); + diff --git a/t/functions/301-mtimes.t b/t/functions/301-mtimes.t new file mode 100644 index 0000000..950039e --- /dev/null +++ b/t/functions/301-mtimes.t @@ -0,0 +1,17 @@ +plan(3) + +A = [1,2;3,4]; +B = [5,6;7,8]; +C = [19,22;43,50]; +is(mtimes(A, B), C, "product 2 square matrices"); + +A = [1,2;3,4;5,6]; +B = [7,8,9;10,11,12]; +C = [27,30,33;61,68,75;95,106,117]; +is(mtimes(A, B), C, "product 2 non square matrices") + +A = [ 1+2i 2+3i ; 4+5i 6+7i; 8+9i 9+1i ]; +B = [ 1+2i 2+3i 3+4i; 5+6i 7+8i 9+1i ]; +C = [ -11+31i, -14+44i, 10+39i; -18+84i, -21+119i, 39+100i; 29+84i, 44+121i, 68+77i ]; +is(mtimes(A, B), C, "product 2 non square complex matrices") + diff --git a/t/functions/302-floor-ceil-round.t b/t/functions/302-floor-ceil-round.t new file mode 100644 index 0000000..68a5454 --- /dev/null +++ b/t/functions/302-floor-ceil-round.t @@ -0,0 +1,36 @@ +plan(7); + +A = [2.3 4.5; 6.7 8.9]; +B = [2 4; 6 8]; +B1 = floor(A); +is(B1, B, "floor() on a matrix"); + +A = 10.2; +B = 10; +B1 = floor(A); +is(B1, B, "floor() on a scalar"); + +A = [2.3 4.5; 6.7 8.9]; +B = [3 5; 7 9]; +B1 = ceil(A); +is(B1, B, "ceil() on a matrix"); + +A = 20.3; +B = 21; +B1 = ceil(A); +is(B1, B, "ceil() on a scalar"); + +A = [2.3 4.5; 4.49 9.51]; +B = [2 5; 4 10]; +B1 = round(A); +is(B1, B, "round() on a matrix"); + +A = 10.49; +B = 10; +B1 = round(A); +is(B1, B, "round() on a scalar (round down)"); + +A = 10.50; +B = 11; +B1 = round(A); +is(B1, B, "round() on a scalar (round up)"); diff --git a/t/functions/303-matrix-operations.t b/t/functions/303-matrix-operations.t new file mode 100644 index 0000000..a04c7dd --- /dev/null +++ b/t/functions/303-matrix-operations.t @@ -0,0 +1,117 @@ +plan(27); + +a = 123; +b = 789; +A = [4 25; 9 16]; +B = [1 2; 3 4]; + +% Add two matrices +X = [5 27; 12 20]; +Y = plus(A,B); +is(X, Y, "add two matrices"); + +Y = A + B; +is(X, Y, "Symbolic + two matrices"); + +x = 912; +y = plus(a,b); +is(x, y, "plus() two scalars"); + +y = a + b; +is(x, y, "symbolic + two scalars"); + +% Minus +X = [3 23; 6 12]; +Y = minus(A,B); +is(X, Y, "subtract two matrices"); + +Y = A-B; +is(X, Y, "symbolic sybtract two matrices"); + +x = -666; +y = minus(a,b); +is(x, y, "minus a negative scalar"); + +y = a-b; +is(x, y, "symbolic - two scalars"); + +% Times +X = [4 50; 27 64]; +Y = times(A,B); +is(X, Y, "times() tow matrices"); + +Y = A.*B; +is(X, Y, "Symbolic .* two matrices"); + +x = 97047; +y = times(a,b); +is(x, y, "times() two scalars"); + +X = [4 50; 27 64]; +y = a.*b; +is(x, y, "symbolic .* two scalars"); + +X = [3156 19725; 7101 12624]; +Y = A.*b; +is(X, Y, "symbolic .* a matrix and a scalar"); + +X = [123 246 ; 369 492]; +Y = a.*B; +is(X, Y, "symbolic .* a scalar and a matrix"); + +% RDivide +X = [4.0 12.5; 3.0 4.0]; +Y = rdivide(A, B); +is(X, Y, "rdivide() two matrices"); + +Y = A./B; +is(X, Y, "symbolic ./ two matrices"); + +x = 4; +y = rdivide(20, 5); +is(x, y, "rdivide() two scalars"); + +y = 20./5; +is(x, y, "symbolic ./ two scalars"); + +X = [ 2 12.5; 4.5 8 ]; +Y = A./2; +is(X, Y, "symbolic ./ a matrix and a scalar"); + +% LDivide +m100 = [100 100; 100 100]; +X = [0.25 0.08; 0.333333 0.25]; +Y = ldivide(A, B); +is(floor(times(X, m100)), floor(times(Y, m100)), "ldivide() two matrices"); + +% TODO: syntax error currently +start_todo("syntax error on symbolic .\\"); + ok(0, "symbolic .\\ on two matrices"); + %Y = A.\B; + %is(floor(times(X, m100)), floor(times(Y, m100)), "symbolic .\\ on two matrices"); +end_todo(); + +x = 9; +y = ldivide(3, 27); +is(x, y, "ldivide() two scalars"); + +start_todo("syntax error on symbolic .\\"); + ok(0, "symbolic .\\ on two scalars"); + %y = 3.\27; + %is(x, y, "symbolic .\\ on two scalars"); +end_todo(); + +% Power +X = [4 625; 729 65536]; +Y = power(A, B); +is(X, Y, "power() on two matrices"); + +Y = A.^B; +is(X, Y, "Symbolic .^ on two matrices"); + +x = 15129; +y = power(a, 2); +is(x, y, "power() on two scalars"); + +y = a.^2; +is(x, y, "symbolic .^ on two scalars"); diff --git a/t/functions/304-isscalar.t b/t/functions/304-isscalar.t new file mode 100644 index 0000000..992c0aa --- /dev/null +++ b/t/functions/304-isscalar.t @@ -0,0 +1,17 @@ +plan(5); + +x1 = 1; +x2 = [ 1 ]; +x3 = [ 1 1 ]; +x4 = [ 1; 1]; +x5 = ones(2,3); + +ok(isscalar(x1), "isscalar"); + +ok(isscalar(x2), "isscalar 2"); + +is(isscalar(x3), 0, "row vector is not scalar"); + +is(isscalar(x4), 0, "col vector is not scalar"); + +is(isscalar(x5), 0, "matrix is not scalar"); diff --git a/t/functions/306-inverse.t b/t/functions/306-inverse.t new file mode 100644 index 0000000..92aed59 --- /dev/null +++ b/t/functions/306-inverse.t @@ -0,0 +1,17 @@ +if libisloaded('CLAPACK') + plan(2) + + A1 = [ 1 2 ; 3 4]; + B1 = [-2, 1; 1.5, -0.5]; + C1 = inverse(A1); + is(round(10.*B1), round(10.*C1), "invert 2x2") + + A1 = [1,5,2; 1,1,7; 0,-3,4]; + B1 = [-25,26,-33; 4,-4,5; 3,-3,4]; + C1 = inverse(A1); + is(B1, C1, "invert 3x3") +else + plan(0) +end + + diff --git a/t/functions/307-abs-max-min.t b/t/functions/307-abs-max-min.t new file mode 100644 index 0000000..ceffa76 --- /dev/null +++ b/t/functions/307-abs-max-min.t @@ -0,0 +1,21 @@ +plan(12); + + +# abs (use some pythagorean triples) +is(abs(3+4i), 5, "complex abs 1") +is(abs(9+40i), 41, "complex abs 2") +is(abs([ 5+12i, -20; 20, -9-40i ]), [ 13 20; 20 41], "various abs") +is(abs(3/2+2i), 2.5, "simple rational abs") + +# max (only non complex scalar types supported currently) +is(max(10,5), 10, "max integers") +is(max(10.5,5.5), 10.5, "max floats") +is(max(-10.5,5.5), 5.5, "max negative, positive floats") +is(max(-10.5,-5.5), -5.5, "max negative floats") + + +# min (only non complex scalar types supported currently) +is(min(10,5), 5, "min integers") +is(min(10.5,5.5), 5.5, "min floats") +is(min(-10.5,5.5), -10.5, "min negative, positive floats") +is(min(-10.5,-5.5), -10.5, "min negative floats") \ No newline at end of file diff --git a/t/functions/308-loadlibrary.t b/t/functions/308-loadlibrary.t new file mode 100644 index 0000000..f9d911b --- /dev/null +++ b/t/functions/308-loadlibrary.t @@ -0,0 +1,19 @@ +plan(4); + +signatures = [ "[]" ]; +x = loadlibrary('nonexistent', signatures, 'FOOBAR'); +is(x, 0, "nonexistent library") + +x = libisloaded('FOOBAR'); +is(x, 0, "nonexistent library not loaded") + +start_todo("Need to figure out how to load the NCITEST library from Parrot"); + +signatures = [ '["nci_c", "c"]' ]; +x = loadlibrary('../../runtime/parrot/dynext/libnci_test', signatures, 'NCITEST'); +is(x, 1, "can load ncitest lib"); + +x = libisloaded('NCITEST'); +is(x, 1, "existent library is loaded"); + +end_todo();