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

This is the scoreboard lab. #17

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
7 changes: 7 additions & 0 deletions answers-ScoreboardLab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
##Scoreboard-Lab
###Martin Nesbitt
***Question 1:***
There must be a test that verifies that the high score is in the `[0]` index of the `scores` array list. There also must be verification that the scores are sorting themselves from largest to smallest value.

***Question 2:***
A full scoreboard test includes adding the same amount of scores as the maximum amount able to be held in the scoreboard itself.
16 changes: 10 additions & 6 deletions src/Scoreboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
public class Scoreboard {
private ArrayList<Integer> scores;
private int maxCount;

private int highScore = 0;
private int temp;
public Scoreboard(int maxScoreCount) {
scores = new ArrayList<>(maxScoreCount);
maxCount = maxScoreCount;
Expand All @@ -12,12 +13,15 @@ public Scoreboard(int maxScoreCount) {
public void addScore(int score) {
scores.add(score);
}

public boolean isHighScore(int score) {

return true;
if (score >= getScore(0)){
return true;
}
else {
return false;
}
}

public int getScore(int position) {
if (position < scores.size()) {
return scores.get(position);
Expand All @@ -30,4 +34,4 @@ public int getScore(int position) {
public int getNumScores() {
return scores.size();
}
}
}
52 changes: 48 additions & 4 deletions src/ScoreboardTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public class ScoreboardTest extends TestCase {
public void testEmptyScoreboard() {
Scoreboard sb = new Scoreboard(10);

assertTrue(sb.isHighScore(10));
assertEquals(0, sb.getScore(0));
assertEquals(0, sb.getNumScores());
}
Expand All @@ -13,9 +12,54 @@ public void testOneEntry() {
Scoreboard sb = new Scoreboard(10);

sb.addScore(50);

assertTrue(sb.isHighScore(10));
assertEquals(50, sb.getScore(0));
assertEquals(1, sb.getNumScores());
}
}

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

sb.addScore(1);
sb.addScore(2);

assertEquals(1, sb.getScore(0));
assertEquals(2, sb.getScore(1));
}

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

sb.addScore(1);
sb.addScore(2);

assertEquals(1, sb.getScore(0));
assertEquals(2, sb.getScore(1));
}

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

sb.addScore(1);
sb.addScore(2);
sb.addScore(3);

assertEquals(true, sb.isHighScore(3));
}
public void testFullBoard() {
Scoreboard sb = new Scoreboard(5);

sb.addScore(4);
sb.addScore(2);
sb.addScore(1);
sb.addScore(3);
sb.addScore(5);

assertEquals(4, sb.getScore(0));
assertEquals(2, sb.getScore(1));
assertEquals(1, sb.getScore(2));
assertEquals(3, sb.getScore(3));
assertEquals(5, sb.getScore(4));

}

}