diff --git a/docs/DeveloperGuide.adoc b/docs/DeveloperGuide.adoc index 0f87ed8fe..e3f021a1b 100644 --- a/docs/DeveloperGuide.adoc +++ b/docs/DeveloperGuide.adoc @@ -258,9 +258,32 @@ Classes used by multiple components are in the `planmysem.commons` package. This section describes some noteworthy details on how certain features are implemented. -=== Initializing of the Planner and it's Semesters +=== Initialization of the Planner and it's Semester -==== Future Implementation +The Planner and it's Semester has to be initialized for _PlanMySem_ to work as all other features of _PlanMySem_ would +interact with this Semester object. + +==== Current Implementation + +Upon launching _PlanMySem_, the initialization of the Planner and it's Semester would be implemented via two steps: + +1. Automatically generate the academic calendar from the current date. +2. Setup current Semester from the academic calendar. + +//The academic calendar is dynamically generated by invoking the function +//based on the current date retrieved from the system clock. +//TBC +==== Design Considerations + +===== Aspect: Generation of academic calendar + +* *Alternative 1 (current choice):* Generate academic calendar by performing calculations from the current date. +** Pros: Generation of academic calendar is dynamic and will work for future dates. +** Cons: Computationally expensive as many operations have to be performed. + +* *Alternative 2:* Retrieve academic calendar from a pre-generated file. +** Pros: Generation of academic calendar is efficient and not prone to calculation errors. +** Cons: Requires the pre-generated file which may be accidentally edited or deleted by the user. === Reinventing the Parser / Command Format and Structure diff --git a/src/planmysem/data/Planner.java b/src/planmysem/data/Planner.java index 0c3dd43fa..4209037d0 100644 --- a/src/planmysem/data/Planner.java +++ b/src/planmysem/data/Planner.java @@ -1,17 +1,11 @@ package planmysem.data; -import java.time.DayOfWeek; import java.time.LocalDate; import java.time.LocalTime; -import java.time.temporal.TemporalAdjusters; -import java.time.temporal.WeekFields; import java.util.HashMap; -import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; -import java.util.stream.Collectors; import javafx.util.Pair; import planmysem.data.exception.IllegalValueException; @@ -32,7 +26,7 @@ public class Planner { * Creates an empty planner. */ public Planner() { - semester = generateSemester(LocalDate.now()); + semester = Semester.generateSemester(LocalDate.now()); } /** @@ -44,246 +38,6 @@ public Planner(Semester semester) { this.semester = new Semester(semester); } - /** - * Generates current semester based on current date. - * As long as the current date falls within a semester, the generated semester is always the same. - * - * @param currentDate the current date when the program is run - * @return the current semester object - */ - public static Semester generateSemester(LocalDate currentDate) { - String acadSem; - String acadYear; - String[] semesterDetails; - int noOfWeeks; - LocalDate startDate; - LocalDate endDate; - List datesList; - HashMap acadCalMap; - HashMap days = new HashMap<>(); - Set recessDays = new HashSet<>(); - Set readingDays = new HashSet<>(); - Set normalDays = new HashSet<>(); - Set examDays = new HashSet<>(); - - acadCalMap = generateAcadCalMap(currentDate); - semesterDetails = getSemesterDetails(currentDate, acadCalMap); - acadSem = semesterDetails[1]; - acadYear = semesterDetails[2]; - noOfWeeks = Integer.parseInt(semesterDetails[3]); - startDate = LocalDate.parse(semesterDetails[4]); - endDate = LocalDate.parse(semesterDetails[5]); - - // Initialise HashMap and Sets of all days in current semester - datesList = startDate.datesUntil(endDate).collect(Collectors.toList()); - for (LocalDate date: datesList) { - int weekOfYear = date.get(WeekFields.ISO.weekOfWeekBasedYear()); - String weekType = acadCalMap.get(weekOfYear).split("_")[0]; - days.put(date, new Day(date.getDayOfWeek(), weekType)); - switch (weekType) { - case "Recess Week": - recessDays.add(date); - break; - case "Reading Week": - readingDays.add(date); - break; - case "Examination Week": - examDays.add(date); - break; - default: - normalDays.add(date); - break; - } - } - - return new Semester(acadSem, acadYear, days, startDate, endDate, noOfWeeks, - recessDays, readingDays, normalDays, examDays); - } - - /** - * Generates academic calendar for a given date. - * - * @param date used to determine academic year - * @return details of academic calendar - */ - private static HashMap generateAcadCalMap(LocalDate date) { - HashMap acadCalMap = new HashMap<>(); - LocalDate semOneStartDate = date; - LocalDate semTwoEndDate = date; - int currentMonth = date.getMonthValue(); - int currentYear = date.getYear(); - int semOneStartWeek; - int semTwoStartWeek; - int semTwoEndWeek; - int acadWeekNo; - int noOfWeeksInYear; - int vacationWeekNo; - - if (currentMonth < 8) { - // Academic Year beginning from August of previous year - semOneStartDate = semOneStartDate.withYear(currentYear - 1).withMonth(8) - .with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY)); - semOneStartWeek = semOneStartDate.get(WeekFields.ISO.weekOfWeekBasedYear()); - semTwoEndDate = semTwoEndDate.withYear(currentYear).withMonth(8) - .with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY)).minusDays(1); - semTwoEndWeek = semTwoEndDate.get(WeekFields.ISO.weekOfWeekBasedYear()); - } else { - // Academic Year beginning from August of current year - semOneStartDate = semOneStartDate.withYear(currentYear).withMonth(8) - .with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY)); - semOneStartWeek = semOneStartDate.get(WeekFields.ISO.weekOfWeekBasedYear()); - semTwoEndDate = semTwoEndDate.withYear(currentYear + 1).withMonth(8) - .with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY)).minusDays(1); - semTwoEndWeek = semTwoEndDate.get(WeekFields.ISO.weekOfWeekBasedYear()); - } - - // Sem 1 - Orientation Week - acadCalMap.put(semOneStartWeek, "Orientation Week_Sem 1"); - - // Sem 1 - Week 1 to 6 - acadWeekNo = 1; - for (int i = semOneStartWeek + 1; i < semOneStartWeek + 7; i++) { - acadCalMap.put(i, "Week " + acadWeekNo + "_Sem 1"); - acadWeekNo++; - } - - // Sem 1 - Recess Week - acadCalMap.put(semOneStartWeek + 7, "Recess Week_Sem 1"); - - // Sem 1 - Week 7 to 13 - acadWeekNo = 7; - for (int i = semOneStartWeek + 8; i < semOneStartWeek + 15; i++) { - acadCalMap.put(i, "Week " + acadWeekNo + "_Sem 1"); - acadWeekNo++; - } - - // Sem 1 - Reading & Examination Weeks - acadCalMap.put(semOneStartWeek + 15, "Reading Week_Sem 1"); - acadCalMap.put(semOneStartWeek + 16, "Examination Week_Sem 1"); - acadCalMap.put(semOneStartWeek + 17, "Examination Week_Sem 1"); - - // Sem 1 - Vacation - noOfWeeksInYear = (int) semOneStartDate.range(WeekFields.ISO.weekOfWeekBasedYear()).getMaximum(); - vacationWeekNo = semOneStartWeek + 18; - semTwoStartWeek = 1; - for (int i = 0; i < 5; i++) { - if ((vacationWeekNo + i) <= noOfWeeksInYear) { - acadCalMap.put(vacationWeekNo + i, "Vacation_Sem 1"); - } else { - acadCalMap.put(semTwoStartWeek++, "Vacation_Sem 1"); - } - } - - // Sem 2 - Week 1 to 6 - acadWeekNo = 1; - for (int i = semTwoStartWeek; i < semTwoStartWeek + 6; i++) { - acadCalMap.put(i, "Week " + acadWeekNo + "_Sem 2"); - acadWeekNo++; - } - - // Sem 2 - Recess Week - acadCalMap.put(semTwoStartWeek + 6, "Recess Week_Sem 2"); - - // Sem 2 - Week 7 to 13 - acadWeekNo = 7; - for (int i = semTwoStartWeek + 7; i < semTwoStartWeek + 14; i++) { - acadCalMap.put(i, "Week " + acadWeekNo + "_Sem 2"); - acadWeekNo++; - } - - // Sem 2 - Reading & Examination Weeks - acadCalMap.put(semTwoStartWeek + 14, "Reading Week_Sem 2"); - acadCalMap.put(semTwoStartWeek + 15, "Examination Week_Sem 2"); - acadCalMap.put(semTwoStartWeek + 16, "Examination Week_Sem 2"); - - // Sem 2 - Vacation - vacationWeekNo = semTwoStartWeek + 17; - while (vacationWeekNo <= semTwoEndWeek) { - acadCalMap.put(vacationWeekNo++, "Vacation_Sem 2"); - } - - return acadCalMap; - } - - /** - * Initialises current semester's details. - * - * @param date the current date when the program is run - * @param acadCalMap used to determine current academic week - * @return an array of Strings of the current semester's details - */ - private static String[] getSemesterDetails(LocalDate date, HashMap acadCalMap) { - String acadWeek; - String acadSem; - String acadYear = null; - String noOfWeeks = null; - String[] acadWeekDetails; - LocalDate startDate = date; - LocalDate endDate = date; - int currentYear = date.getYear(); - int currentWeekOfYear = date.get(WeekFields.ISO.weekOfWeekBasedYear()); - - // Initialise week numbers for certain weeks. - int firstWeekSemOne = 0; - int firstWeekSemOneHol = 0; - int lastWeekSemOneHol = 0; - int firstWeekSemTwo = 0; - int firstWeekSemTwoHol = 0; - for (Map.Entry entry: acadCalMap.entrySet()) { - if ("Orientation Week_Sem 1".equals(entry.getValue())) { - firstWeekSemOne = entry.getKey(); - } else if ("Examination Week_Sem 1".equals(entry.getValue())) { - firstWeekSemOneHol = entry.getKey() + 1; - } else if ("Week 1_Sem 2".equals(entry.getValue())) { - lastWeekSemOneHol = entry.getKey() - 1; - firstWeekSemTwo = entry.getKey(); - } else if ("Examination Week_Sem 2".equals(entry.getValue())) { - firstWeekSemTwoHol = entry.getKey() + 1; - } - } - - // Set semester details. - acadWeekDetails = acadCalMap.get(currentWeekOfYear).split("_"); - acadWeek = acadWeekDetails[0]; - acadSem = acadWeekDetails[1]; - if ("Vacation".equals(acadWeek) && "Sem 1".equals(acadSem)) { - noOfWeeks = "5"; - if (currentWeekOfYear < 4) { - acadYear = "AY" + (currentYear - 1) + "/" + currentYear; - startDate = startDate.withYear(currentYear - 1); - } else { - acadYear = "AY" + currentYear + "/" + (currentYear + 1); - endDate = endDate.withYear(currentYear + 1); - } - startDate = startDate.with(WeekFields.ISO.weekOfWeekBasedYear(), firstWeekSemOneHol); - startDate = startDate.with(WeekFields.ISO.dayOfWeek(), 1); - endDate = endDate.with(WeekFields.ISO.weekOfWeekBasedYear(), lastWeekSemOneHol); - endDate = endDate.with(WeekFields.ISO.dayOfWeek(), 7); - } else if ("Vacation".equals(acadWeek) && "Sem 2".equals(acadSem)) { - noOfWeeks = "12"; - acadYear = "AY" + (currentYear - 1) + "/" + currentYear; - startDate = startDate.with(WeekFields.ISO.weekOfWeekBasedYear(), firstWeekSemTwoHol); - startDate = startDate.with(WeekFields.ISO.dayOfWeek(), 1); - endDate = endDate.with(WeekFields.ISO.weekOfWeekBasedYear(), firstWeekSemTwoHol + 11); - endDate = endDate.with(WeekFields.ISO.dayOfWeek(), 7); - } else if ("Sem 1".equals(acadSem)) { - noOfWeeks = "18"; - acadYear = "AY" + currentYear + "/" + (currentYear + 1); - startDate = startDate.with(WeekFields.ISO.weekOfWeekBasedYear(), firstWeekSemOne); - startDate = startDate.with(WeekFields.ISO.dayOfWeek(), 1); - endDate = endDate.with(WeekFields.ISO.weekOfWeekBasedYear(), firstWeekSemOne + 17); - endDate = endDate.with(WeekFields.ISO.dayOfWeek(), 7); - } else if ("Sem 2".equals(acadSem)) { - noOfWeeks = "17"; - acadYear = "AY" + (currentYear - 1) + "/" + currentYear; - startDate = startDate.with(WeekFields.ISO.weekOfWeekBasedYear(), firstWeekSemTwo); - startDate = startDate.with(WeekFields.ISO.dayOfWeek(), 1); - endDate = endDate.with(WeekFields.ISO.weekOfWeekBasedYear(), firstWeekSemTwo + 16); - endDate = endDate.with(WeekFields.ISO.dayOfWeek(), 7); - } - return new String[] {acadWeek, acadSem, acadYear, noOfWeeks, startDate.toString(), endDate.toString()}; - } - /** * Adds a day to the Planner. * diff --git a/src/planmysem/data/semester/Semester.java b/src/planmysem/data/semester/Semester.java index 004e48543..f9502177a 100644 --- a/src/planmysem/data/semester/Semester.java +++ b/src/planmysem/data/semester/Semester.java @@ -1,14 +1,19 @@ package planmysem.data.semester; +import java.time.DayOfWeek; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.temporal.TemporalAdjusters; +import java.time.temporal.WeekFields; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.TreeMap; +import java.util.stream.Collectors; import planmysem.data.exception.DuplicateDataException; import planmysem.data.exception.IllegalValueException; @@ -82,6 +87,246 @@ public Semester(Semester source) { this.examDays.addAll(source.examDays); } + /** + * Generates current semester based on current date. + * As long as the current date falls within a semester, the generated semester is always the same. + * + * @param currentDate the current date when the program is run + * @return the current semester object + */ + public static Semester generateSemester(LocalDate currentDate) { + String acadSem; + String acadYear; + String[] semesterDetails; + int noOfWeeks; + LocalDate startDate; + LocalDate endDate; + List datesList; + HashMap acadCalMap; + HashMap days = new HashMap<>(); + Set recessDays = new HashSet<>(); + Set readingDays = new HashSet<>(); + Set normalDays = new HashSet<>(); + Set examDays = new HashSet<>(); + + acadCalMap = generateAcadCalMap(currentDate); + semesterDetails = getSemesterDetails(currentDate, acadCalMap); + acadSem = semesterDetails[1]; + acadYear = semesterDetails[2]; + noOfWeeks = Integer.parseInt(semesterDetails[3]); + startDate = LocalDate.parse(semesterDetails[4]); + endDate = LocalDate.parse(semesterDetails[5]); + + // Initialise HashMap and Sets of all days in current semester + datesList = startDate.datesUntil(endDate).collect(Collectors.toList()); + for (LocalDate date: datesList) { + int weekOfYear = date.get(WeekFields.ISO.weekOfWeekBasedYear()); + String weekType = acadCalMap.get(weekOfYear).split("_")[0]; + days.put(date, new Day(date.getDayOfWeek(), weekType)); + switch (weekType) { + case "Recess Week": + recessDays.add(date); + break; + case "Reading Week": + readingDays.add(date); + break; + case "Examination Week": + examDays.add(date); + break; + default: + normalDays.add(date); + break; + } + } + + return new Semester(acadSem, acadYear, days, startDate, endDate, noOfWeeks, + recessDays, readingDays, normalDays, examDays); + } + + /** + * Generates academic calendar for a given date. + * + * @param date used to determine academic year + * @return details of academic calendar + */ + private static HashMap generateAcadCalMap(LocalDate date) { + HashMap acadCalMap = new HashMap<>(); + LocalDate semOneStartDate = date; + LocalDate semTwoEndDate = date; + int currentMonth = date.getMonthValue(); + int currentYear = date.getYear(); + int semOneStartWeek; + int semTwoStartWeek; + int semTwoEndWeek; + int acadWeekNo; + int noOfWeeksInYear; + int vacationWeekNo; + + if (currentMonth < 8) { + // Academic Year beginning from August of previous year + semOneStartDate = semOneStartDate.withYear(currentYear - 1).withMonth(8) + .with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY)); + semOneStartWeek = semOneStartDate.get(WeekFields.ISO.weekOfWeekBasedYear()); + semTwoEndDate = semTwoEndDate.withYear(currentYear).withMonth(8) + .with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY)).minusDays(1); + semTwoEndWeek = semTwoEndDate.get(WeekFields.ISO.weekOfWeekBasedYear()); + } else { + // Academic Year beginning from August of current year + semOneStartDate = semOneStartDate.withYear(currentYear).withMonth(8) + .with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY)); + semOneStartWeek = semOneStartDate.get(WeekFields.ISO.weekOfWeekBasedYear()); + semTwoEndDate = semTwoEndDate.withYear(currentYear + 1).withMonth(8) + .with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY)).minusDays(1); + semTwoEndWeek = semTwoEndDate.get(WeekFields.ISO.weekOfWeekBasedYear()); + } + + // Sem 1 - Orientation Week + acadCalMap.put(semOneStartWeek, "Orientation Week_Sem 1"); + + // Sem 1 - Week 1 to 6 + acadWeekNo = 1; + for (int i = semOneStartWeek + 1; i < semOneStartWeek + 7; i++) { + acadCalMap.put(i, "Week " + acadWeekNo + "_Sem 1"); + acadWeekNo++; + } + + // Sem 1 - Recess Week + acadCalMap.put(semOneStartWeek + 7, "Recess Week_Sem 1"); + + // Sem 1 - Week 7 to 13 + acadWeekNo = 7; + for (int i = semOneStartWeek + 8; i < semOneStartWeek + 15; i++) { + acadCalMap.put(i, "Week " + acadWeekNo + "_Sem 1"); + acadWeekNo++; + } + + // Sem 1 - Reading & Examination Weeks + acadCalMap.put(semOneStartWeek + 15, "Reading Week_Sem 1"); + acadCalMap.put(semOneStartWeek + 16, "Examination Week_Sem 1"); + acadCalMap.put(semOneStartWeek + 17, "Examination Week_Sem 1"); + + // Sem 1 - Vacation + noOfWeeksInYear = (int) semOneStartDate.range(WeekFields.ISO.weekOfWeekBasedYear()).getMaximum(); + vacationWeekNo = semOneStartWeek + 18; + semTwoStartWeek = 1; + for (int i = 0; i < 5; i++) { + if ((vacationWeekNo + i) <= noOfWeeksInYear) { + acadCalMap.put(vacationWeekNo + i, "Vacation_Sem 1"); + } else { + acadCalMap.put(semTwoStartWeek++, "Vacation_Sem 1"); + } + } + + // Sem 2 - Week 1 to 6 + acadWeekNo = 1; + for (int i = semTwoStartWeek; i < semTwoStartWeek + 6; i++) { + acadCalMap.put(i, "Week " + acadWeekNo + "_Sem 2"); + acadWeekNo++; + } + + // Sem 2 - Recess Week + acadCalMap.put(semTwoStartWeek + 6, "Recess Week_Sem 2"); + + // Sem 2 - Week 7 to 13 + acadWeekNo = 7; + for (int i = semTwoStartWeek + 7; i < semTwoStartWeek + 14; i++) { + acadCalMap.put(i, "Week " + acadWeekNo + "_Sem 2"); + acadWeekNo++; + } + + // Sem 2 - Reading & Examination Weeks + acadCalMap.put(semTwoStartWeek + 14, "Reading Week_Sem 2"); + acadCalMap.put(semTwoStartWeek + 15, "Examination Week_Sem 2"); + acadCalMap.put(semTwoStartWeek + 16, "Examination Week_Sem 2"); + + // Sem 2 - Vacation + vacationWeekNo = semTwoStartWeek + 17; + while (vacationWeekNo <= semTwoEndWeek) { + acadCalMap.put(vacationWeekNo++, "Vacation_Sem 2"); + } + + return acadCalMap; + } + + /** + * Initialises current semester's details. + * + * @param date the current date when the program is run + * @param acadCalMap used to determine current academic week + * @return an array of Strings of the current semester's details + */ + private static String[] getSemesterDetails(LocalDate date, HashMap acadCalMap) { + String acadWeek; + String acadSem; + String acadYear = null; + String noOfWeeks = null; + String[] acadWeekDetails; + LocalDate startDate = date; + LocalDate endDate = date; + int currentYear = date.getYear(); + int currentWeekOfYear = date.get(WeekFields.ISO.weekOfWeekBasedYear()); + + // Initialise week numbers for certain weeks. + int firstWeekSemOne = 0; + int firstWeekSemOneHol = 0; + int lastWeekSemOneHol = 0; + int firstWeekSemTwo = 0; + int firstWeekSemTwoHol = 0; + for (Map.Entry entry: acadCalMap.entrySet()) { + if ("Orientation Week_Sem 1".equals(entry.getValue())) { + firstWeekSemOne = entry.getKey(); + } else if ("Examination Week_Sem 1".equals(entry.getValue())) { + firstWeekSemOneHol = entry.getKey() + 1; + } else if ("Week 1_Sem 2".equals(entry.getValue())) { + lastWeekSemOneHol = entry.getKey() - 1; + firstWeekSemTwo = entry.getKey(); + } else if ("Examination Week_Sem 2".equals(entry.getValue())) { + firstWeekSemTwoHol = entry.getKey() + 1; + } + } + + // Set semester details. + acadWeekDetails = acadCalMap.get(currentWeekOfYear).split("_"); + acadWeek = acadWeekDetails[0]; + acadSem = acadWeekDetails[1]; + if ("Vacation".equals(acadWeek) && "Sem 1".equals(acadSem)) { + noOfWeeks = "5"; + if (currentWeekOfYear < 4) { + acadYear = "AY" + (currentYear - 1) + "/" + currentYear; + startDate = startDate.withYear(currentYear - 1); + } else { + acadYear = "AY" + currentYear + "/" + (currentYear + 1); + endDate = endDate.withYear(currentYear + 1); + } + startDate = startDate.with(WeekFields.ISO.weekOfWeekBasedYear(), firstWeekSemOneHol); + startDate = startDate.with(WeekFields.ISO.dayOfWeek(), 1); + endDate = endDate.with(WeekFields.ISO.weekOfWeekBasedYear(), lastWeekSemOneHol); + endDate = endDate.with(WeekFields.ISO.dayOfWeek(), 7); + } else if ("Vacation".equals(acadWeek) && "Sem 2".equals(acadSem)) { + noOfWeeks = "12"; + acadYear = "AY" + (currentYear - 1) + "/" + currentYear; + startDate = startDate.with(WeekFields.ISO.weekOfWeekBasedYear(), firstWeekSemTwoHol); + startDate = startDate.with(WeekFields.ISO.dayOfWeek(), 1); + endDate = endDate.with(WeekFields.ISO.weekOfWeekBasedYear(), firstWeekSemTwoHol + 11); + endDate = endDate.with(WeekFields.ISO.dayOfWeek(), 7); + } else if ("Sem 1".equals(acadSem)) { + noOfWeeks = "18"; + acadYear = "AY" + currentYear + "/" + (currentYear + 1); + startDate = startDate.with(WeekFields.ISO.weekOfWeekBasedYear(), firstWeekSemOne); + startDate = startDate.with(WeekFields.ISO.dayOfWeek(), 1); + endDate = endDate.with(WeekFields.ISO.weekOfWeekBasedYear(), firstWeekSemOne + 17); + endDate = endDate.with(WeekFields.ISO.dayOfWeek(), 7); + } else if ("Sem 2".equals(acadSem)) { + noOfWeeks = "17"; + acadYear = "AY" + (currentYear - 1) + "/" + currentYear; + startDate = startDate.with(WeekFields.ISO.weekOfWeekBasedYear(), firstWeekSemTwo); + startDate = startDate.with(WeekFields.ISO.dayOfWeek(), 1); + endDate = endDate.with(WeekFields.ISO.weekOfWeekBasedYear(), firstWeekSemTwo + 16); + endDate = endDate.with(WeekFields.ISO.dayOfWeek(), 7); + } + return new String[] {acadWeek, acadSem, acadYear, noOfWeeks, startDate.toString(), endDate.toString()}; + } + /** * Adds a Day to the list. * diff --git a/test/java/planmysem/data/PlannerTest.java b/test/java/planmysem/data/PlannerTest.java index 45c725126..525ced206 100644 --- a/test/java/planmysem/data/PlannerTest.java +++ b/test/java/planmysem/data/PlannerTest.java @@ -25,21 +25,21 @@ public void execute_generateSemester() { Semester expectedSemester; // Assert Semester One generation - generatedSemester = Planner.generateSemester(LocalDate.of(2018, 8, 6)); + generatedSemester = Semester.generateSemester(LocalDate.of(2018, 8, 6)); LocalDate semOneDate = LocalDate.of(2018, 8, 6); expectedSemester = helper.generateSemesterFromDate(semOneDate, "Sem 1"); assertSameSemester(generatedSemester, expectedSemester); - expectedSemester = Planner.generateSemester(LocalDate.of(2018, 10, 6)); + expectedSemester = Semester.generateSemester(LocalDate.of(2018, 10, 6)); assertSameSemester(generatedSemester, expectedSemester); // Assert Semester Two generation - generatedSemester = Planner.generateSemester(LocalDate.of(2019, 1, 14)); + generatedSemester = Semester.generateSemester(LocalDate.of(2019, 1, 14)); LocalDate semTwoDate = LocalDate.of(2019, 1, 14); expectedSemester = helper.generateSemesterFromDate(semTwoDate, "Sem 2"); assertSameSemester(generatedSemester, expectedSemester); - expectedSemester = Planner.generateSemester(LocalDate.of(2019, 3, 17)); + expectedSemester = Semester.generateSemester(LocalDate.of(2019, 3, 17)); assertSameSemester(generatedSemester, expectedSemester); } @@ -48,15 +48,7 @@ public void execute_generateSemester() { */ private void assertSameSemester(Semester generatedSemester, Semester expectedSemester) { //Confirm the state of data is as expected - assertEquals(generatedSemester.getName(), expectedSemester.getName()); - assertEquals(generatedSemester.getAcademicYear(), expectedSemester.getAcademicYear()); - assertEquals(generatedSemester.getNoOfWeeks(), expectedSemester.getNoOfWeeks()); - assertEquals(generatedSemester.getStartDate(), expectedSemester.getStartDate()); - assertEquals(generatedSemester.getEndDate(), expectedSemester.getEndDate()); - assertEquals(generatedSemester.getDays().size(), expectedSemester.getDays().size()); - assertEquals(generatedSemester.getRecessDays().size(), expectedSemester.getRecessDays().size()); - assertEquals(generatedSemester.getReadingDays().size(), expectedSemester.getReadingDays().size()); - assertEquals(generatedSemester.getExamDays().size(), expectedSemester.getExamDays().size()); + assertEquals(generatedSemester.hashCode(), expectedSemester.hashCode()); } /** diff --git a/test/java/planmysem/logic/LogicTest.java b/test/java/planmysem/logic/LogicTest.java index f9e692581..3bb1d13d0 100644 --- a/test/java/planmysem/logic/LogicTest.java +++ b/test/java/planmysem/logic/LogicTest.java @@ -42,6 +42,7 @@ import planmysem.data.recurrence.Recurrence; import planmysem.data.semester.Day; import planmysem.data.semester.ReadOnlyDay; +import planmysem.data.semester.Semester; import planmysem.data.slot.Description; import planmysem.data.slot.Location; import planmysem.data.slot.Name; @@ -74,7 +75,7 @@ public void setup() throws Exception { } private Planner createPlanner() { - return new Planner(Planner.generateSemester(LocalDate.of(2019, 1, 14))); + return new Planner(Semester.generateSemester(LocalDate.of(2019, 1, 14))); } @Test