CHC4010 DevOps Week 2 β Practical: Testing
Exercise 1: Testing from a specification
Determine a set of Black Box test cases and test data from the following specification.
Given an array of integers arr, return true if and only if it is a valid mountain array. That arr is a mountain array if and only if:
arr.length> = 3There exists some i with $0 < \dot { 1 } < arr.length - 1$ such that:
$arr[0] < arr[1] < ... < arr[i - 1] < arr[i]$
$arr[i] > arr[i+1] > ... > arr[arr.length - 1]$

MOUNTAIN ARRAY

NOT A MOUNTAIN ARRAY
Example:
An array that ascends. without descending
[-9, 0, 2, 5, 19]
False
An array that descends without ascending
[28, 15, 12, 5, -3, -4]
False
A valid mountain array
[0, 2, 3, 4, 5, 2, 1, 0]
True
Test cases:
Arrays of lengths 0 and 1 e.g.
[], [1]Arrays of length 2, ascending, descending and plateauing e.g.
[1, 2], [2, 1], [1, 1]An array that ascends without ever descending e.g.
[1, 2, 3, 4, 5]An array that descends without ever ascending e.g.
[5, 4, 3, 2, 1]A valley array (descends first then ascends) e.g.
[3, 2, 1, 2, 3]An array that ascends, plateaus, ascends again, and descends e.g.
[1, 2, 2, 3, 4, 3]An array that ascends, plateaus, and descends e.g.
[1, 2, 2, 1]An array that ascends, descends, plateaus, and descends again e.g.
[1, 3, 2, 2, 1]An array that plateaus, then descends e.g.
[2, 2, 1]An array that ascends, then plateaus e.g.
[1, 2, 2]An array that plateaus, then ascends e.g.
[2, 2, 3]An array that descends, then plateaus e.g.
[2, 1, 1]An array that ascends, descends, then ascends again e.g.
[1, 2, 3, 2, 4]An array that descends, ascends, then descends again e.g.
[3, 1, 2, 1]A valid mountain array of length 3 e.g.
[1, 2, 1]A mountain array that begins to descend towards the beginning e.g.
[1, 3, 2, 1]A mountain array that begins to descend towards the end e.g.
[1, 2, 3, 1]A mountain array that begins to descend around the midd e.g.
[1, 2, 3, 2, 1]
Exercise 2: Test an implementation
Using your test plan walk through the algorithm below with the tests above.
Arrays of lengths 0 and 1
[],[1]
False
False
Arrays of length 2, various
[1, 2],[2, 1], [1, 1]
False
False
Ascends without descending
[1, 2, 3, 4, 5]
False
False
Descends without ascending
[5, 4, 3, 2, 1]
False
True
Γ
Valley array
[3, 2, 1, 2, 3]
False
False
Ascends, plateaus, ascends, descends
[1, 2, 2, 3, 4, 3]
False
False
Ascends, plateaus, descends
[1, 2, 2, 1]
False
True
Γ
Ascends, descends, plateaus, descends
[1, 3, 2, 2, 1]
False
False
Plateaus, then descends
[2, 2, 1]
False
True
Γ
Ascends, then plateaus
[1, 2, 2]
False
False
Plateaus, then ascends
[2, 2, 3]
False
True
Γ
Descends, then plateaus
[2, 1, 1]
False
True
Γ
Ascends, descends, then ascends
[1, 2, 3, 2, 4]
False
True
Γ
Descends, ascends, then descends
[3, 1, 2, 1]
False
False
Valid mountain of length 3 Mountain descends towards
[1,2, 1]
True
False
Γ
beginning
[1, 3, 2, 1]
True
True
Mountain descends towards end
[1, 2, 3, 1]
True
False
Γ
Mountain descends around middle
[1, 2, 3, 2, 1]
True
True
Exercise 3: Fix the implementation
Did the implementation above pass all your tests? If not, can you find and fix the bugs? Correct implementation:
Exercise 4: Automate your tests (optional)
Can you write a method that will test the algorithm with all of your test data, so that you donβt have to do so manually? Your method should print out all the test cases that failed and output a Boolean indicating the final result.
Last updated