diff options
| author | WillemDalton <willemhdalton@gmail.com> | 2025-11-13 17:56:52 -0500 |
|---|---|---|
| committer | WillemDalton <willemhdalton@gmail.com> | 2025-11-13 17:56:52 -0500 |
| commit | cf3db9a7e13f7e919381cd2c8555ee31e3d50cf0 (patch) | |
| tree | e446ad10acdf3032acff662f8bab23f2a0f4b0e1 /src/test/java | |
| parent | ea93075796d8af8e7dee1d2eac7407e7bbe8aea8 (diff) | |
| download | designproject-design-6-cf3db9a7e13f7e919381cd2c8555ee31e3d50cf0.tar.gz designproject-design-6-cf3db9a7e13f7e919381cd2c8555ee31e3d50cf0.tar.bz2 designproject-design-6-cf3db9a7e13f7e919381cd2c8555ee31e3d50cf0.zip | |
completed unit testing for play class
Diffstat (limited to '')
| -rw-r--r-- | src/test/java/design/TestCourseList.java | 86 | ||||
| -rw-r--r-- | src/test/java/design/model/TestPlay.java | 43 |
2 files changed, 43 insertions, 86 deletions
diff --git a/src/test/java/design/TestCourseList.java b/src/test/java/design/TestCourseList.java deleted file mode 100644 index f943852..0000000 --- a/src/test/java/design/TestCourseList.java +++ /dev/null @@ -1,86 +0,0 @@ -// package design; - -// import static org.junit.jupiter.api.Assertions.assertEquals; -// import static org.junit.jupiter.api.Assertions.assertTrue; - -// import org.junit.jupiter.api.Test; -// import design.model.course_search.*; -// import design.model.*; - -// import java.util.List; - -// class TestCourseList { - -// // A dummy Course implementation for testing -// private static class DummyCourse implements ICourse { -// private final String name; -// private final float difficulty; - -// public DummyCourse(String name, float difficulty) { -// this.name = name; -// this.difficulty = difficulty; -// } - -// @Override -// public String getName() { return name; } - -// @Override -// public float getDifficultyRating() { return difficulty; } - -// @Override -// public String getLocation() { return ""; } - -// @Override -// public int getTotalPar() { return 0; } - -// @Override -// public int getHoleCount() { return 0; } - -// @Override -// public List<Hole> getHoles() { return null; } -// } - -// // A simple sorter that sorts courses by difficulty -// private static class SortByDifficultyTest implements CourseSorter { -// @Override -// public void sortCourses(List<ICourse> courses) { -// courses.sort((c1, c2) -> Float.compare(c1.getDifficultyRating(), c2.getDifficultyRating())); -// } -// } - -// @Test -// public void testAddAndRemoveCourses() { -// CourseList courseList = new CourseList(); -// ICourse course1 = new DummyCourse("Course A", 2.0f); -// ICourse course2 = new DummyCourse("Course B", 5.0f); - -// courseList.add(course1); -// courseList.add(course2); - -// assertEquals(2, courseList.getCourses().size(), "Should have 2 courses after adding"); -// assertTrue(courseList.getCourses().contains(course1), "Course A should be in the list"); -// assertTrue(courseList.getCourses().contains(course2), "Course B should be in the list"); - -// courseList.remove(course1); -// assertEquals(1, courseList.getCourses().size(), "Should have 1 course after removal"); -// assertTrue(!courseList.getCourses().contains(course1), "Course A should no longer be in the list"); -// } - -// @Test -// public void testSortCourses() { -// CourseList courseList = new CourseList(); -// courseList.add(new DummyCourse("Course A", 3.0f)); -// courseList.add(new DummyCourse("Course B", 1.0f)); -// courseList.add(new DummyCourse("Course C", 2.0f)); - -// // Set sorting strategy -// courseList.setSorter(new SortByDifficultyTest()); - -// courseList.sort(); - -// List<ICourse> sorted = courseList.getCourses(); -// assertEquals("Course B", sorted.get(0).getName(), "First course should have lowest difficulty"); -// assertEquals("Course C", sorted.get(1).getName(), "Second course should have medium difficulty"); -// assertEquals("Course A", sorted.get(2).getName(), "Last course should have highest difficulty"); -// } -// }
\ No newline at end of file diff --git a/src/test/java/design/model/TestPlay.java b/src/test/java/design/model/TestPlay.java new file mode 100644 index 0000000..c3282bf --- /dev/null +++ b/src/test/java/design/model/TestPlay.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 TestPlay { + @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]); + } +} |
