changeset 13054:63d06af0376a

codesprint: Tests for sprand.m * sprand.m: Added tests. No tests for density until function is improved.
author Rik <octave@nomad.inbox5.com>
date Sat, 03 Sep 2011 10:14:46 -0700
parents a7e82bdf12b3
children 4e95529cbc51
files scripts/sparse/sprand.m
diffstat 1 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/sparse/sprand.m	Sat Sep 03 13:11:53 2011 -0400
+++ b/scripts/sparse/sprand.m	Sat Sep 03 10:14:46 2011 -0700
@@ -92,3 +92,30 @@
 
 endfunction
 
+## FIXME: Test for density can't happen until code of sprand is improved
+%!test
+%! s = sprand (4, 10, 0.1);
+%! assert (size (s), [4, 10]);
+##%! assert (nnz (s) / numel (s), 0.1, .01);
+
+%% Test 1-input calling form
+%!test
+%! s = sprand (sparse ([1 2 3], [3 2 3], [2 2 2]));
+%! [i, j, v] = find (s);
+%! assert (sort (i), [1 2 3]');
+%! assert (sort (j), [2 3 3]');
+%! assert (all (v > 0 & v < 1));
+
+%% Test input validation
+%!error sprand ()
+%!error sprand (1, 2)
+%!error sprand (1, 2, 3, 4)
+%!error sprand (ones(3), 3, 0.5)
+%!error sprand (3.5, 3, 0.5)
+%!error sprand (0, 3, 0.5)
+%!error sprand (3, ones(3), 0.5)
+%!error sprand (3, 3.5, 0.5)
+%!error sprand (3, 0, 0.5)
+%!error sprand (3, 3, -1)
+%!error sprand (3, 3, 2)
+