initisl implementation

This commit is contained in:
djmil 2023-11-10 14:04:05 +01:00
parent 7a2d7f435f
commit e3699c9e17
4 changed files with 45 additions and 45 deletions

View File

@ -1,9 +1,9 @@
package djmil.cordacheckers.cordaclient.dao; package djmil.cordacheckers.cordaclient.dao;
public record Rank( public record Rank(
Integer gamesPlayed, Integer total, // total played games
Integer gamesWon, Integer victory, // total won games
Integer gamesDraw Integer draw // agreed draw with opponent
) { ) {
} }

View File

@ -58,13 +58,13 @@ public class RankingTests {
final Map<String, Rank> liderboard2 = cordaClient.fetchRanking(hiCustodian); final Map<String, Rank> liderboard2 = cordaClient.fetchRanking(hiCustodian);
assertThat(liderboard1.get(winnerName).gamesWon() +1 == liderboard2.get(winnerName).gamesWon() ); assertThat(liderboard1.get(winnerName).victory() +1 == liderboard2.get(winnerName).victory());
assertThat(liderboard1.get(winnerName).gamesPlayed() +1 == liderboard2.get(winnerName).gamesPlayed()); assertThat(liderboard1.get(winnerName).total() +1 == liderboard2.get(winnerName).total() );
assertThat(liderboard1.get(winnerName).gamesDraw() == liderboard2.get(winnerName).gamesDraw() ); assertThat(liderboard1.get(winnerName).draw() == liderboard2.get(winnerName).draw() );
assertThat(liderboard1.get(losserName).gamesWon() == liderboard2.get(losserName).gamesWon() ); assertThat(liderboard1.get(losserName).victory() == liderboard2.get(losserName).victory());
assertThat(liderboard1.get(losserName).gamesPlayed() +1 == liderboard2.get(losserName).gamesPlayed()); assertThat(liderboard1.get(losserName).total() +1 == liderboard2.get(losserName).total() );
assertThat(liderboard1.get(losserName).gamesDraw() == liderboard2.get(losserName).gamesDraw() ); assertThat(liderboard1.get(losserName).draw() == liderboard2.get(losserName).draw() );
} }
@Test @Test
@ -87,13 +87,13 @@ public class RankingTests {
final Map<String, Rank> liderboard2 = cordaClient.fetchRanking(hiCustodian); final Map<String, Rank> liderboard2 = cordaClient.fetchRanking(hiCustodian);
assertThat(liderboard1.get(winnerName).gamesWon() +1 == liderboard2.get(winnerName).gamesWon() ); assertThat(liderboard1.get(winnerName).victory() +1 == liderboard2.get(winnerName).victory());
assertThat(liderboard1.get(winnerName).gamesPlayed() +1 == liderboard2.get(winnerName).gamesPlayed()); assertThat(liderboard1.get(winnerName).total() +1 == liderboard2.get(winnerName).total() );
assertThat(liderboard1.get(winnerName).gamesDraw() == liderboard2.get(winnerName).gamesDraw() ); assertThat(liderboard1.get(winnerName).draw() == liderboard2.get(winnerName).draw() );
assertThat(liderboard1.get(losserName).gamesWon() == liderboard2.get(losserName).gamesWon() ); assertThat(liderboard1.get(losserName).victory() == liderboard2.get(losserName).victory());
assertThat(liderboard1.get(losserName).gamesPlayed() +1 == liderboard2.get(losserName).gamesPlayed()); assertThat(liderboard1.get(losserName).total() +1 == liderboard2.get(losserName).total() );
assertThat(liderboard1.get(losserName).gamesDraw() == liderboard2.get(losserName).gamesDraw() ); assertThat(liderboard1.get(losserName).draw() == liderboard2.get(losserName).draw() );
} }
@Test @Test
@ -114,13 +114,13 @@ public class RankingTests {
cordaClient.gameDrawAccept(hiPlayer1, game.uuid()); cordaClient.gameDrawAccept(hiPlayer1, game.uuid());
final Map<String, Rank> liderboard2 = cordaClient.fetchRanking(hiCustodian); final Map<String, Rank> liderboard2 = cordaClient.fetchRanking(hiCustodian);
assertThat(liderboard1.get(player1).gamesWon() == liderboard2.get(player1).gamesWon() ); assertThat(liderboard1.get(player1).victory() == liderboard2.get(player1).victory());
assertThat(liderboard1.get(player1).gamesPlayed() +1 == liderboard2.get(player1).gamesPlayed()); assertThat(liderboard1.get(player1).total() +1 == liderboard2.get(player1).total() );
assertThat(liderboard1.get(player1).gamesDraw() +1 == liderboard2.get(player1).gamesDraw() ); assertThat(liderboard1.get(player1).draw() +1 == liderboard2.get(player1).draw() );
assertThat(liderboard1.get(player2).gamesWon() == liderboard2.get(player2).gamesWon() ); assertThat(liderboard1.get(player2).victory() == liderboard2.get(player2).victory());
assertThat(liderboard1.get(player2).gamesPlayed() +1 == liderboard2.get(player2).gamesPlayed()); assertThat(liderboard1.get(player2).total() +1 == liderboard2.get(player2).total() );
assertThat(liderboard1.get(player2).gamesDraw() +1 == liderboard2.get(player2).gamesDraw() ); assertThat(liderboard1.get(player2).draw() +1 == liderboard2.get(player2).draw() );
} }
@Test @Test

