Mercurial > octave
changeset 27096:deb0273199a2 stable
maint: Make old style class tests Matlab compatible.
* test/classes/@Gork/subsasgn.m: Add missing "end".
* test/classes/@Gork/subsref.m: Add missing "end".
* test/classes/@SizeTester/numel.m: Replace "endfunction" by "end".
* test/classes/@SizeTester/size.m: Replace "endfunction" by "end".
* test/classes/@SizeTester/SizeTester.m: Replace "endfunction" by "end".
* test/classes/@Snork/end.m: Replace "!=" by "~=".
* test/classes/@Snork/mpower.m: Replace "!" by "~".
* test/classes/@Snork/ne.m: Replace "!" by "~".
* test/classes/@Snork/power.m: Replace "!" by "~".
* test/classes/@Snork/subsasgn.m: Replace "!=" by "~=".
* test/classes/@Snork/subsref.m: Replace "!=" by "~=".
* test/classes/@Spork/loadobj.m: Replace "!" by "~".
* test/classes/classes.tst: Replace "!" and "!= by "~" and "!=", use Matlab
style comments only, new (c)transpose tests.
* test/classes/@Snork/ctranspose.m: New class method.
* test/classes/@Snork/transpose.m: New class method.
* test/classes/module.mk: Add new class methods to test suite.
author | Kai T. Ohlhus <k.ohlhus@gmail.com> |
---|---|
date | Mon, 20 May 2019 09:40:56 +0200 |
parents | 4ae89360ca16 |
children | bdd2964964cc 9fc02c2b6dbc |
files | test/classes/@Gork/subsasgn.m test/classes/@Gork/subsref.m test/classes/@SizeTester/SizeTester.m test/classes/@SizeTester/numel.m test/classes/@SizeTester/size.m test/classes/@Snork/ctranspose.m test/classes/@Snork/end.m test/classes/@Snork/mpower.m test/classes/@Snork/ne.m test/classes/@Snork/power.m test/classes/@Snork/subsasgn.m test/classes/@Snork/subsref.m test/classes/@Snork/transpose.m test/classes/@Spork/loadobj.m test/classes/classes.tst test/classes/module.mk |
diffstat | 16 files changed, 57 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/test/classes/@Gork/subsasgn.m Mon May 20 09:30:43 2019 +0200 +++ b/test/classes/@Gork/subsasgn.m Mon May 20 09:40:56 2019 +0200 @@ -5,6 +5,7 @@ switch s.subs case 'gyrk' g.gyrk = x; + end end end
--- a/test/classes/@Gork/subsref.m Mon May 20 09:30:43 2019 +0200 +++ b/test/classes/@Gork/subsref.m Mon May 20 09:40:56 2019 +0200 @@ -5,6 +5,7 @@ switch s.subs case 'gyrk' x = g.gyrk; + end end end
--- a/test/classes/@SizeTester/SizeTester.m Mon May 20 09:30:43 2019 +0200 +++ b/test/classes/@SizeTester/SizeTester.m Mon May 20 09:40:56 2019 +0200 @@ -3,4 +3,4 @@ x = struct ("desired_size", desired_size); x = class (x, "SizeTester"); -endfunction +end
--- a/test/classes/@SizeTester/numel.m Mon May 20 09:30:43 2019 +0200 +++ b/test/classes/@SizeTester/numel.m Mon May 20 09:40:56 2019 +0200 @@ -2,4 +2,4 @@ n = prod (this.desired_size); -endfunction +end
--- a/test/classes/@SizeTester/size.m Mon May 20 09:30:43 2019 +0200 +++ b/test/classes/@SizeTester/size.m Mon May 20 09:40:56 2019 +0200 @@ -2,4 +2,4 @@ s = this.desired_size; -endfunction +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/classes/@Snork/ctranspose.m Mon May 20 09:40:56 2019 +0200 @@ -0,0 +1,7 @@ +function s = ctranspose (s) + + x = double (s); + + s = Snork (x' + 4); % +4 To make sure some non-standard tranpose is called. + +end
--- a/test/classes/@Snork/end.m Mon May 20 09:30:43 2019 +0200 +++ b/test/classes/@Snork/end.m Mon May 20 09:40:56 2019 +0200 @@ -1,6 +1,6 @@ function r = end (snk, index_pos, num_indices) - if (num_indices != 1) + if (num_indices ~= 1) error ('Snork object may only have one index') end
--- a/test/classes/@Snork/mpower.m Mon May 20 09:30:43 2019 +0200 +++ b/test/classes/@Snork/mpower.m Mon May 20 09:40:56 2019 +0200 @@ -1,6 +1,6 @@ function s = mpower (s1, x) - if (!isa (s1, 'Snork') || isa (x, 'Snork')) + if (~isa (s1, 'Snork') || isa (x, 'Snork')) error ('mpower Snork!!!'); end
--- a/test/classes/@Snork/ne.m Mon May 20 09:30:43 2019 +0200 +++ b/test/classes/@Snork/ne.m Mon May 20 09:40:56 2019 +0200 @@ -1,5 +1,5 @@ function b = ne (s1, s2) - b = !(s1 == s2); + b = ~(s1 == s2); end
--- a/test/classes/@Snork/power.m Mon May 20 09:30:43 2019 +0200 +++ b/test/classes/@Snork/power.m Mon May 20 09:40:56 2019 +0200 @@ -1,6 +1,6 @@ function s = power (s1, x) - if (!isa (s1, 'Snork') || isa (x, 'Snork')) + if (~isa (s1, 'Snork') || isa (x, 'Snork')) error ('power Snork!!!'); end
--- a/test/classes/@Snork/subsasgn.m Mon May 20 09:30:43 2019 +0200 +++ b/test/classes/@Snork/subsasgn.m Mon May 20 09:40:56 2019 +0200 @@ -6,7 +6,7 @@ switch (s(1).type) case '()' ind = s(1).subs; - if (numel (ind) != 1) + if (numel (ind) ~= 1) error ('Snork: need exactly one index'); else if (length (s) == 1) @@ -17,7 +17,7 @@ end case '{}' ind = s(1).subs; - if (numel (ind) != 1) + if (numel (ind) ~= 1) error ('Snork: need exactly one index'); else if (length (s) == 1)
--- a/test/classes/@Snork/subsref.m Mon May 20 09:30:43 2019 +0200 +++ b/test/classes/@Snork/subsref.m Mon May 20 09:40:56 2019 +0200 @@ -6,14 +6,14 @@ switch (s(1).type) case '()' ind = s(1).subs; - if (numel (ind) != 1) + if (numel (ind) ~= 1) error ('Snork: need exactly one index'); else b = snk.cack(ind{1}); end case '{}' ind = s(1).subs; - if (numel (ind) != 1) + if (numel (ind) ~= 1) error ('Snork: need exactly one index'); else b = snk.cack(ind{1});
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/classes/@Snork/transpose.m Mon May 20 09:40:56 2019 +0200 @@ -0,0 +1,7 @@ +function s = transpose (s) + + x = double (s); + + s = Snork (x.' + 2); % +2 To make sure some non-standard tranpose is called. + +end
--- a/test/classes/@Spork/loadobj.m Mon May 20 09:30:43 2019 +0200 +++ b/test/classes/@Spork/loadobj.m Mon May 20 09:40:56 2019 +0200 @@ -1,7 +1,7 @@ function out = loadobj (in) out = in; - if (!isa (in, 'Spork')) + if (~isa (in, 'Spork')) out.cack = []; end
--- a/test/classes/classes.tst Mon May 20 09:30:43 2019 +0200 +++ b/test/classes/classes.tst Mon May 20 09:40:56 2019 +0200 @@ -272,17 +272,17 @@ %!assert (s1 == s1) %!assert (s1 == x1) %!assert (x1 == s1) -%!assert (!(s1 == (s1 + 1))) -%!assert (!(s1 == (x1 + 1))) -%!assert (!(x1 == (s1 + 1))) +%!assert (~(s1 == (s1 + 1))) +%!assert (~(s1 == (x1 + 1))) +%!assert (~(x1 == (s1 + 1))) -%% Test overloaded ne (!=) for the Snork class -%!assert (!(s1 != s1)) -%!assert (!(s1 != x1)) -%!assert (!(x1 != s1)) -%!assert (s1 != (s1 + 1)) -%!assert (x1 != (s1 + 1)) -%!assert (s1 != (x1 + 1)) +%% Test overloaded ne (~=) for the Snork class +%!assert (~(s1 ~= s1)) +%!assert (~(s1 ~= x1)) +%!assert (~(x1 ~= s1)) +%!assert (s1 ~= (s1 + 1)) +%!assert (x1 ~= (s1 + 1)) +%!assert (s1 ~= (x1 + 1)) %% Test overloaded lt (<) for the Snork class %!assert (s1 < (s1 + 1)) @@ -304,9 +304,13 @@ %!assert (s1 >= (x1 - 1)) %!assert (x1 >= (s1 - 1)) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Testing horizontal & vertical concatenation %% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Testing concatenation and transposition %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%% Test overloaded (c)transpose for the Snork class +%!assert (isequal (s1', Snork (double (s1)' + 4))) % +4 is intentional +%!assert (isequal (s1.', Snork (double (s1).' + 2))) % +2 is intentional %% Test overloaded vertcat() for the Snork class %!test <*38128> @@ -324,8 +328,8 @@ %!test <*38128> %! s = [x1 s2]; assert (isa (s, 'Snork') && isequal (s.gick, [x1 x2])); -%% Test with the Blork class, where neither vertcat() nor horzcat() -%% is overloaded +%% Test with the Blork class, where neither ctranspose(), transpose(), +%% vertcat() nor horzcat() is overloaded %!shared x1, x2, x3 %!test x1 = Blork (); %!test x2 = [x1 x1]; @@ -338,6 +342,9 @@ %!assert (isa (x3, 'Blork') && isequal (size (x3), [2 2])) %!error <dimension mismatch> x4 = [x1, x3] %!error <dimension mismatch> x4 = [x1; x3] +%!test x2 = [x1 x1]; +%!assert (isequal (x2', [x1; x1]) && isequal (size (x2'), [2 1])) +%!assert (isequal (x2.', [x1; x1]) && isequal (size (x2.'), [2 1])) %%%%%%%%%%%%%%%%%%%%%%%% %% Testing precedence %% @@ -372,11 +379,11 @@ %% Trying to change to CPrecendenceTester3 > Snork %!error D = CPrecedenceTester3 (1) -############################################## -## Testing overridden size+numel method ## -## (builtin size method and similar methods ## -## use the size of the struct container) ## -############################################## +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Testing overridden size+numel method %% +%% (builtin size method and similar methods %% +%% use the size of the struct container) %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %!shared st %!test st = SizeTester ([1 1]);
--- a/test/classes/module.mk Mon May 20 09:30:43 2019 +0200 +++ b/test/classes/module.mk Mon May 20 09:40:56 2019 +0200 @@ -48,6 +48,7 @@ class_Snork_TEST_FILES = \ %reldir%/@Snork/Snork.m \ %reldir%/@Snork/cack.m \ + %reldir%/@Snork/ctranspose.m \ %reldir%/@Snork/display.m \ %reldir%/@Snork/double.m \ %reldir%/@Snork/end.m \ @@ -79,6 +80,7 @@ %reldir%/@Snork/subsref.m \ %reldir%/@Snork/tattack.m \ %reldir%/@Snork/times.m \ + %reldir%/@Snork/transpose.m \ %reldir%/@Snork/uminus.m \ %reldir%/@Snork/uplus.m \ %reldir%/@Snork/vertcat.m