summaryrefslogtreecommitdiff
path: root/src/test/java/design/model/statistics
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-11-16 02:15:49 -0500
committersowgro <tpoke.ferrari@gmail.com>2025-11-16 02:15:49 -0500
commit6ffc6b4cbd9e0c5ce2dc82a7c77f39b3adf849b6 (patch)
tree456ed56e629a6324e5993b7ce094705c72e0b922 /src/test/java/design/model/statistics
parent64dd072264dd59457cb195f23d17f03720b1cca0 (diff)
parentb5d46c7701716bcb2dd6127aeb97f8fcdb7774fc (diff)
downloaddesignproject-design-6-league-model.tar.gz
designproject-design-6-league-model.tar.bz2
designproject-design-6-league-model.zip
Merge branch 'main' into league-modelleague-model
# Conflicts: # src/main/java/design/controller/userinput/menus/MainMenu.java # src/main/java/design/model/Golfer.java # src/main/java/design/model/ScrambleLeague.java # src/test/java/design/model/GolferTest.java # test.xml
Diffstat (limited to 'src/test/java/design/model/statistics')
-rw-r--r--src/test/java/design/model/statistics/StatisticsTest.java180
1 files changed, 180 insertions, 0 deletions
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);
+ }
+}