Skip to content

Commit 1bc86d7

Browse files
committed
leetcode: RemoveElements: cover with tests
1 parent 598d473 commit 1bc86d7

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/main/java/com/leetcode/list/RemoveElements.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public final class RemoveElements {
44
private RemoveElements() {
55
}
66

7-
public ListNode removeElements(ListNode head, int val) {
7+
public static ListNode removeElements(ListNode head, int val) {
88
ListNode res = null;
99
ListNode last = null;
1010
ListNode it = head;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.leetcode.list;
2+
3+
import com.leetcode.array.IntArrayConverter;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.params.ParameterizedTest;
6+
import org.junit.jupiter.params.converter.ConvertWith;
7+
import org.junit.jupiter.params.provider.CsvSource;
8+
9+
class RemoveElementsTest {
10+
11+
@ParameterizedTest
12+
@CsvSource("'1,3,5,3,-1',3,'1,5,-1'")
13+
void testRemoveElements(@ConvertWith(ListNodeConverter.class) ListNode list, int val,
14+
@ConvertWith(IntArrayConverter.class) int[] expected) {
15+
ListNode actual = RemoveElements.removeElements(list, val);
16+
int[] actualArray = ListNodeUtils.toCollection(actual)
17+
.stream()
18+
.mapToInt(Integer::intValue)
19+
.toArray();
20+
Assertions.assertArrayEquals(expected, actualArray);
21+
}
22+
}

0 commit comments

Comments
 (0)