From daba6a383d8ba385b4d7bcf766e02687a3b603cb Mon Sep 17 00:00:00 2001 From: Jacob Fritz Date: Thu, 19 Feb 2015 16:36:04 -0500 Subject: [PATCH] Submission for the Scoreboard lab --- FritzAnswers.md | 7 ++++ src/Scoreboard.java | 38 +++++++++++++++--- src/ScoreboardTest.java | 87 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 123 insertions(+), 9 deletions(-) create mode 100644 FritzAnswers.md diff --git a/FritzAnswers.md b/FritzAnswers.md new file mode 100644 index 0000000..f8ef9a9 --- /dev/null +++ b/FritzAnswers.md @@ -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) \ No newline at end of file diff --git a/src/Scoreboard.java b/src/Scoreboard.java index f0b8d0a..cfa7f18 100644 --- a/src/Scoreboard.java +++ b/src/Scoreboard.java @@ -5,17 +5,45 @@ public class Scoreboard { private int maxCount; public Scoreboard(int maxScoreCount) { - scores = new ArrayList<>(maxScoreCount); + scores = new ArrayList(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.get(i)) + { + scores.add(i,score); + if(scores.size() > maxCount) + { + for(int j=maxCount; j maxCount) + { + for(int k=maxCount; k= scores.get(i)) + return true; + } + return false; } public int getScore(int position) { diff --git a/src/ScoreboardTest.java b/src/ScoreboardTest.java index 697a6b4..9d0e07a 100644 --- a/src/ScoreboardTest.java +++ b/src/ScoreboardTest.java @@ -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()); } @@ -12,10 +12,89 @@ public void testEmptyScoreboard() { 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; i0; 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