# HG changeset patch # User Rik # Date 1315070086 25200 # Node ID 63d06af0376a3a7c4754aef6600c10d0ba040e81 # Parent a7e82bdf12b30356e3b2c0c0e2e6f8846e798c94 codesprint: Tests for sprand.m * sprand.m: Added tests. No tests for density until function is improved. diff -r a7e82bdf12b3 -r 63d06af0376a scripts/sparse/sprand.m --- 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) +