Cody

Solution 1352879

Submitted on 22 Nov 2017
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
% It is possible that even a genuine random number generator could produce % a sequence that does not have the characteristics of a random number stream, % so a couple of incorrect assessments are allowed as 'leeway' in each test.

2   Fail
% Random, very short faults = 0; isRandom_C = true; for i = 1 : 10 x = randi(4, [1, randi(8)]); [prob, isRandom] = testRandomness(x); % assert( abs(prob - prob_C) / prob_C < 1E-5 , 'Wrong probability.') if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** Warning: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

Undefined function 'xcorr' for input arguments of type 'double'. Error in testRandomness (line 4) Rxx = xcorr(x','coeff'); Error in Test2 (line 6) [prob, isRandom] = testRandomness(x);

3   Fail
% Random, short faults = 0; prob_C = 1.121038771459854E-44; isRandom_C = true; for i = 1 : 10 x = randi(4, [1,73]); [prob, isRandom] = testRandomness(x); assert( abs(prob - prob_C) / prob_C < 1E-5 , 'Wrong probability.') if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** Warning: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

Undefined function 'xcorr' for input arguments of type 'double'. Error in testRandomness (line 4) Rxx = xcorr(x','coeff'); Error in Test3 (line 7) [prob, isRandom] = testRandomness(x);

4   Fail
% Random, medium faults = 0; prob_C = 1.785917798878555E-102; isRandom_C = true; for i = 1 : 10 x = randi(4, [1,169]); [prob, isRandom] = testRandomness(x); assert( abs(prob - prob_C) / prob_C < 1E-5 , 'Wrong probability.') if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** Warning: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

Undefined function 'xcorr' for input arguments of type 'double'. Error in testRandomness (line 4) Rxx = xcorr(x','coeff'); Error in Test4 (line 7) [prob, isRandom] = testRandomness(x);

5   Fail
% Random, long faults = 0; prob_C = 9.332636185032189E-302; isRandom_C = true; for i = 1 : 10 x = randi(4, [1,500]); [prob, isRandom] = testRandomness(x); assert( abs(prob - prob_C) / prob_C < 1E-5 , 'Wrong probability.') if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** Warning: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

Undefined function 'xcorr' for input arguments of type 'double'. Error in testRandomness (line 4) Rxx = xcorr(x','coeff'); Error in Test5 (line 7) [prob, isRandom] = testRandomness(x);

6   Fail
% Too many of some number, short faults = 0; prob_C = 1.121038771459854E-44; isRandom_C = false; for i = 1 : 10 x = randi(4, [1,73]); x( randi(3, [1,73]) < 3 ) = randi(4); [prob, isRandom] = testRandomness(x); assert( abs(prob - prob_C) / prob_C < 1E-5 , 'Wrong probability.') if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** Warning: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

Undefined function 'xcorr' for input arguments of type 'double'. Error in testRandomness (line 4) Rxx = xcorr(x','coeff'); Error in Test6 (line 8) [prob, isRandom] = testRandomness(x);

7   Fail
% Too many of some number, medium faults = 0; prob_C = 1.785917798878555E-102; isRandom_C = false; for i = 1 : 10 x = randi(4, [1,169]); x( randi(3, [1,169]) == 1 ) = randi(4); [prob, isRandom] = testRandomness(x); assert( abs(prob - prob_C) / prob_C < 1E-5 , 'Wrong probability.') if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** Warning: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

Undefined function 'xcorr' for input arguments of type 'double'. Error in testRandomness (line 4) Rxx = xcorr(x','coeff'); Error in Test7 (line 8) [prob, isRandom] = testRandomness(x);

8   Fail
% Too few of some number, long faults = 0; prob_C = 9.332636185032189E-302; isRandom_C = false; for i = 1 : 10 x = randi(4, [1,500]); els = find(x == randi(4)); new = randi(4, [1,length(els)]); x(els) = new; [prob, isRandom] = testRandomness(x); assert( abs(prob - prob_C) / prob_C < 1E-5 , 'Wrong probability.') if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** Warning: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

Undefined function 'xcorr' for input arguments of type 'double'. Error in testRandomness (line 4) Rxx = xcorr(x','coeff'); Error in Test8 (line 10) [prob, isRandom] = testRandomness(x);

9   Fail
% Repeated patterns, long faults = 0; prob_C = 9.332636185032189E-302; isRandom_C = false; for i = 1 : 10 x = repmat( randi(4, [1, randi([4, 12])]) , [1,150] ); x = x(1:500); [prob, isRandom] = testRandomness(x); assert( abs(prob - prob_C) / prob_C < 1E-5 , 'Wrong probability.') if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** Warning: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

Undefined function 'xcorr' for input arguments of type 'double'. Error in testRandomness (line 4) Rxx = xcorr(x','coeff'); Error in Test9 (line 8) [prob, isRandom] = testRandomness(x);

10   Fail
% Blocked randomisation (i.e. permuted block randomisation), medium faults = 0; prob_C = 1.785917798878555E-102; isRandom_C = false; for i = 1 : 10 x = []; for j = 1 : 50, x = [x randperm(4)]; end; x = x(1:169); [prob, isRandom] = testRandomness(x); assert( abs(prob - prob_C) / prob_C < 1E-5 , 'Wrong probability.') if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** Warning: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

Undefined function 'xcorr' for input arguments of type 'double'. Error in testRandomness (line 4) Rxx = xcorr(x','coeff'); Error in Test10 (line 9) [prob, isRandom] = testRandomness(x);

11   Fail
% Blocked randomisation (i.e. permuted block randomisation), long faults = 0; prob_C = 9.332636185032189E-302; isRandom_C = false; for i = 1 : 10 x = []; for j = 1 : 125, x = [x randperm(4)]; end; %x = x(1:500); [prob, isRandom] = testRandomness(x); assert( abs(prob - prob_C) / prob_C < 1E-5 , 'Wrong probability.') if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** Warning: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

Undefined function 'xcorr' for input arguments of type 'double'. Error in testRandomness (line 4) Rxx = xcorr(x','coeff'); Error in Test11 (line 9) [prob, isRandom] = testRandomness(x);

12   Fail
% Partially repeated 4-digit sequence, long faults = 0; prob_C = 9.332636185032189E-302; isRandom_C = false; for i = 1 : 10 pattern = randperm(4); x = []; for j = 1 : 300, d = randi(6, [1,4]); p = pattern; p(d==1) = []; x = [x p]; end; x = x(1:500); [prob, isRandom] = testRandomness(x); assert( abs(prob - prob_C) / prob_C < 1E-5 , 'Wrong probability.') if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** Warning: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

Undefined function 'xcorr' for input arguments of type 'double'. Error in testRandomness (line 4) Rxx = xcorr(x','coeff'); Error in Test12 (line 15) [prob, isRandom] = testRandomness(x);

13   Fail
% Partially repeated 8-digit sequence, long faults = 0; prob_C = 9.332636185032189E-302; isRandom_C = false; for i = 1 : 10 pattern = [randperm(4) randperm(4)]; x = []; for j = 1 : 150, d = randi(6, [1,8]); p = pattern; p(d==1) = []; x = [x p]; end; x = x(1:500); [prob, isRandom] = testRandomness(x); assert( abs(prob - prob_C) / prob_C < 1E-5 , 'Wrong probability.') if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** Warning: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

Undefined function 'xcorr' for input arguments of type 'double'. Error in testRandomness (line 4) Rxx = xcorr(x','coeff'); Error in Test13 (line 15) [prob, isRandom] = testRandomness(x);

14   Fail
% Partially segregated sequence, long faults = 0; prob_C = 9.332636185032189E-302; isRandom_C = false; for i = 1 : 10 pattern = [randperm(4) randperm(4)]; x = []; for j = 1 : 50, p = randi(12, [1,10]); p(p>4) = randi(4); x = [x p]; end; [prob, isRandom] = testRandomness(x); assert( abs(prob - prob_C) / prob_C < 1E-5 , 'Wrong probability.') if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** Warning: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

Undefined function 'xcorr' for input arguments of type 'double'. Error in testRandomness (line 4) Rxx = xcorr(x','coeff'); Error in Test14 (line 13) [prob, isRandom] = testRandomness(x);