View File

@ -1,50 +1,50 @@
package djmil.cordacheckers.gameresult; package djmil.cordacheckers.gameresult;
public class Rank { public class Rank {
private Integer gamesPlayed; private Integer total; // total played games
private Integer gamesWon; private Integer victory; // total won games
private Integer gamesDraw; private Integer draw; // agreed draw with opponent
// Serialisation service requires a default constructor // Serialisation service requires a default constructor
public Rank() { public Rank() {
gamesPlayed = 0; total = 0;
gamesWon = 0; victory = 0;
gamesDraw = 0; draw = 0;
} }
public Rank(Integer gamesPlayed, Integer gamesWon, Integer gamesDraw) { public Rank(Integer total, Integer vicotry, Integer draw) {
this.gamesPlayed = gamesPlayed; this.total = total;
this.gamesWon = gamesWon; this.victory = vicotry;
this.gamesDraw = gamesDraw; this.draw = draw;
} }
Rank gamePlayed() { Rank gamePlayed() {
gamesPlayed++; total++;
return this; return this;
} }
Rank gameWon() { Rank gameWon() {
gamesWon++; victory++;
return this; return this;
} }
Rank gameDraw(boolean isDraw) { Rank gameDraw(boolean isDraw) {
if (isDraw) if (isDraw)
gamesDraw++; draw++;
return this; return this;
} }
public Integer getGamesPlayed() { public Integer getTotal() {
return gamesPlayed; return total;
} }
public Integer getGamesWon() { public Integer getVictory() {
return gamesWon; return victory;
} }
public Integer getGamesDraw() { public Integer getDraw() {
return gamesDraw; return draw;
} }
} }

View File

@ -14,9 +14,9 @@ export default function Leaderboard({ players }) {
return <tr key={playerName} className={players.isCurrentUser(playerName) && 'currentuser'}> return <tr key={playerName} className={players.isCurrentUser(playerName) && 'currentuser'}>
<td>{playerName}</td> <td>{playerName}</td>
<td>{rank.gamesPlayed}</td> <td>{rank.total}</td>
<td>{rank.gamesWon}</td> <td>{rank.victory}</td>
<td>{rank.gamesDraw}</td> <td>{rank.draw}</td>
</tr> </tr>
}); });
@ -26,8 +26,8 @@ export default function Leaderboard({ players }) {
<thead> <thead>
<tr> <tr>
<th></th> <th></th>
<th>Played</th> <th>Total</th>
<th>Won</th> <th>Victory</th>
<th>Draw</th> <th>Draw</th>
</tr> </tr>
</thead> </thead>