Mercurial > hg > octave-terminal
changeset 13136:79b9a7669bb8
Tests added for scripts/plot
(plot/ishghandle.m, plot/text.m, plot/title.m, plot/xlabel.m, plot/ylabel.m,
plot/zlabel.m): Tests added for plot functions.
plot/whitebg.m: Fix typo. Change colors only for figure under test
author | Kai Habel <kai.habel@gmx.de> |
---|---|
date | Wed, 14 Sep 2011 21:03:39 +0200 |
parents | af36cdb552a6 |
children | 52c5799130c2 |
files | scripts/plot/ishghandle.m scripts/plot/text.m scripts/plot/title.m scripts/plot/whitebg.m scripts/plot/xlabel.m scripts/plot/ylabel.m scripts/plot/zlabel.m |
diffstat | 7 files changed, 134 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/ishghandle.m +++ b/scripts/plot/ishghandle.m @@ -26,3 +26,34 @@ ## no simulink equivalent. retval = ishandle (h); endfunction + +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! assert (ishghandle (hf)); +%! assert (!ishghandle (-hf)); +%! l = line; +%! ax = gca(); +%! assert (ishghandle (ax)); +%! assert (!ishghandle (-ax)); +%! assert (ishghandle (l)); +%! assert (!ishghandle (-l)); +%! p = patch; +%! assert (ishghandle (p)); +%! assert (!ishghandle (-p)); +%! s = surface; +%! assert (ishghandle (s)); +%! assert (!ishghandle (-s)); +%! t = text; +%! assert (ishghandle (t)); +%! assert (!ishghandle (-t)); +%! i = image; +%! assert (ishghandle (i)); +%! assert (!ishghandle (-i)); +%! hg = hggroup; +%! assert (ishghandle (hg)); +%! assert (!ishghandle (-hg)); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect +
--- a/scripts/plot/text.m +++ b/scripts/plot/text.m @@ -218,3 +218,33 @@ %! ylabel (1:2) %! title (1:2) +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! h = text (0.5, 0.3, "char"); +%! assert ("char", class (get (h, "string"))) +%! h = text (0.5, 0.4, ["char row 1"; "char row 2"]); +%! assert ("char", class (get (h, "string"))) +%! h = text (0.5, 0.6, {"cell2str (1,1)", "cell2str (1,2)"; "cell2str (2,1)", "cell2str (2,2)"}); +%! assert ("cell", class (get (h, "string"))) +%! h = text (0.5, 0.8, "foobar"); +%! set (h, "string", 1:3) +%! h = text ([0.1, 0.1], [0.3, 0.4], "one string & two objects"); +%! assert ("char", class (get (h(1), "string"))) +%! assert ("char", class (get (h(2), "string"))) +%! h = text ([0.1, 0.1], [0.5, 0.6], {"one cellstr & two objects"}); +%! assert ("cell", class (get (h(1), "string"))) +%! assert ("cell", class (get (h(2), "string"))) +%! h = text ([0.1, 0.1], [0.7, 0.8], {"cellstr 1 object 1", "cellstr 2 object 2"}); +%! assert ("char", class (get (h(1), "string"))) +%! assert ("char", class (get (h(2), "string"))) +%! h = text ([0.1, 0.1], [0.1, 0.2], ["1st string & 1st object"; "2nd string & 2nd object"]); +%! assert ("char", class (get (h(1), "string"))) +%! assert ("char", class (get (h(2), "string"))) +%! h = text (0.7, 0.6, "single string"); +%! assert ("char", class (get (h, "string"))) +%! h = text (0.7, 0.5, {"single cell-string"}); +%! assert ("cell", class (get (h, "string"))) +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect
--- a/scripts/plot/title.m +++ b/scripts/plot/title.m @@ -52,5 +52,24 @@ %! title("Testing title") %! assert(get(xl,"string"),"Testing title") -## Remove from test statistics. No real tests possible. -%!assert (1) +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! ax=axes(); +%! xl = get(ax,"title"); +%! title("Testing title") +%! assert(get(xl,"string"),"Testing title") +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! plot3 ([0,1], [0,1], [0,1]); +%! xl = get(gca (), "title"); +%! title("Testing title") +%! assert(get(xl,"string"),"Testing title") +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect
--- a/scripts/plot/whitebg.m +++ b/scripts/plot/whitebg.m @@ -40,7 +40,7 @@ h = 0; color = NaN; - if (nargin > 0 && nargin < 2) + if (nargin > 0 && nargin < 3) if (ishandle (varargin{1})) h = varargin{1}; if (nargin == 2) @@ -152,11 +152,11 @@ %! l = line; %! assert (get (hf, "color"), dfc); %! assert (get (gca, "color"), dac); -%! whitebg; +%! whitebg (hf); %! assert (get (hf, "color"), 1 - dfc); %! assert (get (gca, "color"), 1 - dac); %! c = [0.2 0.2 0.2]; -%! whitebg (c); +%! whitebg (hf, c); %! assert (get (hf, "color"), 1 - dfc); %! assert (get (gca, "color"), c); %! unwind_protect_cleanup
--- a/scripts/plot/xlabel.m +++ b/scripts/plot/xlabel.m @@ -53,3 +53,15 @@ endif endfunction + +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! x = xlabel ("xlabel_string"); +%! assert (get(gca, "xlabel"), x); +%! assert (get(x, "type"), "text"); +%! assert (get(x, "visible"), "on"); +%! assert (get(x, "string"), "xlabel_string"); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect
--- a/scripts/plot/ylabel.m +++ b/scripts/plot/ylabel.m @@ -47,3 +47,15 @@ endif endfunction + +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! y = ylabel ("ylabel_string"); +%! assert (get(gca, "ylabel"), y); +%! assert (get(y, "type"), "text"); +%! assert (get(y, "visible"), "on"); +%! assert (get(y, "string"), "ylabel_string"); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect
--- a/scripts/plot/zlabel.m +++ b/scripts/plot/zlabel.m @@ -47,3 +47,28 @@ endif endfunction + +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! z = zlabel ("zlabel_string"); +%! assert (get(gca, "zlabel"), z); +%! assert (get(z, "type"), "text"); +%! assert (get(z, "visible"), "off"); +%! assert (get(z, "string"), "zlabel_string"); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + +%!test +%! hf = figure ("visible", "off"); +%! plot3 (0, 0, 0); +%! unwind_protect +%! z = zlabel ("zlabel_string"); +%! assert (get(gca, "zlabel"), z); +%! assert (get(z, "type"), "text"); +%! assert (get(z, "visible"), "off"); +%! assert (get(z, "string"), "zlabel_string"); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect