Skip to content

Commit

Permalink
Add additional test for reversed immutable list.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanaken committed Feb 6, 2024
1 parent 8750fc3 commit 9ee376d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public ImmutableList<T> addHead(final T head) {

@Override
public ImmutableList<T> addList(final ImmutableList<T> list) {
final ImmutableList<T> ts2 = new ImmutableList<>(originalList);
ts2.addAll(list.reverse());
final LinkedList<T> ts2 = new LinkedList<>(list.reverse());
ts2.addAll(originalList);
return new ReversedImmutableList<>(ts2);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package io.parsingdata.metal.data;


import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.params.provider.Arguments.arguments;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -28,7 +26,36 @@ public static Stream<Arguments> addHeadTest() {
@ParameterizedTest
@MethodSource
public void addHeadTest(final List<Integer> originalToReverse, final int head, final List<Integer> expected) {
final ImmutableList<Integer> reverse = new ImmutableList<>(originalToReverse).reverse().addHead(head);
final ImmutableList<Integer> reverse1 = new ImmutableList<>(originalToReverse).reverse();
final ImmutableList<Integer> reverse = reverse1.addHead(head);
final List<Integer> actual = new ArrayList<>(reverse);
assertIterableEquals(expected, actual);
assertEquals(head, reverse.head());
}

public static Stream<Arguments> addListTest() {
return Stream.of(
arguments(List.of(), List.of(), List.of()),
arguments(List.of(1), List.of(), List.of(1)),
arguments(List.of(1, 2), List.of(), List.of(2, 1)),
arguments(List.of(1, 2, 3), List.of(), List.of(3, 2, 1)),

arguments(List.of(), List.of(4), List.of(4)),
arguments(List.of(1), List.of(4), List.of(1, 4)),
arguments(List.of(1, 2), List.of(4), List.of(2, 1, 4)),
arguments(List.of(1, 2, 3), List.of(4), List.of(3, 2, 1, 4)),

arguments(List.of(), List.of(4, 5), List.of(4, 5)),
arguments(List.of(1), List.of(4, 5), List.of(1, 4, 5)),
arguments(List.of(1, 2), List.of(4, 5), List.of(2, 1, 4, 5)),
arguments(List.of(1, 2, 3), List.of(4, 5), List.of(3, 2, 1, 4, 5))
);
}

@ParameterizedTest
@MethodSource
public void addListTest(final List<Integer> listToReverse, final List<Integer> listToAdd, final List<Integer> expected) {
final ImmutableList<Integer> reverse = new ImmutableList<>(listToReverse).reverse().addList(new ImmutableList<>(listToAdd));
final List<Integer> actual = new ArrayList<>(reverse);
assertIterableEquals(expected, actual);
}
Expand Down

0 comments on commit 9ee376d

Please sign in to comment.