Browse Source

leaderboard: getTop10Players returns elements of sorted list

leaderboard
Tobias Krause 3 years ago
committed by Lorenz Hohmann
parent
commit
21b07d077f
  1. 12
      src/main/java/de/tims/leaderboard/Leaderboard.java
  2. 8
      src/test/java/de/tims/leaderboard/LeaderboardTest.java

12
src/main/java/de/tims/leaderboard/Leaderboard.java

@ -6,12 +6,20 @@ import de.tims.player_management.Player;
public class Leaderboard {
private List<Player> allPlayers;
public Leaderboard(List<Player> allPlayers, String actualPlayer) {
// TODO Auto-generated constructor stub
this.allPlayers = allPlayers;
}
public Player[] getTop10Players() {
return new Player[] {null, null, null, null, null, null, null, null, null, null};
Player[] top10Players = new Player[10];
for (int i = 0; i < allPlayers.size(); i++) {
top10Players[i] = allPlayers.get(i);
}
return top10Players;
}
}

8
src/test/java/de/tims/leaderboard/LeaderboardTest.java

@ -25,7 +25,13 @@ class LeaderboardTest {
}
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}));
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}));
}
}
Loading…
Cancel
Save