Diff of /src/gf.cc [f62e8c] .. [b92126] Maximize Restore

  Switch to side-by-side view

--- a/src/gf.cc
+++ b/src/gf.cc
@@ -55,6 +55,12 @@
   return octave_value ();
 }
 
+/*
+%% Test input validation
+%!error isgalois ()
+%!error isgalois (1, 2)
+*/
+
 // FIXME:
 // I want to replace the "16" below with __OCTAVE_GALOIS_MAX_M_AS_STRING,
 // but as I don't run the preprocessor when getting the help from the
@@ -89,22 +95,17 @@
   int m = 1;
   int primpoly = 0;
 
-  if ( nargin == 0 )
+  if (nargin < 1 || nargin > 3)
     {
       print_usage ();
       return retval;
     }
 
   data = args(0).matrix_value ();
-  if ( nargin > 1 )
+  if (nargin > 1)
     m = args(1).int_value ();
-  if ( nargin > 2 )
+  if (nargin > 2)
     primpoly = args(2).int_value ();
-  if (nargin > 3)
-    {
-      error ("gf: too many arguments");
-      return retval;
-    }
 
   if (!galois_type_loaded)
     {
@@ -121,6 +122,12 @@
   retval = new octave_galois (data, m, primpoly);
   return retval;
 }
+
+/*
+%% Test input validation
+%!error gf ()
+%!error gf (1, 2, 3, 4)
+*/
 
 static octave_value
 make_gdiag (const octave_value& a, const octave_value& b)
@@ -228,6 +235,12 @@
   return retval;
 }
 
+/*
+%% Test input validation
+%!error gdiag ()
+%!error gdiag (1, 2, 3)
+*/
+
 // PKG_ADD: autoload ("greshape", "gf.oct");
 DEFUN_DLD (greshape, args, ,
   "-*- texinfo -*-\n\
@@ -270,9 +283,8 @@
   octave_value retval;
   int nargin = args.length ();
 
-  if (nargin != 2 && nargin !=3)
-    {
-      error ("greshape (a, m, m) or greshape (a, size(b))");
+  if (nargin != 2 && nargin != 3)
+    {
       print_usage ();
     }
   else
@@ -318,6 +330,13 @@
     }
   return retval;
 }
+
+/*
+%% Test input validation
+%!error greshape ()
+%!error greshape (1)
+%!error greshape (1, 2, 3, 4)
+*/
 
 #define DATA_REDUCTION(FCN) \
  \
@@ -370,6 +389,12 @@
   DATA_REDUCTION (prod);
 }
 
+/*
+%% Test input validation
+%!error gprod ()
+%!error gprod (1, 2, 3)
+*/
+
 // PKG_ADD: autoload ("gsum", "gf.oct");
 DEFUN_DLD (gsum, args, ,
   "-*- texinfo -*-\n\
@@ -382,6 +407,12 @@
   DATA_REDUCTION (sum);
 }
 
+/*
+%% Test input validation
+%!error gsum ()
+%!error gsum (1, 2, 3)
+*/
+
 // PKG_ADD: autoload ("gsumsq", "gf.oct");
 DEFUN_DLD (gsumsq, args, ,
   "-*- texinfo -*-\n\
@@ -400,6 +431,12 @@
   DATA_REDUCTION (sumsq);
 }
 
+/*
+%% Test input validation
+%!error gsumsq ()
+%!error gsumsq (1, 2, 3)
+*/
+
 // PKG_ADD: autoload ("gsqrt", "gf.oct");
 DEFUN_DLD (gsqrt, args, ,
   "-*- texinfo -*-\n\
@@ -430,6 +467,12 @@
 
   return retval;
 }
+
+/*
+%% Test input validation
+%!error gsqrt ()
+%!error gsqrt (1, 2)
+*/
 
 // PKG_ADD: autoload ("glog", "gf.oct");
 DEFUN_DLD (glog, args, ,
@@ -463,6 +506,11 @@
   return retval;
 }
 
+/*
+%% Test input validation
+%!error glog ()
+%!error glog (1, 2)
+*/
 
 // PKG_ADD: autoload ("gexp", "gf.oct");
 DEFUN_DLD (gexp, args, ,
@@ -495,6 +543,12 @@
 
   return retval;
 }
+
+/*
+%% Test input validation
+%!error gexp ()
+%!error gexp (1, 2)
+*/
 
 static inline int
 modn (int x, int m, int n)
@@ -818,6 +872,14 @@
   return retval;
 }
 
