diff options
| author | sowgro <tpoke.ferrari@gmail.com> | 2025-11-16 02:15:49 -0500 |
|---|---|---|
| committer | sowgro <tpoke.ferrari@gmail.com> | 2025-11-16 02:15:49 -0500 |
| commit | 6ffc6b4cbd9e0c5ce2dc82a7c77f39b3adf849b6 (patch) | |
| tree | 456ed56e629a6324e5993b7ce094705c72e0b922 /src/test/java/design/model | |
| parent | 64dd072264dd59457cb195f23d17f03720b1cca0 (diff) | |
| parent | b5d46c7701716bcb2dd6127aeb97f8fcdb7774fc (diff) | |
| download | designproject-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 '')
| -rw-r--r-- | src/test/java/design/model/ClubTest.java | 29 | ||||
| -rw-r--r-- | src/test/java/design/model/GolferTest.java | 14 | ||||
| -rw-r--r-- | src/test/java/design/model/HoleTest.java | 55 | ||||
| -rw-r--r-- | src/test/java/design/model/InviteTest.java | 38 | ||||
| -rw-r--r-- | src/test/java/design/model/MatchTest.java | 59 | ||||
| -rw-r--r-- | src/test/java/design/model/PlayTest.java | 43 | ||||
| -rw-r--r-- | src/test/java/design/model/RoundTest.java | 50 | ||||
| -rw-r--r-- | src/test/java/design/model/ScrambleLeagueTest.java | 89 | ||||
| -rw-r--r-- | src/test/java/design/model/StrokeLeagueTest.java | 65 | ||||
| -rw-r--r-- | src/test/java/design/model/TeamTest.java | 42 | ||||
| -rw-r--r-- | src/test/java/design/model/coursesearch/CourseListTest.java | 62 | ||||
| -rw-r--r-- | src/test/java/design/model/coursesearch/CurrentSearchQueryTest.java | 27 | ||||
| -rw-r--r-- | src/test/java/design/model/coursesearch/sortStrategyTest.java | 15 | ||||
| -rw-r--r-- | src/test/java/design/model/holeplay/HolePlayContextTest.java | 69 | ||||
| -rw-r--r-- | src/test/java/design/model/statistics/StatisticsTest.java | 180 |
15 files changed, 825 insertions, 12 deletions
diff --git a/src/test/java/design/model/ClubTest.java b/src/test/java/design/model/ClubTest.java index 9ac8130..f47405f 100644 --- a/src/test/java/design/model/ClubTest.java +++ b/src/test/java/design/model/ClubTest.java @@ -1,6 +1,13 @@ package design.model; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -17,13 +24,23 @@ public class ClubTest { { Club testClub = new Club("John Doe", "The Slammer", ClubType.DRIVER); - assertEquals(0, testClub.getId()); + assertEquals(-1, testClub.getId()); assertEquals("John Doe", testClub.getManufacture()); assertEquals("The Slammer", testClub.getNickname()); assertEquals(ClubType.DRIVER, testClub.getClubType()); } @Test + void testPrivateConstructor() throws Exception + { + Constructor<Club> constructor = Club.class.getDeclaredConstructor(int.class, String.class, String.class, ClubType.class); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + Club testClub = constructor.newInstance(0, "John Doe", "The Slammer", ClubType.DRIVER); + assertNotNull(testClub); + } + + @Test void testGetClubType() { Club testClub = new Club("John Doe", "The Slammer", ClubType.DRIVER); @@ -52,10 +69,18 @@ public class ClubTest { } @Test + void testSetId() + { + Club testClub = new Club("John Doe", "The Slammer", ClubType.DRIVER); + testClub.setId(10); + assertThrows(AssertionError.class, () -> testClub.setId(5)); + } + + @Test void testToString() { Club testClub = new Club("John Doe", "The Slammer", ClubType.DRIVER); - String expectedString = "#0 The Slammer - John Doe (DRIVER)"; + String expectedString = "#-1 The Slammer - John Doe (DRIVER)"; assertEquals(expectedString, testClub.toString()); } } diff --git a/src/test/java/design/model/GolferTest.java b/src/test/java/design/model/GolferTest.java index a73997a..98dad20 100644 --- a/src/test/java/design/model/GolferTest.java +++ b/src/test/java/design/model/GolferTest.java @@ -10,6 +10,7 @@ import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import design.model.Club.ClubType; +import design.model.undo.Memento; import java.lang.reflect.Constructor; import java.time.LocalDateTime; @@ -136,4 +137,17 @@ public class GolferTest { String expectedString = "John Doe (@jdoesgolf2)"; assertEquals(expectedString, testGolfer.toString()); } + + @Test + void testMemento() + { + Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321"); + Memento memento = testGolfer.createMemento(); + testGolfer.setFullName("Joe Doe"); + assertEquals("Joe Doe", testGolfer.getFullName()); + testGolfer.restore(memento); + assertEquals("John Doe", testGolfer.getFullName()); + } + + }
\ No newline at end of file diff --git a/src/test/java/design/model/HoleTest.java b/src/test/java/design/model/HoleTest.java new file mode 100644 index 0000000..58aff49 --- /dev/null +++ b/src/test/java/design/model/HoleTest.java @@ -0,0 +1,55 @@ +package design.model; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +/** Tests for the hole model class. + * @author Willem Dalton + */ +@Tag("Model-tier") +public class HoleTest { + + @Test + void testValidEquals() + { + Hole hole1 = new Hole(0, 10); + Hole hole2 = new Hole(0, 10); + assertTrue(hole1.equals(hole2)); + } + + @Test + void testNotAHole() + { + Hole hole1 = new Hole(0, 10); + String notAHole = "ImNotAHole!"; + assertFalse(hole1.equals(notAHole)); + } + + @Test + void testNotEquals() + { + Hole hole1 = new Hole(0, 10); + Hole hole2 = new Hole(10, 999); + assertFalse(hole1.equals(hole2)); + } + + @Test + void testNotEqualPar() + { + Hole hole1 = new Hole(0, 10); + Hole hole2 = new Hole(0, 999); + assertFalse(hole1.equals(hole2)); + } + + @Test + void testNotEqualNumber() + { + Hole hole1 = new Hole(0, 10); + Hole hole2 = new Hole(10, 10); + assertFalse(hole1.equals(hole2)); + } +} + diff --git a/src/test/java/design/model/InviteTest.java b/src/test/java/design/model/InviteTest.java new file mode 100644 index 0000000..29388a2 --- /dev/null +++ b/src/test/java/design/model/InviteTest.java @@ -0,0 +1,38 @@ +package design.model; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import java.util.Date; + +/** Unit Tests for the Invite Class. + * @author Willem Dalton + **/ +@Tag("Model-tier") +public class InviteTest { + @Test + void testConstructor() + { + Golfer testOwner = new Golfer("Jane Doe", "j_doe_rocks", "1234"); + Team testTeam = new Team("A Team", testOwner); + Date testDate = new Date(123456); + Invite testInvite = new Invite(testTeam, testDate); + + assertEquals(testTeam, testInvite.getTeam()); + assertEquals(testDate, testInvite.getSendDate()); + } + + @Test + void testAccept() + { + Golfer testOwner = new Golfer("Jane Doe", "j_doe_rocks", "1234"); + Golfer testInvitee = new Golfer("James Doe", "j_doe_is_cool", "54321"); + Team testTeam = new Team("A Team", testOwner); + Date testDate = new Date(123456); + Invite testInvite = new Invite(testTeam, testDate); + testInvite.accept(testInvitee); + assertEquals(testInvitee, testTeam.getMembers()[0]); + } +} diff --git a/src/test/java/design/model/MatchTest.java b/src/test/java/design/model/MatchTest.java new file mode 100644 index 0000000..9058218 --- /dev/null +++ b/src/test/java/design/model/MatchTest.java @@ -0,0 +1,59 @@ +package design.model; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.Date; +import java.time.LocalDateTime; + +/** Unit Tests for the Match class. + * @author Willem Dalton + **/ +@Tag("Model-tier") +public class MatchTest { + + @Test + void testConstructor() + { + Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester. NY", 9, 30, new ArrayList<Hole>()); + Date testDate = new Date(1234567); + LocalDateTime now = LocalDateTime.now(); + Match testMatch = new Match(testCourse, testDate, now, 9); + assertEquals(testCourse, testMatch.getCourse()); + assertEquals(testDate, testMatch.getDateScheduled()); + assertEquals(now, testMatch.getStart()); + assertEquals(9, testMatch.getHoleCount()); + } + + @Test + void testPrivateConstructor() throws Exception + { + Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester. NY", 9, 30, new ArrayList<Hole>()); + Constructor<Match> constructor = Match.class.getDeclaredConstructor(Course.class, Date.class, LocalDateTime.class, int.class, List.class); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + Match testMatch = constructor.newInstance(testCourse, new Date(1234), LocalDateTime.now(), 0, new ArrayList<>()); + assertNotNull(testMatch); + } + + @Test + void testAddRound() + { + Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester. NY", 9, 30, new ArrayList<Hole>()); + Date testDate = new Date(1234567); + LocalDateTime now = LocalDateTime.now(); + Match testMatch = new Match(testCourse, testDate, now, 9); + Round testRound = new Round(testCourse, now, new Hole(0, 5)); + testMatch.addRound(testRound); + assertEquals(testRound, testMatch.getRounds()[0]); + assertEquals(1, testMatch.getRounds().length); + } +} diff --git a/src/test/java/design/model/PlayTest.java b/src/test/java/design/model/PlayTest.java new file mode 100644 index 0000000..0a27076 --- /dev/null +++ b/src/test/java/design/model/PlayTest.java @@ -0,0 +1,43 @@ +package design.model; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import design.model.Club.ClubType; + +import java.util.ArrayList; + +/** Unit Tests for the Play class. + * @author Willem Dalton + **/ +@Tag("Model-tier") +public class PlayTest { + @Test + void testConstructor() + { + Play testPlay = new Play(0); + assertEquals(0, testPlay.getHoleNumber()); + } + + @Test + void testConstructorNull() + { + Play testPlay2 = new Play(0, null); + assertEquals(0, testPlay2.getHoleNumber()); + assertEquals(0, testPlay2.getSwings().length); + } + + @Test + void testConstructorNotNull() + { + Club newClub = new Club("John Doe Inc", "The Slammer", ClubType.DRIVER); + Swing newSwing = new Swing(100, newClub); + ArrayList<Swing> swings = new ArrayList<Swing>(); + swings.add(newSwing); + Play testPlay3 = new Play(0, swings); + assertEquals(0, testPlay3.getHoleNumber()); + assertEquals(swings.get(0), testPlay3.getSwings()[0]); + } +} diff --git a/src/test/java/design/model/RoundTest.java b/src/test/java/design/model/RoundTest.java index d472f5b..76d8f47 100644 --- a/src/test/java/design/model/RoundTest.java +++ b/src/test/java/design/model/RoundTest.java @@ -1,12 +1,19 @@ package design.model; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; +import design.model.Club.ClubType; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.List; /** Unit Tests for the Round class. * @author Willem Dalton @@ -27,6 +34,18 @@ public class RoundTest { } @Test + void testPrivateConstructor() throws Exception + { + Course testCourse = new Course(0, "Rolling Waves", 62, "Rochester, NY", 9, 20, new ArrayList<Hole>()); + Constructor<Round> constructor = Round.class.getDeclaredConstructor(Course.class, LocalDateTime.class, Hole.class, List.class); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + Round testRound = constructor.newInstance(testCourse, LocalDateTime.now(), new Hole(0, 0), new ArrayList<Play>()); + assertNotNull(testRound); + } + + + @Test void testHolePlay() { Course testCourse = new Course(0, "Rolling Waves", 62, "Rochester, NY", 9, 20, new ArrayList<Hole>()); @@ -36,7 +55,38 @@ public class RoundTest { Play testPlay = new Play(0); testRound.addPlay(testPlay); + assertEquals(1, testRound.getPlays().length); assertEquals(testPlay, testRound.getPlays()[0]); + assertEquals(0, testRound.getTotalSwings()); + + Club newClub = new Club("John Doe Inc", "The Slammer", ClubType.DRIVER); + Swing newSwing = new Swing(200, newClub); + + // try swinging, expect to see another swing added. + testPlay.addSwing(newSwing); + + assertEquals(1, testRound.getTotalSwings()); + assertEquals(200, testRound.getTotalDistance()); + } + + @Test + void testProgressHole() + { + Hole testHole = new Hole(0,3); + Hole nextHole = new Hole(1, 5); + + ArrayList<Hole> testHoles = new ArrayList<Hole>(); + testHoles.add(testHole); + testHoles.add(nextHole); + + Course testCourse = new Course(0, "Rolling Waves", 62, "Rochester, NY", 9, 20, testHoles); + LocalDateTime testTime = LocalDateTime.now(); + Round testRound = new Round(testCourse, testTime, testHole); + + // progress a Hole and check value. + assertEquals(testHole, testRound.getCurrentHole()); + testRound.nextHole(); + assertEquals(nextHole, testRound.getCurrentHole()); } } diff --git a/src/test/java/design/model/ScrambleLeagueTest.java b/src/test/java/design/model/ScrambleLeagueTest.java new file mode 100644 index 0000000..e8fe63c --- /dev/null +++ b/src/test/java/design/model/ScrambleLeagueTest.java @@ -0,0 +1,89 @@ +package design.model; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +/** Tests for the scramble league model class. + * @author Willem Dalton + */ +@Tag("Model-tier") +public class ScrambleLeagueTest { + + @Test + void testConstructor() + { + Date testStart = new Date(1234567); + Date testRegistration = new Date(1234568); + Date testEnd = new Date(12345679); + Golfer testOwner = new Golfer("Bobby", "bobby123", "iloveswen262"); + ScrambleLeague testLeague = new ScrambleLeague("Bobby's Band", testRegistration, testStart, testEnd, testOwner); + assertEquals(-1, testLeague.getId()); + assertEquals("Bobby's Band", testLeague.getName()); + assertEquals(testRegistration, testLeague.getRegistrationDate()); + assertEquals(testStart, testLeague.getStartDate()); + assertEquals(testEnd, testLeague.getEndDate()); + assertEquals(testOwner, testLeague.getOwner()); + } + + @Test + void testPrivateConstructor() throws Exception + { + Golfer testOwner = new Golfer("Bobby", "bobby123", "iloveswen262"); + Constructor<ScrambleLeague> constructor = ScrambleLeague.class.getDeclaredConstructor(int.class, String.class, Date.class, Date.class, Date.class, Golfer.class, List.class, List.class); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + ScrambleLeague testLeague = constructor.newInstance(1, "Bobby's Band", new Date(), new Date(), new Date(), testOwner, new ArrayList<Team>(), new ArrayList<Match>()); + assertNotNull(testLeague); + } + + @Test + void testParticipants() throws Exception + { + Date testStart = new Date(1234567); + Date testRegistration = new Date(1234568); + Date testEnd = new Date(12345679); + Golfer testOwner = new Golfer("Bobby", "bobby123", "iloveswen262"); + ScrambleLeague testLeague = new ScrambleLeague("Bobby's Band", testRegistration, testStart, testEnd, testOwner); + Team testTeam = new Team("The A Team", testOwner); + + // add and remove participant + testLeague.addParticipants(testTeam); + assertEquals(testTeam, testLeague.getParticipants()[0]); + assertEquals(1, testLeague.getParticipants().length); + testLeague.removeParticipants(testTeam); + assertEquals(0, testLeague.getParticipants().length); + } + + @Test + void testLocateTeam() throws Exception + { + Date testStart = new Date(1234567); + Date testRegistration = new Date(1234568); + Date testEnd = new Date(12345679); + Golfer testOwner = new Golfer("Bobby", "bobby123", "iloveswen262"); + ScrambleLeague testLeague = new ScrambleLeague("Bobby's Band", testRegistration, testStart, testEnd, testOwner); + + Team testTeam = new Team("The A Team", testOwner); + Golfer teamMember = new Golfer("Jane Doe", "jane_doe", "weback"); + Golfer nonMember = new Golfer("NAN doe", "nan_doe", "wenotback"); + + // expect a result if member is part of team. expect null if they are not. + testTeam.addMember(teamMember); + testLeague.addParticipants(testTeam); + Team result = testLeague.locateTeam(teamMember); + assertEquals(result, testTeam); + result = testLeague.locateTeam(nonMember); + assertNull(result); + } +} diff --git a/src/test/java/design/model/StrokeLeagueTest.java b/src/test/java/design/model/StrokeLeagueTest.java new file mode 100644 index 0000000..8af7561 --- /dev/null +++ b/src/test/java/design/model/StrokeLeagueTest.java @@ -0,0 +1,65 @@ +package design.model; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +/** Tests for the stroke league model class. + * @author Willem Dalton + */ +@Tag("Model-tier") +public class StrokeLeagueTest { + + @Test + void testConstructor() + { + Date testStart = new Date(1234567); + Date testRegistration = new Date(1234568); + Date testEnd = new Date(12345679); + Golfer testOwner = new Golfer("Bobby", "bobby123", "iloveswen262"); + StrokeLeague testLeague = new StrokeLeague("Bobby's Band", testRegistration, testStart, testEnd, testOwner); + assertEquals(-1, testLeague.getId()); + assertEquals("Bobby's Band", testLeague.getName()); + assertEquals(testRegistration, testLeague.getRegistrationDate()); + assertEquals(testStart, testLeague.getStartDate()); + assertEquals(testEnd, testLeague.getEndDate()); + assertEquals(testOwner, testLeague.getOwner()); + } + + @Test + void testPrivateConstructor() throws Exception + { + Golfer testOwner = new Golfer("Bobby", "bobby123", "iloveswen262"); + Constructor<StrokeLeague> constructor = StrokeLeague.class.getDeclaredConstructor(int.class, String.class, Date.class, Date.class, Date.class, Golfer.class, List.class, List.class); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + StrokeLeague testLeague = constructor.newInstance(1, "Bobby's Band", new Date(), new Date(), new Date(), testOwner, new ArrayList<Golfer>(), new ArrayList<Match>()); + assertNotNull(testLeague); + } + + @Test + void testParticipants() throws Exception + { + Date testStart = new Date(1234567); + Date testRegistration = new Date(1234568); + Date testEnd = new Date(12345679); + Golfer testOwner = new Golfer("Bobby", "bobby123", "iloveswen262"); + StrokeLeague testLeague = new StrokeLeague("Bobby's Band", testRegistration, testStart, testEnd, testOwner); + + // add and remove participant + testLeague.addParticipants(testOwner); + assertEquals(testOwner, testLeague.getParticipants()[0]); + assertEquals(1, testLeague.getParticipants().length); + testLeague.removeParticipants(testOwner); + assertEquals(0, testLeague.getParticipants().length); + } +} diff --git a/src/test/java/design/model/TeamTest.java b/src/test/java/design/model/TeamTest.java new file mode 100644 index 0000000..c81aa1e --- /dev/null +++ b/src/test/java/design/model/TeamTest.java @@ -0,0 +1,42 @@ +package design.model; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +/** Unit Tests for the Team Class. + * @author Willem Dalton + **/ +@Tag("Model-tier") +public class TeamTest { + @Test + void testConstructor() + { + Golfer testGolfer = new Golfer("John Doe", "j_doe_golfs", "ilovegolf123"); + Team testTeam = new Team("A Team", testGolfer); + assertEquals("A Team", testTeam.getName()); + assertEquals(testGolfer, testTeam.getOwner()); + } + + @Test + void testSetName() + { + Golfer testGolfer = new Golfer("John Doe", "j_doe_golfs", "ilovegolf123"); + Team testTeam = new Team("A Team", testGolfer); + testTeam.setName("B Team"); + assertEquals("B Team", testTeam.getName()); + } + + @Test + void testRemoveMember() + { + Golfer testGolfer = new Golfer("John Doe", "j_doe_golfs", "ilovegolf123"); + Golfer newGolfer = new Golfer("Jane Doe", "j_doe_golfs2", "ilovegolf321"); + Team testTeam = new Team("A Team", testGolfer); + testTeam.addMember(newGolfer); + assertEquals(1, testTeam.getMembers().length); + testTeam.removeMember(newGolfer); + assertEquals(0, testTeam.getMembers().length); + } +} diff --git a/src/test/java/design/model/coursesearch/CourseListTest.java b/src/test/java/design/model/coursesearch/CourseListTest.java index 7538ba5..6bc5529 100644 --- a/src/test/java/design/model/coursesearch/CourseListTest.java +++ b/src/test/java/design/model/coursesearch/CourseListTest.java @@ -1,18 +1,19 @@ package design.model.coursesearch; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import java.util.ArrayList; +import design.model.course_search.ICourse; import design.model.course_search.*; import design.model.Course; -/** Unit Tests for the Club class. +/** Unit Tests for the Course List class. * @author Willem Dalton **/ @Tag("Model-tier") @@ -22,6 +23,61 @@ public class CourseListTest { void testConstructor() { CourseList testList = new CourseList(); + assertNotNull(testList); + } + + @Test + void testSetCourses() + { + CourseList testList = new CourseList(); + Course testCourse1 = new Course(0, "Rolling Waves", 10, "Rochester, NY", 0, 0, null); + Course testCourse2 = new Course(1, "Arcadia Hills", 10, "Rochester, NY", 0, 0, null); + ArrayList<ICourse> courses = new ArrayList<ICourse>(); + courses.add(testCourse1); + courses.add(testCourse2); + testList.setCourses(courses); + assertEquals(courses, testList.getCourses()); + } + @Test + void testSort() + { + CourseList testList = new CourseList(); + Course testCourse1 = new Course(0, "Rolling Waves", 10, "Rochester, NY", 0, 0, null); + Course testCourse2 = new Course(1, "Arcadia Hills", 10, "Rochester, NY", 0, 0, null); + ArrayList<ICourse> courses = new ArrayList<ICourse>(); + courses.add(testCourse1); + courses.add(testCourse2); + testList.setCourses(courses); + SortByName sorter = new SortByName(); + testList.setSorter(sorter); + testList.sort(); + assertEquals(testCourse2, testList.getCourses().get(0)); + assertEquals(testCourse1, testList.getCourses().get(1)); + } + + @Test + void testAddRemove() + { + CourseList testList = new CourseList(); + Course testCourse1 = new Course(0, "Rolling Waves", 10, "Rochester, NY", 0, 0, null); + testList.add(testCourse1); + assertEquals(testCourse1, testList.getCourses().get(0)); + assertEquals(1, testList.getCourses().size()); + testList.remove(testCourse1); + assertEquals(0, testList.getCourses().size()); + } + + @Test + void testOverrides() + { + CourseList testList = new CourseList(); + assertEquals("Course List", testList.getName()); + assertEquals("Course List", testList.toString()); + assertEquals(0, testList.getDifficultyRating()); + assertEquals("", testList.getLocation()); + assertEquals(0, testList.getTotalPar()); + assertEquals(0, testList.getHoleCount()); + assertNull(testList.getHoles()); } } diff --git a/src/test/java/design/model/coursesearch/CurrentSearchQueryTest.java b/src/test/java/design/model/coursesearch/CurrentSearchQueryTest.java new file mode 100644 index 0000000..10f3f87 --- /dev/null +++ b/src/test/java/design/model/coursesearch/CurrentSearchQueryTest.java @@ -0,0 +1,27 @@ +package design.model.coursesearch; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import java.util.ArrayList; + +import design.model.course_search.*; +import design.model.Course; + +/** Unit Tests for the Current Search Query Class + * @author Willem Dalton + **/ +@Tag("Model-tier") +public class CurrentSearchQueryTest { + + // @Test + // void testReset() + // { + // CurrentSearchQuery query + // } + + +} diff --git a/src/test/java/design/model/coursesearch/sortStrategyTest.java b/src/test/java/design/model/coursesearch/sortStrategyTest.java index aecbeff..35fa335 100644 --- a/src/test/java/design/model/coursesearch/sortStrategyTest.java +++ b/src/test/java/design/model/coursesearch/sortStrategyTest.java @@ -11,10 +11,11 @@ import java.util.ArrayList; import design.model.course_search.*; import design.model.Course; -/** Unit Tests for the Difficulty Sorter class +/** Unit Tests for the Sorter Strategy classes * @author Willem Dalton **/ -public class sortStrategyTest { +@Tag("Model-tier") +public class SortStrategyTest { Course test1 = new Course(0, "Rolling Waves", 67, "Rochester, NY", 9, 30, null); Course test2 = new Course(1, "Balls in the Rough", 60, "Buffalo, NY", 18, 60, null); @@ -25,7 +26,7 @@ public class sortStrategyTest { void testDifficultySort() { SortByDifficulty sorter = new SortByDifficulty(); - ArrayList<ICourse> courses = new ArrayList(); + ArrayList<ICourse> courses = new ArrayList<ICourse>(); courses.add(test1); courses.add(test2); sorter.sortCourses(courses); @@ -38,7 +39,7 @@ public class sortStrategyTest { void testNameSort() { SortByName sorter = new SortByName(); - ArrayList<ICourse> courses = new ArrayList(); + ArrayList<ICourse> courses = new ArrayList<ICourse>(); courses.add(test1); courses.add(test4); sorter.sortCourses(courses); @@ -51,7 +52,7 @@ public class sortStrategyTest { void testLocationSort() { SortByLocation sorter = new SortByLocation(); - ArrayList<ICourse> courses = new ArrayList(); + ArrayList<ICourse> courses = new ArrayList<ICourse>(); courses.add(test1); courses.add(test4); sorter.sortCourses(courses); @@ -64,7 +65,7 @@ public class sortStrategyTest { void testParSort() { SortByPar sorter = new SortByPar(); - ArrayList<ICourse> courses = new ArrayList(); + ArrayList<ICourse> courses = new ArrayList<ICourse>(); courses.add(test1); courses.add(test4); sorter.sortCourses(courses); @@ -77,7 +78,7 @@ public class sortStrategyTest { void testHoleSort() { SortByHoles sorter = new SortByHoles(); - ArrayList<ICourse> courses = new ArrayList(); + ArrayList<ICourse> courses = new ArrayList<ICourse>(); courses.add(test1); courses.add(test4); sorter.sortCourses(courses); 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); + } +} |
