Skip to content

Commit

Permalink
adding test cases for races #22
Browse files Browse the repository at this point in the history
  • Loading branch information
isuru89 committed Jan 27, 2019
1 parent 94d976b commit d5c937f
Show file tree
Hide file tree
Showing 6 changed files with 406 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum AggregatorType {

public static AggregatorType from(String text) {
for (AggregatorType val : values()) {
if (val.name().toLowerCase().equals(text)) {
if (val.name().equalsIgnoreCase(text)) {
return val;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class LeaderboardDef extends BaseDef {
private boolean includeStatePoints = true;

public boolean hasStates() {
AggregatorType from = AggregatorType.from(aggregatorType);
AggregatorType from = AggregatorType.from(getAggregatorType());
return isIncludeStatePoints() && from != null && from.isMultiAggregatable();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,11 @@ public long addRace(long gameId, RaceDef raceDef) throws Exception {
Checks.nonNullOrEmpty(raceDef.getName(), "name");
Checks.nonNullOrEmpty(raceDef.getDisplayName(), "displayName");
Checks.greaterThanZero(raceDef.getLeaderboardId(), "leaderboardId");
Checks.validate(raceDef.getTop() != null && raceDef.getTop() > 0, "top");
Checks.onlyOneOf(!Commons.isNullOrEmpty(raceDef.getRankPointsExpression()),
!Commons.isNullOrEmpty(raceDef.getRankPoints()), "rankPointExpression", "rankPointMap");

if (readLeaderboardDef(raceDef.getLeaderboardId()) != null) {
if (listLeaderboardDefs(gameId).stream().noneMatch(l -> l.getId() == raceDef.getLeaderboardId())) {
throw new InputValidationException("Leaderboard does not exist by id #" + raceDef.getLeaderboardId() + "!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void calculateAwardPoints(RaceWinRecord winner, RaceDef raceDef, Seriali
vars.put("$winner", winner);

double awardPoints = Commons.asDouble(MVEL.executeExpression(expr, vars));
if (awardPoints == Double.NaN) {
if (Double.isNaN(awardPoints)) {
awardPoints = DefaultEntities.DEFAULT_RACE_WIN_VALUE;
}
winner.setAwardedPoints(awardPoints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public void testLeaderboardAdds() throws Exception {
Assert.assertEquals(defId, addedDef.getId().longValue());
Assert.assertEquals(def.getName(), addedDef.getName());
Assert.assertEquals(def.getDisplayName(), addedDef.getDisplayName());
// default values
Assert.assertEquals("SUM", addedDef.getAggregatorType());
Assert.assertTrue(addedDef.isIncludeStatePoints());
Assert.assertTrue(addedDef.hasStates());

// one more should be added
checkTotalCount(gameId, size + 1);
Expand Down Expand Up @@ -246,6 +250,8 @@ private LeaderboardDef readAssert(long id, LeaderboardDef check) throws Exceptio
Assert.assertEquals(check.getDisplayName(), addedDef.getDisplayName());
Assert.assertEquals(check.getDescription(), addedDef.getDescription());
Assert.assertEquals(check.getOrderBy(), addedDef.getOrderBy());
Assert.assertEquals(check.getAggregatorType(), addedDef.getAggregatorType());
Assert.assertEquals(check.isIncludeStatePoints(), addedDef.isIncludeStatePoints());
if (check.getRuleIds() == null) {
Assert.assertNull(addedDef.getRuleIds());
} else {
Expand Down
Loading

0 comments on commit d5c937f

Please sign in to comment.