summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/design/model/InviteTest.java1
-rw-r--r--src/test/java/design/model/holeplay/HolePlayContextTest.java69
-rw-r--r--src/test/java/design/model/statistics/StatisticsTest.java180
-rw-r--r--src/test/java/design/persistence/CSVMasterDatabaseTest.java2
4 files changed, 251 insertions, 1 deletions
diff --git a/src/test/java/design/model/InviteTest.java b/src/test/java/design/model/InviteTest.java
index a71271d..29388a2 100644
--- a/src/test/java/design/model/InviteTest.java
+++ b/src/test/java/design/model/InviteTest.java
@@ -10,6 +10,7 @@ import java.util.Date;
/** Unit Tests for the Invite Class.
* @author Willem Dalton
**/
+@Tag("Model-tier")
public class InviteTest {
@Test
void testConstructor()
diff --git a/src/test/java/design/model/holeplay/HolePlayContextTest.java b/src/test/java/design/model/holeplay/HolePlayContextTest.java
index de0f1e9..c2ca619 100644
--- a/src/test/java/design/model/holeplay/HolePlayContextTest.java
+++ b/src/test/java/design/model/holeplay/HolePlayContextTest.java
@@ -1,5 +1,74 @@
package design.model.holeplay;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+import java.util.Date;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+
+import design.model.Golfer;
+import design.model.Round;
+import design.model.Club.ClubType;
+import design.persistence.PersonalDatabase;
+import design.model.Course;
+import design.model.Hole;
+import design.model.Club;
+
+/** Unit Tests for the HolePlayContext Class.
+ * @author Willem Dalton
+ **/
+@Tag("Model-tier")
public class HolePlayContextTest {
+ @Test
+ void testConstructor()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback");
+ Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>());
+ Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10));
+ HolePlayContext testContext = new HolePlayContext(testGolfer, testRound, PersonalDatabase.instance());
+ assertEquals(testGolfer, testContext.getGolfer());
+ assertEquals(testRound, testContext.getRound());
+ }
+
+ @Test
+ void testPlay()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback");
+ Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>());
+ Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10));
+ HolePlayContext testContext = new HolePlayContext(testGolfer, testRound, PersonalDatabase.instance());
+ testContext.beginNewPlay(0);
+ Club testClub = new Club("John Doe Inc", "The Slammer", ClubType.DRIVER);
+ testContext.addSwing(testClub, 100);
+ assertEquals(1, testContext.getCurrentPlay().getSwingCount());
+ assertEquals(100, testContext.getCurrentPlay().getDistance());
+ }
+
+ @Test
+ void testPlayNull()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback");
+ Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>());
+ Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10));
+ HolePlayContext testContext = new HolePlayContext(testGolfer, testRound, PersonalDatabase.instance());
+ testContext.beginNewPlay(0);
+ Club testClub = new Club("John Doe Inc", "The Slammer", ClubType.DRIVER);
+ testContext.addSwing(testClub, null);
+ assertEquals(1, testContext.getCurrentPlay().getSwingCount());
+ assertEquals(0, testContext.getCurrentPlay().getDistance());
+ }
+
+ // @Test
+ // void testHolePlay()
+ // {
+ // Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback");
+ // Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>());
+ // Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10));
+ // HolePlayContext testContext = new HolePlayContext(testGolfer, testRound, PersonalDatabase.instance());
+ // testContext.startHole();
+ // }
} \ No newline at end of file
diff --git a/src/test/java/design/model/statistics/StatisticsTest.java b/src/test/java/design/model/statistics/StatisticsTest.java
new file mode 100644
index 0000000..e68796a
--- /dev/null
+++ b/src/test/java/design/model/statistics/StatisticsTest.java
@@ -0,0 +1,180 @@
+package design.model.statistics;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import design.model.Course;
+import design.model.Golfer;
+import design.model.Hole;
+import design.model.Round;
+import design.model.Club.ClubType;
+import design.model.Play;
+import design.model.Club;
+import design.model.Swing;
+
+/** Unit Tests for the Statistics Subsystem
+ * @author Willem Dalton
+ **/
+@Tag("Model-tier")
+public class StatisticsTest {
+
+ /* base stats wrapper for testing purposes */
+ private static class StubStatistics implements Statistics {
+ private final Golfer golfer;
+
+ public StubStatistics(Golfer golfer) {
+ this.golfer = golfer;
+ }
+
+ @Override
+ public Round[] getRounds() {
+ return golfer.getRounds();
+ }
+
+ @Override
+ public int get_score() {
+ return Arrays.stream(getRounds())
+ .mapToInt(Round::getTotalSwings)
+ .sum();
+ }
+
+ @Override
+ public double get_distance() {
+ return Arrays.stream(getRounds())
+ .mapToDouble(Round::getTotalDistance)
+ .sum();
+ }
+ }
+
+ @Test
+ void testLifeTime()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback");
+ Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>());
+ Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10));
+ Swing testSwing = new Swing(100, new Club("John Doe Inc", "The Slammer", ClubType.DRIVER));
+ LifetimeStats stats = new LifetimeStats(testGolfer);
+
+ assertNotNull(stats);
+ assertEquals(0, stats.get_score());
+ assertEquals(0, stats.get_distance());
+
+ ArrayList<Swing> testSwings = new ArrayList<Swing>();
+ testSwings.add(testSwing);
+ Play testPlay = new Play(0, testSwings);
+ testRound.addPlay(testPlay);
+ testGolfer.addRound(testRound);
+
+ assertEquals(1, stats.get_score());
+ assertEquals(100, stats.get_distance());
+ }
+
+ @Test
+ void testYearly()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback");
+ Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>());
+ Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10));
+ Swing testSwing = new Swing(100, new Club("John Doe Inc", "The Slammer", ClubType.DRIVER));
+
+ Statistics wrapper = new StubStatistics(testGolfer);
+ YearlyStats stats = new YearlyStats(wrapper, 2025);
+
+ assertNotNull(stats);
+ assertEquals(0, stats.get_score());
+ assertEquals(0, stats.get_distance());
+
+ ArrayList<Swing> testSwings = new ArrayList<Swing>();
+ testSwings.add(testSwing);
+ Play testPlay = new Play(0, testSwings);
+ testRound.addPlay(testPlay);
+ testGolfer.addRound(testRound);
+
+ assertEquals(1, stats.get_score());
+ assertEquals(100, stats.get_distance());
+ }
+
+ @Test
+ void testCourse()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback");
+ Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>());
+ Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10));
+ Swing testSwing = new Swing(100, new Club("John Doe Inc", "The Slammer", ClubType.DRIVER));
+
+ Statistics wrapper = new StubStatistics(testGolfer);
+ CourseStats stats = new CourseStats(wrapper, testCourse);
+
+ assertNotNull(stats);
+ assertEquals(0, stats.get_score());
+ assertEquals(0, stats.get_distance());
+
+ ArrayList<Swing> testSwings = new ArrayList<Swing>();
+ testSwings.add(testSwing);
+ Play testPlay = new Play(0, testSwings);
+ testRound.addPlay(testPlay);
+ testGolfer.addRound(testRound);
+
+ assertEquals(1, stats.get_score());
+ assertEquals(100, stats.get_distance());
+ }
+
+ @Test
+ void testRound()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback");
+ Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>());
+ Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10));
+ Swing testSwing = new Swing(100, new Club("John Doe Inc", "The Slammer", ClubType.DRIVER));
+
+ Statistics wrapper = new StubStatistics(testGolfer);
+ RoundStats stats = new RoundStats(wrapper, testRound);
+
+ assertNotNull(stats);
+ assertEquals(0, stats.get_score());
+ assertEquals(0, stats.get_distance());
+
+ ArrayList<Swing> testSwings = new ArrayList<Swing>();
+ testSwings.add(testSwing);
+ Play testPlay = new Play(0, testSwings);
+ testRound.addPlay(testPlay);
+ testGolfer.addRound(testRound);
+
+ assertEquals(1, stats.get_score());
+ assertEquals(100, stats.get_distance());
+ }
+
+ @Test
+ void testHole()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback");
+ Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>());
+ Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10));
+ Swing testSwing = new Swing(100, new Club("John Doe Inc", "The Slammer", ClubType.DRIVER));
+ Hole testHole = new Hole(0, 10);
+
+ Statistics wrapper = new StubStatistics(testGolfer);
+ HoleStats stats = new HoleStats(wrapper, testHole);
+
+ assertNotNull(stats);
+ assertEquals(0, stats.get_score());
+ assertEquals(0, stats.get_distance());
+
+ ArrayList<Swing> testSwings = new ArrayList<Swing>();
+ testSwings.add(testSwing);
+ Play testPlay = new Play(0, testSwings);
+ testRound.addPlay(testPlay);
+ testGolfer.addRound(testRound);
+
+ assertEquals(1, stats.get_score());
+ assertEquals(100, stats.get_distance());
+ assertEquals(0, stats.getRounds().length);
+ }
+}
diff --git a/src/test/java/design/persistence/CSVMasterDatabaseTest.java b/src/test/java/design/persistence/CSVMasterDatabaseTest.java
index 7ecf59f..4c78800 100644
--- a/src/test/java/design/persistence/CSVMasterDatabaseTest.java
+++ b/src/test/java/design/persistence/CSVMasterDatabaseTest.java
@@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test;
/** Unit Tests for the CSV Master Database Singleton class.
* @author Willem Dalton
**/
-@Tag("Model-tier")
+@Tag("Persistence-tier")
public class CSVMasterDatabaseTest {
@Test