Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9951031
commit fd5542a
Showing
16 changed files
with
429 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
Oops, something went wrong.