Skip to content

Commit

Permalink
Fix some Jester complaints.
Browse files Browse the repository at this point in the history
  • Loading branch information
donkirkby committed Aug 9, 2015
1 parent b3d7721 commit 38fabdb
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
6 changes: 6 additions & 0 deletions core/src/com/github/donkirkby/vograbulary/Scheduler.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.github.donkirkby.vograbulary;

public interface Scheduler {
/** Schedule a task to repeat.
*/
public void scheduleRepeating(Runnable task, int periodMilliseconds);

/** Cancel a scheduled task.
*
* If the task is not scheduled or is null, do nothing.
*/
public void cancel(Runnable task);
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void setScheduler(Scheduler scheduler) {
private class ScoreTask implements Runnable {
@Override
public void run() {
screen.getMatch().getPuzzle().adjustScore(SCORE_MILLISECONDS / 1000.0f);
screen.getMatch().getPuzzle().adjustScore(SCORE_MILLISECONDS / 1000f);
screen.refreshScore();
}
}
Expand Down Expand Up @@ -186,9 +186,7 @@ public void solve() {
student.prepareResponse();
}
}
if (searchTask != null) {
scheduler.cancel(searchTask);
}
scheduler.cancel(searchTask);
}
screen.refreshPuzzle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,12 @@ public void setHint(String hint) {
* UKNOWN until a solution and response have been entered.
*/
public WordResult getResult() {
//stopJesting
if (cachedResult != WordResult.UNKNOWN) {
return cachedResult;
}
//resumeJesting

if (solution == NOT_SET) {
return WordResult.UNKNOWN;
}
Expand Down Expand Up @@ -183,7 +186,7 @@ else if (solution == NO_SOLUTION) {
}
if (isCompleted()) {
if (isTimedOut) {
if (resultText.length() > 0) {
if (resultText.length() != 0) {
resultText += "and ";
}
resultText += "out of time ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,37 @@ public void adjustScore() {
assertThat("refresh count", screen.getScoreRefreshCount(), is(loopCount));
}

@Test
public void adjustScoreRoundToZero() {
controller.start();
Puzzle puzzle = screen.getPuzzle();

int seconds = (int) Puzzle.MAX_DELAY;
int loopCount = seconds * 1000 / Controller.SCORE_MILLISECONDS - 2;
for (int i = 0; i < loopCount; i++) {
scoreTask.run();
}

assertThat("score", puzzle.getScore(WordResult.NOT_IMPROVED), is(0));
}

@Test
public void adjustScoreOnResponseUntilTimeout() {
random.setPuzzles("RPE");
controller.start();
Puzzle puzzle = screen.getPuzzle();

puzzle.setSolution("ROPE");
controller.solve();
int seconds = (int) Puzzle.MAX_DELAY/2;
int loopCount = seconds * 1000 / Controller.SCORE_MILLISECONDS;
for (int i = 0; i < loopCount; i++) {
scoreTask.run();
}

assertThat("score", puzzle.getScore(WordResult.NOT_IMPROVED), is(100));
}

@Test
public void newMatch() {
controller.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ public void getDisplayAfterSkip() {
assertThat("display", display, is("skipping -20 of 20"));
}

@Test
public void getDisplayAfterResponse() {
float seconds = 20;
puzzle.adjustScore(seconds);
puzzle.setSolution("");
puzzle.setResponse("PIPE");
String display = puzzle.getResultDisplay();

assertThat("display", display, is("word found (-20 of 20)"));
}

@Test
public void getDisplayAfterInvalidResponse() {
float seconds = 20;
Expand Down

0 comments on commit 38fabdb

Please sign in to comment.