+/*
+%% Test input validation
+%!error gfilter ()
+%!error gfilter (1)
+%!error gfilter (1, 2)
+%!error gfilter (1, 2, 3, 4, 5)
+*/
+
 // PKG_ADD: autoload ("glu", "gf.oct");
 DEFUN_DLD (glu, args, nargout,
   "-*- texinfo -*-\n\
@@ -936,6 +998,12 @@
   return retval;
 }
 
+/*
+%% Test input validation
+%!error glu ()
+%!error glu (1, 2)
+*/
+
 // PKG_ADD: autoload ("ginv", "gf.oct");
 DEFUN_DLD (ginv, args, nargout,
   "-*- texinfo -*-\n\
@@ -1003,6 +1071,12 @@
 
   return retval;
 }
+
+/*
+%% Test input validation
+%!error ginv ()
+%!error ginv (1, 2)
+*/
 
 // FIXME: this should really be done with an alias, but
 // alias_builtin() won't do the right thing if we are actually using
@@ -1021,6 +1095,12 @@
   return Fginv (args, nargout);
 }
 
+/*
+%% Test input validation
+%!error ginverse ()
+%!error ginverse (1, 2)
+*/
+
 // PKG_ADD: autoload ("gdet", "gf.oct");
 DEFUN_DLD (gdet, args, nargout,
   "-*- texinfo -*-\n\
@@ -1072,6 +1152,12 @@
   retval = new octave_galois (m.determinant ());
   return retval;
 }
+
+/*
+%% Test input validation
+%!error gdet ()
+%!error gdet (1, 2)
+*/
 
 // PKG_ADD: autoload ("grank", "gf.oct");
 DEFUN_DLD (grank, args, nargout,
@@ -1156,6 +1242,12 @@
     }
   return retval;
 }
+
+/*
+%% Test input validation
+%!error grank ()
+%!error grank (1, 2)
+*/
 
 // PKG_ADD: autoload ("rsenc", "gf.oct");
 DEFUN_DLD (rsenc, args, nargout,
@@ -1211,7 +1303,7 @@
   octave_value retval;
   int nargin = args.length ();
 
-  if ((nargin < 3) || (nargin > 5))
+  if (nargin < 3 || nargin > 5)
     {
       print_usage ();
       return retval;
@@ -1462,6 +1554,14 @@
 
   return retval;
 }
+
+/*
+%% Test input validation
+%!error rsenc ()
+%!error rsenc (1)
+%!error rsenc (1, 2)
+%!error rsenc (1, 2, 3, 4, 5, 6)
+*/
 
 int
 decode_rs(galois& data, const int prim, const int iprim, const int nroots,
@@ -1743,7 +1843,7 @@
 
   int nargin = args.length ();
 
-  if ((nargin < 3) || (nargin > 5))
+  if (nargin < 3 || nargin > 5)
     {
       print_usage ();
       return retval;
@@ -2017,6 +2117,14 @@
   return retval;
 }
 
+/*
+%% Test input validation
+%!error rsdec ()
+%!error rsdec (1)
+%!error rsdec (1, 2)
+%!error rsdec (1, 2, 3, 4, 5, 6)
+*/
+
 // PKG_ADD: autoload ("bchenco", "gf.oct");
 DEFUN_DLD (bchenco, args, ,
   "-*- texinfo -*-\n\
@@ -2059,7 +2167,7 @@
   octave_value retval;
   int nargin = args.length ();
 
-  if ((nargin < 3) || (nargin > 5))
+  if (nargin < 3 || nargin > 5)
     {
       print_usage ();
       return retval;
@@ -2312,6 +2420,14 @@
   return retval;
 }
 
+/*
+%% Test input validation
+%!error bchenco ()
+%!error bchenco (1)
+%!error bchenco (1, 2)
+%!error bchenco (1, 2, 3, 4, 5, 6)
+*/
+
 // PKG_ADD: autoload ("bchdeco", "gf.oct");
 DEFUN_DLD (bchdeco, args, ,
   "-*- texinfo -*-\n\
@@ -2369,7 +2485,7 @@
   octave_value_list retval;
   int nargin = args.length ();
 
-  if ((nargin < 3) || (nargin > 5))
+  if (nargin < 3 || nargin > 5)
     {
       print_usage ();
       return retval;
@@ -2659,3 +2775,11 @@
   retval(2) = octave_value (code);
   return retval;
 }
+
+/*
+%% Test input validation
+%!error bchdeco ()
+%!error bchdeco (1)
+%!error bchdeco (1, 2)
+%!error bchdeco (1, 2, 3, 4, 5, 6)
+*/