-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay27-Testing
More file actions
65 lines (53 loc) · 2.85 KB
/
Day27-Testing
File metadata and controls
65 lines (53 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Problem:
his problem is all about unit testing.
Your company needs a function that meets the following requirements:
For a given array of n integers, the function returns the index of the element with the minimum value in the array.
If there is more than one element with the minimum value, the returned index should be the smallest one.
If an empty array is passed to the function, it should raise an Exception.
Note: The arrays are indexed from 0.
A colleague has written that function, and your task is to design 3 separated unit tests, testing if the function behaves correctly.
The implementation in Python is listed below (Implementations in other languages can be found in the code template):
def minimum_index(seq):
if len(seq) == 0:
raise ValueError("Cannot get the minimum value index from an empty sequence")
min_idx = 0
for i in range(1, len(seq)):
if a[i] < a[min_idx]:
min_idx = i
return min_idx
Another co-worker has prepared functions that will perform the testing and validate returned results with expectations.
Your task is to implement 3 classes that will produce test data and the expected results for the testing functions.
More specifically: function get_array() in TestDataEmptyArray class and functions get_array() and get_expected_result() in classes TestDataUniqueValues and TestDataExactlyTwoDifferentMinimums following the below specifications:
get_array() method in class TestDataEmptyArray has to return an empty array.
get_array() method in class TestDataUniqueValues has to return an array of size at least 2 with all unique elements,
while method get_expected_result() of this class has to return the expected minimum value index for this array.
get_array() method in class TestDataExactlyTwoDifferentMinimums has to return an array where there are exactly two different
minimum values, while method get_expected_result() of this class has to return the expected minimum value index for this array.
Take a look at the code template to see the exact implementation of functions that your colleagues already implemented.
Solution:
static class TestDataEmptyArray {
public static int[] get_array() {
// complete this function
return new int[]{};
}
}
static class TestDataUniqueValues {
public static int[] get_array() {
// complete this function
return new int[]{1,2,3,4,5,6,7,8,9,10};
}
public static int get_expected_result() {
// complete this function
return 0;
}
}
static class TestDataExactlyTwoDifferentMinimums {
public static int[] get_array() {
// complete this function
return new int[]{1,2,3,4,5,6,1,2};
}
public static int get_expected_result() {
// complete this function
return 0;
}
}