summaryrefslogtreecommitdiff
path: root/src/test/java/design
diff options
context:
space:
mode:
authorWillemDalton <willemhdalton@gmail.com>2025-10-02 08:55:33 -0400
committerWillemDalton <willemhdalton@gmail.com>2025-10-02 08:55:33 -0400
commite218e35f333f8a30d213c7d3eebeb6f5f6bbcea3 (patch)
treeafc16118dd13e4ab089a85df90be11a80b157fd2 /src/test/java/design
parentc03d30761e74e27815e6b7639f9ff4ec4e5c185a (diff)
downloaddesignproject-design-6-e218e35f333f8a30d213c7d3eebeb6f5f6bbcea3.tar.gz
designproject-design-6-e218e35f333f8a30d213c7d3eebeb6f5f6bbcea3.tar.bz2
designproject-design-6-e218e35f333f8a30d213c7d3eebeb6f5f6bbcea3.zip
more progress on the strategy, unit testing
Diffstat (limited to '')
-rw-r--r--src/test/java/design/TestCourseList.java86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/test/java/design/TestCourseList.java b/src/test/java/design/TestCourseList.java
new file mode 100644
index 0000000..e18b9ab
--- /dev/null
+++ b/src/test/java/design/TestCourseList.java
@@ -0,0 +1,86 @@
+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