|
@ -0,0 +1,61 @@ |
|
|
|
|
|
package de.tims.leaderboard; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.*; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest; |
|
|
|
|
|
import org.junit.jupiter.params.provider.Arguments; |
|
|
|
|
|
import org.junit.jupiter.params.provider.MethodSource; |
|
|
|
|
|
|
|
|
|
|
|
import de.tims.player_management.Player; |
|
|
|
|
|
|
|
|
|
|
|
class LeaderboardTest { |
|
|
|
|
|
|
|
|
|
|
|
Leaderboard leaderboard; |
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest |
|
|
|
|
|
@MethodSource("testCasesForGetTop10Players") |
|
|
|
|
|
void getTop10PlayersTest(String testName, List<Player> allPlayers, String actualPlayer, Player[] expectedResult) { |
|
|
|
|
|
leaderboard = new Leaderboard(allPlayers, actualPlayer); |
|
|
|
|
|
Player[] calculatedResutl = leaderboard.getTop10Players(); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(calculatedResutl).describedAs(testName).isEqualTo(expectedResult); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static Stream<Arguments> testCasesForGetTop10Players() { |
|
|
|
|
|
return Stream.of(Arguments.of("EmptyListReturnsEmptyArray", List.of(), "TestPlayer", new Player[] {null, null, null, null, null, null, null, null, null, null}), |
|
|
|
|
|
Arguments.of("SortedListWithLessThan10ElementsReturnsListAsArray", |
|
|
|
|
|
List.of(new Player("Eins", 80), new Player("Zwei", 70), new Player("Drei", 60), new Player("Vier", 50), |
|
|
|
|
|
new Player("Fuenf", 40), new Player("Sechs", 30), new Player("Sieben", 20), new Player("Acht", 10)), |
|
|
|
|
|
"TestPlayer", |
|
|
|
|
|
new Player[] {new Player("Eins", 80), new Player("Zwei", 70), new Player("Drei", 60), new Player("Vier", 50), |
|
|
|
|
|
new Player("Fuenf", 40), new Player("Sechs", 30), new Player("Sieben", 20), new Player("Acht", 10), null, null}), |
|
|
|
|
|
Arguments.of("SortedListWithMoreThan10ElementsReturnsFirst10ElementsAsArray", |
|
|
|
|
|
List.of(new Player("Eins", 140), new Player("Zwei", 130), new Player("Drei", 120), new Player("Vier", 110), |
|
|
|
|
|
new Player("Fuenf", 100), new Player("Sechs", 90), new Player("Sieben", 80), new Player("Acht", 70), |
|
|
|
|
|
new Player("Neun", 60), new Player("Zehn", 50), new Player("Elf", 40), new Player("Zwoelf", 30), |
|
|
|
|
|
new Player("Dreizehn", 20), new Player("Vierzehn", 10)), |
|
|
|
|
|
"TestPlayer", |
|
|
|
|
|
new Player[] {new Player("Eins", 140), new Player("Zwei", 130), new Player("Drei", 120), new Player("Vier", 110), |
|
|
|
|
|
new Player("Fuenf", 100), new Player("Sechs", 90), new Player("Sieben", 80), new Player("Acht", 70), |
|
|
|
|
|
new Player("Neun", 60), new Player("Zehn", 50)}), |
|
|
|
|
|
Arguments.of("UnsortedListWithLessThan10ElementsReturnsElementsSortedByPoints", |
|
|
|
|
|
List.of(new Player("Eins", 20), new Player("Zwei", 30), new Player("Drei", 10), new Player("Vier", 60), |
|
|
|
|
|
new Player("Fuenf", 50), new Player("Sechs", 90)), |
|
|
|
|
|
"TestPlayer", |
|
|
|
|
|
new Player[] {new Player("Sechs", 90), new Player("Vier", 60), new Player("Fuenf", 50), new Player("Zwei", 30), |
|
|
|
|
|
new Player("Eins", 20), new Player("Drei", 10), null, null, null, null}), |
|
|
|
|
|
Arguments.of("UnsortedListWithMoreThan10ElementsReturns10ElementsWithMostPointsSortedByPoints", |
|
|
|
|
|
List.of(new Player("Eins", 0), new Player("Zwei", 130), new Player("Drei", 20), new Player("Vier", 10), |
|
|
|
|
|
new Player("Fuenf", 20), new Player("Sechs", 70), new Player("Sieben", 60), new Player("Acht", 20), |
|
|
|
|
|
new Player("Neun", 60), new Player("Zehn", 50), new Player("Elf", 90), new Player("Zwoelf", 20), |
|
|
|
|
|
new Player("Dreizehn", 40), new Player("Vierzehn", 80)), |
|
|
|
|
|
"TestPlayer", |
|
|
|
|
|
new Player[] {new Player("Zwei", 130), new Player("Elf", 90), new Player("Vierzehn", 80), new Player("Sechs", 70), |
|
|
|
|
|
new Player("Sieben", 60), new Player("Neun", 60), new Player("Zehn", 50), new Player("Dreizehn", 40), |
|
|
|
|
|
new Player("Drei", 20), new Player("Fuenf", 20)})); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |