# HG changeset patch
# User Dag Lyberg <daglyberg80@gmail.com>
# Date 1464210667 -7200
#      Wed May 25 23:11:07 2016 +0200
# Node ID ff4af6645847997a9b7eef8c88c21f4d95566879
# Parent  19e8eddd477395a43d3a3368df4f53e3a3a1e935
Add tests to file corefcn/sparse.cc. This includes the functions issparse, sparse and spalloc. For more information, read http://wiki.octave.org/Add_BIST_tests_for_octave_functions_written_in_C%2B%2B.

diff -r 19e8eddd4773 -r ff4af6645847 libinterp/corefcn/sparse.cc
--- a/libinterp/corefcn/sparse.cc	Sat May 14 09:19:43 2016 -0700
+++ b/libinterp/corefcn/sparse.cc	Wed May 25 23:11:07 2016 +0200
@@ -54,6 +54,52 @@ Return true if @var{x} is a sparse matri
   return ovl (args(0).is_sparse_type ());
 }
 
+/*
+%!assert (issparse (sparse (1)), true)
+%!assert (issparse (sparse (1,1,1)), true)
+%!assert (issparse (sparse (single (1))), true)
+%!assert (issparse (sparse (1+i)), true)
+
+%!assert (issparse (1), false)
+%!assert (issparse (sparse (1)), true)
+%!assert (issparse ([1, 2]), false)
+%!assert (issparse (sparse ([1, 2])), true)
+%!assert (issparse ([1, 2]'), false)
+%!assert (issparse (sparse ([1, 2]')), true)
+%!assert (issparse ([1+i, 2]), false)
+%!assert (issparse (sparse ([1+i, 2])), true)
+
+%!assert (issparse ([]), false)
+%!assert (issparse (sparse([])), true)
+
+%!assert (issparse (1+i), false)
+%!assert (issparse (1), false)
+%!assert (issparse (single (1+i)), false)
+%!assert (issparse (single (1)), false)
+%!assert (issparse (double (1+i)), false)
+%!assert (issparse (double (1)), false)
+
+%!assert (issparse (NaN), false)
+%!assert (issparse (NA), false)
+%!assert (issparse (Inf), false)
+%!assert (issparse (-Inf), false)
+%!assert (issparse (Inf+i), false)
+
+%!assert (issparse (true), false)
+%!assert (issparse (int8 (1)), false)
+%!assert (issparse (uint8 (1)), false)
+%!assert (issparse (int16 (1)), false)
+%!assert (issparse (uint16 (1)), false)
+%!assert (issparse (int32 (1)), false)
+%!assert (issparse (uint32 (1)), false)
+%!assert (issparse (int64 (1)), false)
+%!assert (issparse (uint64 (1)), false)
+
+%!assert (issparse ("test"), false)
+%!assert (issparse (struct("one", {1})), false)
+%!assert (issparse (cell (1)), false)
+*/
+
 DEFUN (sparse, args, ,
        "-*- texinfo -*-\n\
 @deftypefn  {} {@var{s} =} sparse (@var{a})\n\
@@ -220,6 +266,72 @@ Compressed Column Sparse (rows = 3, cols
   return retval;
 }
 
+/*
+%!assert (size (sparse ([])), [0,0])
+%!assert (size (sparse ([1])), [1,1])
+%!assert (size (sparse ([1,2])), [1,2])
+%!assert (size (sparse ([1,2]')), [2,1])
+
+%!assert (size (sparse ([1],[1],[1],1,1)), [1,1])
+%!assert (size (sparse ([1,1],[1,2],[1,2],1,2)), [1,2])
+%!assert (size (sparse ([1,2],[1,1],[1,2],2,1)), [2,1])
+
+%!assert (size (sparse ([1],[1],[1],1,1)), [1,1])
+%!assert (size (sparse ([1,1],[1,2],[1,2])), [1,2])
+%!assert (size (sparse ([1,2],[1,1],[1,2])), [2,1])
+
+%!assert (size (sparse (1,1)), [1,1])
+%!assert (size (sparse (1,2)), [1,2])
+%!assert (size (sparse (2,1)), [2,1])
+
+%!assert (size (sparse ([1,2])), [1,2])
+%!assert (size (sparse ([1,2]')), [2,1])
+
+%!assert (sparse ([1])(1) == 1)
+%!assert (sparse ([1,2])(1,1) == 1)
+%!assert (sparse ([1,2])(1,2) == 2)
+%!assert (sparse ([1,2]')(1,1) == 1)
+%!assert (sparse ([1,2]')(2,1) == 2)
+
+%!assert (sparse (1)(1) == 1)
+%!assert (sparse (1,1)(1,1) == 0)
+%!assert (sparse (1,2)(1,1) == 0)
+%!assert (sparse (1,2)(1,2) == 0)
+%!assert (sparse (2,1)(1,1) == 0)
+%!assert (sparse (2,1)(2,1) == 0)
+
+# Multidimensional matrices are not supported but the output is a reduced matrix
+%!assert(size(sparse(zeros(1,2,3))), [1,6])
+# Four arguments are not supported but the output is a reduced matrix
+%!assert(size(sparse(1,2,3,4)), [1,2])
+
+#TODO: Add tests for input argument "unique"? This may be superfluous since it
+# is tested in sparse.tst.
+
+%!error sparse ()
+%!error sparse (1,2,3,4,5,6,7)
+%!error sparse ("test")
+
+%!error sparse ([])(1,1)
+%!error sparse ([1])(1,2)
+%!error sparse ([1])(2,1)
+%!error sparse ([1,2])(1,3)
+%!error sparse ([1,2])(2,1)
+%!error sparse ([1,2]')(1,2)
+%!error sparse ([1,2]')(3,1)
+
+%!error sparse (0,0)(1,1)
+%!error sparse (0,1)(1,1)
+%!error sparse (1,0)(1,1)
+
+%!error sparse (1,1)(1,2)
+%!error sparse (1,1)(2,1)
+%!error sparse (1,2)(1,3)
+%!error sparse (1,2)(2,1)
+%!error sparse (2,1)(1,2)
+%!error sparse (2,1)(3,1)
+*/
+
 DEFUN (spalloc, args, ,
        "-*- texinfo -*-\n\
 @deftypefn {} {@var{s} =} spalloc (@var{m}, @var{n}, @var{nz})\n\
@@ -275,3 +387,18 @@ the function @code{nzmax}.\n\
   else
     error ("spalloc: M,N,NZ must be non-negative");
 }
+
+/*
+%!assert (spalloc (1,1), sparse (1,1))
+%!assert (spalloc (1,1,1), sparse (1,1))
+%!assert (spalloc (1,2), sparse (1,2))
+%!assert (spalloc (1,2,2), sparse (1,2))
+%!assert (spalloc (2,1), sparse (2,1))
+%!assert (spalloc (2,1,2), sparse (2,1))
+
+%!assert(issparse(spalloc(1,1,1)), true)
+
+%!error spalloc ()
+%!error spalloc (1)
+%!error spalloc (1,2,3,4)
+*/
