initisl implementation
This commit is contained in:
parent
7a2d7f435f
commit
e3699c9e17
@ -1,9 +1,9 @@
|
||||
package djmil.cordacheckers.cordaclient.dao;
|
||||
|
||||
public record Rank(
|
||||
Integer gamesPlayed,
|
||||
Integer gamesWon,
|
||||
Integer gamesDraw
|
||||
Integer total, // total played games
|
||||
Integer victory, // total won games
|
||||
Integer draw // agreed draw with opponent
|
||||
) {
|
||||
|
||||
}
|
||||
|
@ -58,13 +58,13 @@ public class RankingTests {
|
||||
|
||||
final Map<String, Rank> liderboard2 = cordaClient.fetchRanking(hiCustodian);
|
||||
|
||||
assertThat(liderboard1.get(winnerName).gamesWon() +1 == liderboard2.get(winnerName).gamesWon() );
|
||||
assertThat(liderboard1.get(winnerName).gamesPlayed() +1 == liderboard2.get(winnerName).gamesPlayed());
|
||||
assertThat(liderboard1.get(winnerName).gamesDraw() == liderboard2.get(winnerName).gamesDraw() );
|
||||
assertThat(liderboard1.get(winnerName).victory() +1 == liderboard2.get(winnerName).victory());
|
||||
assertThat(liderboard1.get(winnerName).total() +1 == liderboard2.get(winnerName).total() );
|
||||
assertThat(liderboard1.get(winnerName).draw() == liderboard2.get(winnerName).draw() );
|
||||
|
||||
assertThat(liderboard1.get(losserName).gamesWon() == liderboard2.get(losserName).gamesWon() );
|
||||
assertThat(liderboard1.get(losserName).gamesPlayed() +1 == liderboard2.get(losserName).gamesPlayed());
|
||||
assertThat(liderboard1.get(losserName).gamesDraw() == liderboard2.get(losserName).gamesDraw() );
|
||||
assertThat(liderboard1.get(losserName).victory() == liderboard2.get(losserName).victory());
|
||||
assertThat(liderboard1.get(losserName).total() +1 == liderboard2.get(losserName).total() );
|
||||
assertThat(liderboard1.get(losserName).draw() == liderboard2.get(losserName).draw() );
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -87,13 +87,13 @@ public class RankingTests {
|
||||
|
||||
final Map<String, Rank> liderboard2 = cordaClient.fetchRanking(hiCustodian);
|
||||
|
||||
assertThat(liderboard1.get(winnerName).gamesWon() +1 == liderboard2.get(winnerName).gamesWon() );
|
||||
assertThat(liderboard1.get(winnerName).gamesPlayed() +1 == liderboard2.get(winnerName).gamesPlayed());
|
||||
assertThat(liderboard1.get(winnerName).gamesDraw() == liderboard2.get(winnerName).gamesDraw() );
|
||||
assertThat(liderboard1.get(winnerName).victory() +1 == liderboard2.get(winnerName).victory());
|
||||
assertThat(liderboard1.get(winnerName).total() +1 == liderboard2.get(winnerName).total() );
|
||||
assertThat(liderboard1.get(winnerName).draw() == liderboard2.get(winnerName).draw() );
|
||||
|
||||
assertThat(liderboard1.get(losserName).gamesWon() == liderboard2.get(losserName).gamesWon() );
|
||||
assertThat(liderboard1.get(losserName).gamesPlayed() +1 == liderboard2.get(losserName).gamesPlayed());
|
||||
assertThat(liderboard1.get(losserName).gamesDraw() == liderboard2.get(losserName).gamesDraw() );
|
||||
assertThat(liderboard1.get(losserName).victory() == liderboard2.get(losserName).victory());
|
||||
assertThat(liderboard1.get(losserName).total() +1 == liderboard2.get(losserName).total() );
|
||||
assertThat(liderboard1.get(losserName).draw() == liderboard2.get(losserName).draw() );
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -114,13 +114,13 @@ public class RankingTests {
|
||||
cordaClient.gameDrawAccept(hiPlayer1, game.uuid());
|
||||
final Map<String, Rank> liderboard2 = cordaClient.fetchRanking(hiCustodian);
|
||||
|
||||
assertThat(liderboard1.get(player1).gamesWon() == liderboard2.get(player1).gamesWon() );
|
||||
assertThat(liderboard1.get(player1).gamesPlayed() +1 == liderboard2.get(player1).gamesPlayed());
|
||||
assertThat(liderboard1.get(player1).gamesDraw() +1 == liderboard2.get(player1).gamesDraw() );
|
||||
assertThat(liderboard1.get(player1).victory() == liderboard2.get(player1).victory());
|
||||
assertThat(liderboard1.get(player1).total() +1 == liderboard2.get(player1).total() );
|
||||
assertThat(liderboard1.get(player1).draw() +1 == liderboard2.get(player1).draw() );
|
||||
|
||||
assertThat(liderboard1.get(player2).gamesWon() == liderboard2.get(player2).gamesWon() );
|
||||
assertThat(liderboard1.get(player2).gamesPlayed() +1 == liderboard2.get(player2).gamesPlayed());
|
||||
assertThat(liderboard1.get(player2).gamesDraw() +1 == liderboard2.get(player2).gamesDraw() );
|
||||
assertThat(liderboard1.get(player2).victory() == liderboard2.get(player2).victory());
|
||||
assertThat(liderboard1.get(player2).total() +1 == liderboard2.get(player2).total() );
|
||||
assertThat(liderboard1.get(player2).draw() +1 == liderboard2.get(player2).draw() );
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1,50 +1,50 @@
|
||||
package djmil.cordacheckers.gameresult;
|
||||
|
||||
public class Rank {
|
||||
private Integer gamesPlayed;
|
||||
private Integer gamesWon;
|
||||
private Integer gamesDraw;
|
||||
private Integer total; // total played games
|
||||
private Integer victory; // total won games
|
||||
private Integer draw; // agreed draw with opponent
|
||||
|
||||
// Serialisation service requires a default constructor
|
||||
public Rank() {
|
||||
gamesPlayed = 0;
|
||||
gamesWon = 0;
|
||||
gamesDraw = 0;
|
||||
total = 0;
|
||||
victory = 0;
|
||||
draw = 0;
|
||||
}
|
||||
|
||||
public Rank(Integer gamesPlayed, Integer gamesWon, Integer gamesDraw) {
|
||||
this.gamesPlayed = gamesPlayed;
|
||||
this.gamesWon = gamesWon;
|
||||
this.gamesDraw = gamesDraw;
|
||||
public Rank(Integer total, Integer vicotry, Integer draw) {
|
||||
this.total = total;
|
||||
this.victory = vicotry;
|
||||
this.draw = draw;
|
||||
}
|
||||
|
||||
Rank gamePlayed() {
|
||||
gamesPlayed++;
|
||||
total++;
|
||||
return this;
|
||||
}
|
||||
|
||||
Rank gameWon() {
|
||||
gamesWon++;
|
||||
victory++;
|
||||
return this;
|
||||
}
|
||||
|
||||
Rank gameDraw(boolean isDraw) {
|
||||
if (isDraw)
|
||||
gamesDraw++;
|
||||
draw++;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getGamesPlayed() {
|
||||
return gamesPlayed;
|
||||
public Integer getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public Integer getGamesWon() {
|
||||
return gamesWon;
|
||||
public Integer getVictory() {
|
||||
return victory;
|
||||
}
|
||||
|
||||
public Integer getGamesDraw() {
|
||||
return gamesDraw;
|
||||
public Integer getDraw() {
|
||||
return draw;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,9 +14,9 @@ export default function Leaderboard({ players }) {
|
||||
|
||||
return <tr key={playerName} className={players.isCurrentUser(playerName) && 'currentuser'}>
|
||||
<td>{playerName}</td>
|
||||
<td>{rank.gamesPlayed}</td>
|
||||
<td>{rank.gamesWon}</td>
|
||||
<td>{rank.gamesDraw}</td>
|
||||
<td>{rank.total}</td>
|
||||
<td>{rank.victory}</td>
|
||||
<td>{rank.draw}</td>
|
||||
</tr>
|
||||
});
|
||||
|
||||
@ -26,8 +26,8 @@ export default function Leaderboard({ players }) {
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Played</th>
|
||||
<th>Won</th>
|
||||
<th>Total</th>
|
||||
<th>Victory</th>
|
||||
<th>Draw</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
Loading…
Reference in New Issue
Block a user