changeset 11098:dcde7c5a1d29

new tests for special-matrix functions
author John W. Eaton <jwe@octave.org>
date Thu, 14 Oct 2010 14:43:59 -0400
parents ffb2f1ef2097
children 65b240770880
files scripts/ChangeLog scripts/special-matrix/pascal.m scripts/special-matrix/rosser.m scripts/special-matrix/wilkinson.m
diffstat 4 files changed, 32 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,10 @@
+2010-10-14  John W. Eaton  <jwe@octave.org>
+
+	* special-matrix/rosser.m: New tests.
+	* special-matrix/wilkinson.m: Fix error message.  New tests.
+	* special-matrix/pascal.m: Error if T is out of range.
+	New tests.
+
 2010-10-14  John W. Eaton  <jwe@octave.org>
 
 	* set/unique.m: Remove check for issparse existence since it is
--- a/scripts/special-matrix/pascal.m
+++ b/scripts/special-matrix/pascal.m
@@ -20,7 +20,6 @@
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {} pascal (@var{n})
 ## @deftypefnx {Function File} {} pascal (@var{n}, @var{t})
-##
 ## Return the Pascal matrix of order @var{n} if @code{@var{t} = 0}.
 ## @var{t} defaults to 0.  Return lower triangular Cholesky factor of 
 ## the Pascal matrix if @code{@var{t} = 1}.  This matrix is its own
@@ -52,6 +51,10 @@
     error ("pascal: expecting scalar arguments, found something else");
   endif
 
+  if (t < -1 || t > 2)
+    error ("pascal: expecting t to be -1, 0, 1, or 2, found %d", t);
+  endif
+
   retval = zeros (n);
   retval(:,1) = 1;
 
@@ -78,3 +81,13 @@
   endif
 
 endfunction
+
+%!assert (pascal(3,-1), [1,0,0;1,1,0;1,2,1])
+%!assert (pascal(3,0), [1,1,1;1,2,3;1,3,6])
+%!assert (pascal(3,0), pascal(3))
+%!assert (pascal(3,1), [1,0,0;1,-1,0;1,-2,1])
+%!assert (pascal(3,2), [0,0,-1;0,-1,2;-1,-1,1])
+%!error (pascal(3,4))
+%!error (pascal(3,-2))
+%!error (pascal())
+%!error (pascal(1,2,3))
--- a/scripts/special-matrix/rosser.m
+++ b/scripts/special-matrix/rosser.m
@@ -18,7 +18,6 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} rosser ()
-##
 ## Return the Rosser matrix.  This is a difficult test case used to evaluate
 ## eigenvalue algorithms.
 ##
@@ -44,3 +43,6 @@
             -49,    -8,     8,    59,   208,   208,    99,  -911;
              29,   -44,    52,   -23,   208,   208,  -911,    99];
 endfunction
+
+%!assert (size(rosser()), [8,8])
+%!error (rosser(1))
--- a/scripts/special-matrix/wilkinson.m
+++ b/scripts/special-matrix/wilkinson.m
@@ -18,7 +18,6 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} wilkinson (@var{n})
-##
 ## Return the Wilkinson matrix of order @var{n}.  Wilkinson matrices are
 ## symmetric and tridiagonal with pairs of nearly, but not exactly, equal
 ## eigenvalues.
@@ -37,7 +36,7 @@
   endif
 
   if (! (isscalar (n) && (n == fix (n)) && n > 0))
-    error ("wilkinson: N must be an integer greater than 1");
+    error ("wilkinson: N must be an integer greater than 0");
   endif
 
   side = ones (n-1, 1);
@@ -45,3 +44,10 @@
   retval = diag (side, -1) + diag (center) + diag (side, 1);
 
 endfunction
+
+%!assert (wilkinson(1), [])
+%!assert (wilkinson(2), [0.5,1;1,0.5])
+%!assert (wilkinson(3), [1,1,0;1,0,1;0,1,1])
+%!assert (wilkinson(4), [1.5,1,0,0;1,0.5,1,0;0,1,0.5,1;0,0,1,1.5])
+%!error (wilkinson())
+%!error (wilkinson(1,2))
\ No newline at end of file