Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

John Ferguson Scoreboard Lab Done #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Answers.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# John Ferguson
#Scoreboard Lab
#2/19/15

>**Question 1:** In terms of the mantra, describe the tests you need to verify the correctness of a non-full SCOREBOARD with more than two entries. Be specific about how many tests you need.

**Answer 1:** The test we would need for a non full scoreboard is testMultipleScoresNonFull. This would give us a total of three tests. We need to use the bubble skip. Make the number from the right go to the left if it's greater than the number to the left of it.

>**Question 2:** In terms of the mantra, describe the test you need to verify the corrections of a full SCOREBOARD. Be specific aobut how many tests you need. HINT: Think carefully about the "bottom" of the SCOREBOARD.

**Answer 2:** The test we would need for a non full scoreboard is testMultipleScoresFull. This would give us a total of four tests.

32 changes: 29 additions & 3 deletions src/Scoreboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,43 @@ public class Scoreboard {
private int maxCount;

public Scoreboard(int maxScoreCount) {
scores = new ArrayList<>(maxScoreCount);
scores = new ArrayList<Integer>(maxScoreCount);
maxCount = maxScoreCount;
}

public void addScore(int score) {
scores.add(score);
if (!isHighScore(score)) {
return;
}

if (scores.size() < maxCount) {
scores.add(score);
}
else {
scores.set(scores.size() - 1, score);
}


for (int i = scores.size() - 1; i > 0; i--) {
if (scores.get(i) > scores.get(i-1)) {
int temp = scores.get(i-1);
scores.set((i-1), scores.get(i));
scores.set(i, temp);
}
}
}

public boolean isHighScore(int score) {
if (scores.size() == 0 || scores.size() < maxCount) {
return true;
}
else if (score > scores.get(scores.size() - 1)) {
return true;
}
else {
return false;
}

return true;
}

public int getScore(int position) {
Expand Down
57 changes: 55 additions & 2 deletions src/ScoreboardTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class ScoreboardTest extends TestCase {
public void testEmptyScoreboard() {
Scoreboard sb = new Scoreboard(10);

assertTrue(sb.isHighScore(10));
assertEquals(true, sb.isHighScore(10));
assertEquals(0, sb.getScore(0));
assertEquals(0, sb.getNumScores());
}
Expand All @@ -14,8 +14,61 @@ public void testOneEntry() {

sb.addScore(50);

assertTrue(sb.isHighScore(10));
assertEquals(true, sb.isHighScore(10));
assertEquals(50, sb.getScore(0));
assertEquals(1, sb.getNumScores());
}
public void testSecondScoreBeforeFirst() {
Scoreboard sb = new Scoreboard(10);

sb.addScore(50);
sb.addScore(51);
assertEquals(true, sb.isHighScore(10));
assertEquals(51, sb.getScore(0));
assertEquals(50, sb.getScore(1));
assertEquals(2, sb.getNumScores());


}

public void testSecondScoreAfterFirst() {
Scoreboard sb = new Scoreboard(10);

sb.addScore(50);
sb.addScore(49);
assertEquals(true, sb.isHighScore(10));
assertEquals(50, sb.getScore(0));
assertEquals(49, sb.getScore(1));
assertEquals(2, sb.getNumScores());
}

public void testMultipleScoresNonFull() {
Scoreboard sb = new Scoreboard(10);

sb.addScore(50);
sb.addScore(51);
sb.addScore(52);

assertEquals(true, sb.isHighScore(10));
assertEquals(52, sb.getScore(0));
assertEquals(51, sb.getScore(1));
assertEquals(50, sb.getScore(2));
assertEquals(3, sb.getNumScores());
}

public void testMultipleScoresFull() {
Scoreboard sb = new Scoreboard(3);

sb.addScore(50);
sb.addScore(51);
sb.addScore(52);
sb.addScore(53);

assertFalse(sb.isHighScore(10));
assertEquals(53, sb.getScore(0));
assertEquals(52, sb.getScore(1));
assertEquals(51, sb.getScore(2));
assertEquals(3, sb.getNumScores());

}
}