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

Fritz Scoreboard Lab #7

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 FritzAnswers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**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.
You only need two tests. You need a to test to confirm that the numbers are in the correct order and a test to confirm the size of the scoreboard.
(*Note* All can be done in one Test Method)

**Question 2:** In terms of the mantra, describe the tests you need to verify the corrections of a full Scoreboard. Be speicific about how many tests you need. HINT: Think carefully about the "bottom" of the Scoreboard.
You need three tests. One to confirm the numbers are in the right order, one to confirm the size of the scoreboard, and one to confirm the minimum number for a high score.
(*Note* All can be done in one Test Method)
38 changes: 33 additions & 5 deletions src/Scoreboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,45 @@ 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);
public void addScore(int score) {
if(isHighScore(score))
{
for(int i=0; i<scores.size();i++)
{
if(score > scores.get(i))
{
scores.add(i,score);
if(scores.size() > maxCount)
{
for(int j=maxCount; j<scores.size();j++)
scores.remove(j);
}
return;
}
}
if(scores.size() < maxCount)
scores.add(score);
if(scores.size() > maxCount)
{
for(int k=maxCount; k<scores.size();k++)
scores.remove(k);
}
}
}

public boolean isHighScore(int score) {

return true;
for(int i=0; i<=maxCount-1; i++)
{
if(scores.size() < maxCount)
return true;
if(score >= scores.get(i))
return true;
}
return false;
}

public int getScore(int position) {
Expand Down
87 changes: 83 additions & 4 deletions src/ScoreboardTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,97 @@ 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());
}

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

sb.addScore(50);
sb.addScore(5);

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

public void testMultipleEntries() {
Scoreboard sb = new Scoreboard(10);
boolean inOrder = true;

sb.addScore(5);
sb.addScore(2);
sb.addScore(7);
sb.addScore(9);
sb.addScore(15);

for(int i=0; i<sb.getNumScores()-1; i++)
{
if(sb.getScore(i) < sb.getScore(i+1))
inOrder = false;
}

assertEquals(true, sb.isHighScore(20));
assertEquals(true, inOrder);
assertEquals(5, sb.getNumScores());
}

public void testTooMany() {
Scoreboard sb = new Scoreboard(5);
boolean inOrder = true;

sb.addScore(100);
sb.addScore(45);
sb.addScore(25);
sb.addScore(5);
sb.addScore(65);
sb.addScore(25);
sb.addScore(35);

for(int i=0; i<sb.getNumScores()-1; i++)
{
if(sb.getScore(i) < sb.getScore(i+1))
inOrder = false;
}

assertEquals(true, sb.isHighScore(45));
assertEquals(false, sb.isHighScore(20));
assertEquals(true, inOrder);
assertEquals(5, sb.getNumScores());
}

public void testSecondScoreBeforeFirst()
{
Scoreboard sb = new Scoreboard(10);
boolean inOrder = true;

sb.addScore(5);
sb.addScore(10);

for(int i=sb.getNumScores()-1; i>0; i--)
{
if(sb.getScore(i) > sb.getScore(i-1))
inOrder = false;
}

assertEquals(true, inOrder);
}

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

sb.addScore(5);
sb.addScore(10);

for(int i=0; i<sb.getNumScores()-1; i++)
{
if(sb.getScore(i) < sb.getScore(i+1))
inOrder = false;
}

assertEquals(true, inOrder);
}
}