Mercurial > hg > octave-lyh
changeset 13770:b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
* unmkpp.m: Add functional test. Improve input validation.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Fri, 28 Oct 2011 09:27:00 -0700 |
parents | 5f96b91b4e0c |
children | 80b30e186b73 |
files | scripts/polynomial/unmkpp.m |
diffstat | 1 files changed, 24 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/polynomial/unmkpp.m +++ b/scripts/polynomial/unmkpp.m @@ -47,11 +47,12 @@ ## @end deftypefn function [x, P, n, k, d] = unmkpp (pp) - if (nargin == 0) + + if (nargin != 1) print_usage (); endif - if (! (isstruct (pp) && strcmp (pp.form, "pp"))) - error ("unmkpp: expecting piecewise polynomial structure"); + if (! (isstruct (pp) && isfield (pp, "form") && strcmp (pp.form, "pp"))) + error ("unmkpp: PP must be a piecewise polynomial structure"); endif x = pp.breaks; P = pp.coefs; @@ -60,3 +61,23 @@ d = pp.dim; endfunction + + +%!test +%! b = 1:3; +%! c = 1:24; +%! pp = mkpp (b,c); +%! [x, P, n, k, d] = unmkpp (pp); +%! assert (x, b); +%! assert (P, reshape (c, [2 12])); +%! assert (n, 2); +%! assert (k, 12); +%! assert (d, 1); + +%% Test input validation +%!error unmkpp () +%!error unmkpp (1,2) +%!error <piecewise polynomial structure> unmkpp (1) +%!error <piecewise polynomial structure> unmkpp (struct ("field1", "pp")) +%!error <piecewise polynomial structure> unmkpp (struct ("form", "not_a_pp")) +