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
|
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
public class SolutionTest {
private Solution solution = new Solution();
private Random rand = new Random();
@Test
public void fixedMin()
{
assertEquals(-110, solution.min(new int[]{-52, 56, 30, 29, -54, 0, -110}));
assertEquals(0, solution.min(new int[]{42, 54, 65, 87, 0}));
assertEquals(1, solution.min(new int[]{1, 2, 3, 4, 5, 10}));
assertEquals(-10, solution.min(new int[]{-1, -2, -3, -4, -5, -10}));
}
@Test
public void fixedMax()
{
assertEquals(56, solution.max(new int[]{-52, 56, 30, 29, -54, 0, -110}));
assertEquals(566, solution.max(new int[]{4,6,2,1,9,63,-134,566}));
assertEquals(5, solution.max(new int[]{5}));
assertEquals(555, solution.max(new int[]{534,43,2,1,3,4,5,5,443,443,555,555}));
}
@Test
public void randomTests()
{
for(int i = 0; i < 10; i++)
{
int randLng = 2 + (rand.nextInt(14) % 15);
List<Integer> randList = new ArrayList<>();
for(int l = 0; l < randLng; l++)
{
randList.add(rand.nextInt());
}
assertEquals(Long.valueOf(Collections.min(randList)),
Long.valueOf(solution.min(randList.stream().mapToInt(e -> e).toArray())));
assertEquals(Long.valueOf(Collections.max(randList)),
Long.valueOf(solution.max(randList.stream().mapToInt(e -> e).toArray())));
}
}
}
|