-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecondLargestElement.test.java
More file actions
47 lines (40 loc) · 1.48 KB
/
Copy pathSecondLargestElement.test.java
File metadata and controls
47 lines (40 loc) · 1.48 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
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class SecondLargestElementTest {
@Test
public void testFindSecondLargest_Basic() {
int[] arr = {10, 5, 19, 8, 20, 15};
int expected = 19;
int result = SecondLargestElement.findSecondLargest(arr);
assertEquals(expected, result);
}
@Test
public void testFindSecondLargest_DuplicateLargest() {
int[] arr = {10, 20, 20, 15, 8};
int expected = 15;
int result = SecondLargestElement.findSecondLargest(arr);
assertEquals(expected, result);
}
@Test
public void testFindSecondLargest_NegativeValues() {
int[] arr = {-10, -20, -30, -5};
int expected = -10;
int result = SecondLargestElement.findSecondLargest(arr);
assertEquals(expected, result);
}
@Test
public void testFindSecondLargest_SingleElement() {
int[] arr = {15};
int expected = Integer.MIN_VALUE; // Since there's no second largest value in this case.
int result = SecondLargestElement.findSecondLargest(arr);
assertEquals(expected, result);
}
@Test
public void testFindSecondLargest_EmptyArray() {
int[] arr = {};
int expected = Integer.MIN_VALUE; // No value to compare against in this case.
int result = SecondLargestElement.findSecondLargest(arr);
assertEquals(expected, result);
}
// ... Additional test cases as necessary ...
}