diff options
| author | sowgro <tpoke.ferrari@gmail.com> | 2025-11-16 02:22:34 -0500 |
|---|---|---|
| committer | sowgro <tpoke.ferrari@gmail.com> | 2025-11-16 02:22:34 -0500 |
| commit | 2001073e2353e4e9824473cf712102cec3af6a11 (patch) | |
| tree | 091e0ba975be4d9b13c8323d49862ac87e22b84d /src/test/java/design/model/statistics/StatisticsTest.java | |
| parent | 5bb349e46fbe9c63ad15379703e0d1371bae0081 (diff) | |
| parent | a667071453840878eb9dba07c5fd96559f79ca57 (diff) | |
| download | designproject-design-6-2001073e2353e4e9824473cf712102cec3af6a11.tar.gz designproject-design-6-2001073e2353e4e9824473cf712102cec3af6a11.tar.bz2 designproject-design-6-2001073e2353e4e9824473cf712102cec3af6a11.zip | |
Merge branch 'main' into league-play-refactoring
# Conflicts:
# src/main/java/design/persistence/JSONLeagueDatabase.java
# src/main/java/design/persistence/JSONPersonalDatabase.java
# src/main/java/design/persistence/Serializers.java
Diffstat (limited to '')
| -rw-r--r-- | src/test/java/design/model/statistics/StatisticsTest.java | 180 |
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); + } +} |
