Cody

Solution 1943071

Submitted on 19 Sep 2019
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
binary_array = [1 1 0 1]; expected_length = 2; expected_index = 1; [actual_length actual_index] = longest_run(binary_array); assert(isequal(expected_length, actual_length)); assert(isequal(expected_index, actual_index));

d = 1×3 logical array 0 0 0 idx = 1×0 empty double row vector d = 1×3 logical array 0 0 0 idx = 1×0 empty double row vector d = 1×3 logical array 1 0 0 idx = 1 L = 2

2   Pass
binary_array = [1 1 0 1 0 0 0 0 1 1 1]; expected_length = 4; expected_index = 5; [actual_length actual_index] = longest_run(binary_array); assert(isequal(expected_length, actual_length)); assert(isequal(expected_index, actual_index));

d = 1×10 logical array 0 0 0 0 0 0 0 0 0 0 idx = 1×0 empty double row vector d = 1×10 logical array 0 0 0 0 0 0 0 0 0 0 idx = 1×0 empty double row vector d = 1×10 logical array 0 0 0 0 0 0 0 0 0 0 idx = 1×0 empty double row vector d = 1×10 logical array 0 0 0 0 0 0 0 0 0 0 idx = 1×0 empty double row vector d = 1×10 logical array 0 0 0 0 0 0 0 0 0 0 idx = 1×0 empty double row vector d = 1×10 logical array 0 0 0 0 0 0 0 0 0 0 idx = 1×0 empty double row vector d = 1×10 logical array 0 0 0 0 0 0 0 0 0 0 idx = 1×0 empty double row vector d = 1×10 logical array 0 0 0 0 1 0 0 0 0 0 idx = 5 L = 4

3   Fail
binary_array = [1 0]; expected_length = 1; expected_index = 1; [actual_length actual_index] = longest_run(binary_array); assert(isequal(expected_length, actual_length)); assert(isequal(expected_index, actual_index));

d = logical 0 idx = []

Error using movsum Window length must be a finite positive scalar or 2-element vector of finite nonnegative scalars. Error in Test3 (line 4) [actual_length actual_index] = longest_run(binary_array);

4   Fail
binary_array = [1]; expected_length = 1; expected_index = 1; [actual_length actual_index] = longest_run(binary_array); assert(isequal(expected_length, actual_length)); assert(isequal(expected_index, actual_index));

Error using movsum Window length must be a finite positive scalar or 2-element vector of finite nonnegative scalars. Error in Test4 (line 4) [actual_length actual_index] = longest_run(binary_array);

5   Pass
binary_array = [1 1 1 1 1 1]; expected_length = 6; expected_index = 1; [actual_length actual_index] = longest_run(binary_array); assert(isequal(expected_length, actual_length)); assert(isequal(expected_index, actual_index));

d = 1×5 logical array 1 0 0 0 0 idx = 1 L = 6

Suggested Problems