well done. alfonso how can i amend the problem so that the coder will be forced to generate random values? :)
true randomness is a bit involved to test (particularly without the stats toolbox), plus the sum constrain adds some additional complexity to the randomness of the resulting values (see for example this Cody problem: http://www.mathworks.com/matlabcentral/cody/problems/331-compute-area-from-fixed-sum-cumulative-probability). In any way, the simplest solution to discourage this sort of extremely-non-random solutions would probably be running your current testsuite twice (with identical inputs) and then checking that the returned vectors are different...
Another possibility, would be to test that there is no repetition in the returned values, which can easily be tested with: assert(all(diff(sort(sum_array))));
you're right guillaume, i apppreciate that.
Test | Status | Code Input and Output |
---|---|---|
1 | Fail |
%%
sum_up = 5*rand; % sum of array should be this
n = randi(10); %number of elements in array
sum_array = [];
for times = 1:100
for i = 1:n
sum_array(i,1) = fill_array_sum_up_to(sum_up,n,sum_array);
end
checksum(times) = all(diff(sort(sum_array)));
end
assert(all(checksum));
Error: Assertion failed.
|
4104 Solvers
534 Solvers
227 Solvers
196 Solvers
07 - Common functions and indexing 6
282 Solvers