From 109ae17a337c1759e621393fe3288138ec5f44c4 Mon Sep 17 00:00:00 2001 From: Kyzure Date: Wed, 6 Nov 2019 02:56:56 +0800 Subject: [PATCH 1/4] Added stub and test for Uiamanger. --- .../address/commons/stub/UiManagerStub.java | 73 +++++++++++++++++++ .../seedu/address/logic/UiManagerTest.java | 52 +++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 src/test/java/seedu/address/logic/UiManagerTest.java diff --git a/src/main/java/seedu/address/commons/stub/UiManagerStub.java b/src/main/java/seedu/address/commons/stub/UiManagerStub.java index ef3477ac361..a5317c28e24 100644 --- a/src/main/java/seedu/address/commons/stub/UiManagerStub.java +++ b/src/main/java/seedu/address/commons/stub/UiManagerStub.java @@ -2,6 +2,15 @@ import seedu.address.logic.UiManager; import seedu.address.model.CalendarDate; +import seedu.address.model.ModelLists; +import seedu.address.model.events.EventDateComparator; +import seedu.address.model.events.EventSource; +import seedu.address.model.tasks.TaskDateComparator; +import seedu.address.model.tasks.TaskSource; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; /** * Represents a stub for the UiManager that is used for testing purpose only. @@ -38,4 +47,68 @@ public void viewWeek(CalendarDate calendarDate) { public void viewMonth(CalendarDate calendarDate) { return; } + + @Override + public void onModelListChange(ModelLists lists) { + List sortedDateEventList = sortDateEventList(lists.getEvents()); + List sortedDateTaskList = sortDateTaskList(lists.getTasks()); + HashMap eventHash = addEventIndex(lists.getEvents()); + HashMap taskHash = addTaskIndex(lists.getTasks()); + } + + /** + * Returns a copy of the event list sorted by start date. + * + * @param events The given event list. + * @return A copy of the event list sorted by date. + */ + private List sortDateEventList(List events) { + List sortedDateEventList = new ArrayList<>(events); + sortedDateEventList.sort(new EventDateComparator()); + return sortedDateEventList; + } + + /** + * Returns a HashMap based on the indexing of the original event list. + * + * @param events The unsorted event list. + * @return Returns a HashMap based on the indexing of the original event list + */ + private HashMap addEventIndex(List events) { + int backIndex = 0; + HashMap eventHash = new HashMap<>(); + for (EventSource event : events) { + eventHash.put(event, backIndex); + backIndex++; + } + return eventHash; + } + + /** + * Returns a copy of the task list sorted by due date. + * + * @param tasks The given task list. + * @return A copy of the task list sorted by due date. + */ + private List sortDateTaskList(List tasks) { + List sortedDateTaskList = new ArrayList<>(tasks); + sortedDateTaskList.sort(new TaskDateComparator()); + return sortedDateTaskList; + } + + /** + * Returns a HashMap based on the indexing of the original event list. + * + * @param tasks The unsorted task list. + * @return Returns a HashMap based on the indexing of the original task list + */ + private HashMap addTaskIndex(List tasks) { + int backIndex = 0; + HashMap taskHash = new HashMap<>(); + for (TaskSource task : tasks) { + taskHash.put(task, backIndex); + backIndex++; + } + return taskHash; + } } diff --git a/src/test/java/seedu/address/logic/UiManagerTest.java b/src/test/java/seedu/address/logic/UiManagerTest.java new file mode 100644 index 00000000000..fe79cece561 --- /dev/null +++ b/src/test/java/seedu/address/logic/UiManagerTest.java @@ -0,0 +1,52 @@ +package seedu.address.logic; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.junit.jupiter.api.Test; + +import seedu.address.commons.stub.UiManagerStub; +import seedu.address.model.DateTime; +import seedu.address.model.ModelLists; +import seedu.address.model.events.EventSource; +import seedu.address.model.tasks.TaskSource; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.List; + +class UiManagerTest { + + @Test + void onModelListChangeTest() { + UiManagerStub uiManager = new UiManagerStub(); + List events = new ArrayList<>(); + List tasks = new ArrayList<>(); + + LocalDate date = LocalDate.parse("2019-11-04"); + Instant instant = date.atStartOfDay(ZoneId.systemDefault()).toInstant(); + LocalDate date1 = LocalDate.parse("2019-11-05"); + Instant instant1 = date1.atStartOfDay(ZoneId.systemDefault()).toInstant(); + + events.add(EventSource.newBuilder( + "description", + DateTime.newBuilder(instant).build()) + .build()); + events.add(EventSource.newBuilder( + "description1", + DateTime.newBuilder(instant1).build()) + .build()); + + tasks.add(TaskSource.newBuilder( + "description") + .build()); + tasks.add(TaskSource.newBuilder( + "description1") + .build()); + + ModelLists modelLists = new ModelLists(events, tasks); + assertDoesNotThrow(() -> uiManager.onModelListChange(modelLists)); + } + +} From 26a26df870f1e41995447a866a5619172eafaab0 Mon Sep 17 00:00:00 2001 From: Kyzure Date: Wed, 6 Nov 2019 17:38:39 +0800 Subject: [PATCH 2/4] Added Test for CalendarDate and certain UiLogic that is abstracted out into stubs. --- .../seedu/address/model/CalendarDate.java | 11 --- .../address/ui/stub/CalendarPanelStub.java | 69 +++++++++++++ .../{commons => ui}/stub/UiManagerStub.java | 43 ++++---- .../commands/CalendarViewCommandTest.java | 3 +- .../logic/commands/DayViewCommandTest.java | 2 +- .../logic/commands/ListViewCommandTest.java | 2 +- .../logic/commands/LogViewCommandTest.java | 2 +- .../logic/commands/MonthViewCommandTest.java | 2 +- .../logic/commands/WeekViewCommandTest.java | 2 +- .../seedu/address/model/CalendarDateTest.java | 97 +++++++++++++++++++ .../address/ui/stub/CalendarPanelTest.java | 69 +++++++++++++ .../{logic => ui/stub}/UiManagerTest.java | 50 ++++++---- 12 files changed, 294 insertions(+), 58 deletions(-) create mode 100644 src/main/java/seedu/address/ui/stub/CalendarPanelStub.java rename src/main/java/seedu/address/{commons => ui}/stub/UiManagerStub.java (87%) create mode 100644 src/test/java/seedu/address/model/CalendarDateTest.java create mode 100644 src/test/java/seedu/address/ui/stub/CalendarPanelTest.java rename src/test/java/seedu/address/{logic => ui/stub}/UiManagerTest.java (53%) diff --git a/src/main/java/seedu/address/model/CalendarDate.java b/src/main/java/seedu/address/model/CalendarDate.java index e05245b863f..9938d73872f 100644 --- a/src/main/java/seedu/address/model/CalendarDate.java +++ b/src/main/java/seedu/address/model/CalendarDate.java @@ -89,17 +89,6 @@ public CalendarDate nextDay() { return new CalendarDate(previousLocalDate); } - /** - * Returns a new CalendarDate of the current day plus the given days. - * - * @param days The number of days to add. - * @return A new CalendarDate of the next days. - */ - public CalendarDate nextDays(Integer days) { - LocalDate previousLocalDate = localDate.plusDays(days); - return new CalendarDate(previousLocalDate); - } - /** * Returns a new CalendarDate of the current day minus the given days. * diff --git a/src/main/java/seedu/address/ui/stub/CalendarPanelStub.java b/src/main/java/seedu/address/ui/stub/CalendarPanelStub.java new file mode 100644 index 00000000000..32962e12cd8 --- /dev/null +++ b/src/main/java/seedu/address/ui/stub/CalendarPanelStub.java @@ -0,0 +1,69 @@ +package seedu.address.ui.stub; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +import seedu.address.model.events.EventSource; +import seedu.address.model.tasks.TaskSource; +import seedu.address.ui.panel.calendar.CalendarPanel; + +/** + * Represents a stub for CalendarPanel that is mainly used for testing purpose only. + * + * @see CalendarPanel + */ +class CalendarPanelStub extends CalendarPanel { + + /** + * Returns a combined copy of list for event list and task list into an Object list to be used. + * This is a version modified mainly for testing. The logic behind it is the exact same. + * + * @param events Represents the event list. + * @param tasks Represents the task list. + * @return A combined copy of list for event list and task list into an Object list to be used. + */ + public List combineList(List events, List tasks) { + List eventTaskList = new ArrayList<>(); + Queue tempEvents = new LinkedList<>(); + tempEvents.addAll(events); + Queue tempTasks = new LinkedList<>(); + tempTasks.addAll(tasks); + + // Events and Tasks are already sorted, so we need to zip them. + while (!tempEvents.isEmpty() || !tempTasks.isEmpty()) { + if (tempEvents.isEmpty()) { + eventTaskList.addAll(tempTasks); + break; + } + + if (tempTasks.isEmpty()) { + eventTaskList.addAll(tempEvents); + break; + } + + EventSource event = tempEvents.peek(); + TaskSource task = tempTasks.peek(); + if (task.isDone() || task.getDueDate() == null) { + tempTasks.poll(); + continue; + } + + int dateCompare = event.getStartDateTime().compareTo(task.getDueDate()); + if (dateCompare == 0) { + if (event.getDescription().compareTo(task.getDescription()) <= 0) { + eventTaskList.add(tempEvents.poll()); + } else { + eventTaskList.add(tempTasks.poll()); + } + } else if (dateCompare < 0) { + eventTaskList.add(tempEvents.poll()); + } else { + eventTaskList.add(tempTasks.poll()); + } + } + + return eventTaskList; + } +} diff --git a/src/main/java/seedu/address/commons/stub/UiManagerStub.java b/src/main/java/seedu/address/ui/stub/UiManagerStub.java similarity index 87% rename from src/main/java/seedu/address/commons/stub/UiManagerStub.java rename to src/main/java/seedu/address/ui/stub/UiManagerStub.java index a5317c28e24..948bdcbcba2 100644 --- a/src/main/java/seedu/address/commons/stub/UiManagerStub.java +++ b/src/main/java/seedu/address/ui/stub/UiManagerStub.java @@ -1,4 +1,8 @@ -package seedu.address.commons.stub; +package seedu.address.ui.stub; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import seedu.address.logic.UiManager; import seedu.address.model.CalendarDate; @@ -8,52 +12,49 @@ import seedu.address.model.tasks.TaskDateComparator; import seedu.address.model.tasks.TaskSource; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - /** - * Represents a stub for the UiManager that is used for testing purpose only. - * @see UiManager + * Represents a logic class that holds all of the methods that uses logic only that + * is mainly used for testing. */ public class UiManagerStub extends UiManager { - @Override - public void viewCalendar(CalendarDate calendarDate) { + public void viewDay(CalendarDate calendarDate) { return; } - @Override - public void viewList() { + public void viewWeek(CalendarDate calendarDate) { return; } - @Override - public void viewLog() { + public void viewMonth(CalendarDate calendarDate) { return; } - @Override - public void viewDay(CalendarDate calendarDate) { + public void viewList() { return; } - @Override - public void viewWeek(CalendarDate calendarDate) { + public void viewLog() { return; } - @Override - public void viewMonth(CalendarDate calendarDate) { + public void viewCalendar(CalendarDate calendarDate) { return; } - @Override - public void onModelListChange(ModelLists lists) { + /** + * Returns a ModelLists mainly for testing. + * + * @param lists The given model lists. + * @return The sorted model lists. + */ + public ModelLists overrideOnModelListChange(ModelLists lists) { List sortedDateEventList = sortDateEventList(lists.getEvents()); List sortedDateTaskList = sortDateTaskList(lists.getTasks()); HashMap eventHash = addEventIndex(lists.getEvents()); HashMap taskHash = addTaskIndex(lists.getTasks()); + + return new ModelLists(sortedDateEventList, sortedDateTaskList); } /** diff --git a/src/test/java/seedu/address/logic/commands/CalendarViewCommandTest.java b/src/test/java/seedu/address/logic/commands/CalendarViewCommandTest.java index 858769e4822..cccee4da693 100644 --- a/src/test/java/seedu/address/logic/commands/CalendarViewCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/CalendarViewCommandTest.java @@ -5,9 +5,10 @@ import org.junit.jupiter.api.Test; -import seedu.address.commons.stub.UiManagerStub; +import seedu.address.ui.stub.UiManagerStub; class CalendarViewCommandTest { + @Test void build_fullCommand_success() { String calendarDate = "11/1111"; diff --git a/src/test/java/seedu/address/logic/commands/DayViewCommandTest.java b/src/test/java/seedu/address/logic/commands/DayViewCommandTest.java index a470e6df932..d2bdf91ced2 100644 --- a/src/test/java/seedu/address/logic/commands/DayViewCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/DayViewCommandTest.java @@ -5,9 +5,9 @@ import org.junit.jupiter.api.Test; -import seedu.address.commons.stub.UiManagerStub; import seedu.address.logic.UiManager; import seedu.address.logic.commands.exceptions.ArgumentException; +import seedu.address.ui.stub.UiManagerStub; class DayViewCommandTest { diff --git a/src/test/java/seedu/address/logic/commands/ListViewCommandTest.java b/src/test/java/seedu/address/logic/commands/ListViewCommandTest.java index a6e2b9307c9..3565820fd5b 100644 --- a/src/test/java/seedu/address/logic/commands/ListViewCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ListViewCommandTest.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test; -import seedu.address.commons.stub.UiManagerStub; +import seedu.address.ui.stub.UiManagerStub; class ListViewCommandTest { diff --git a/src/test/java/seedu/address/logic/commands/LogViewCommandTest.java b/src/test/java/seedu/address/logic/commands/LogViewCommandTest.java index f8cdc994de8..0ca2f9faf41 100644 --- a/src/test/java/seedu/address/logic/commands/LogViewCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/LogViewCommandTest.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test; -import seedu.address.commons.stub.UiManagerStub; +import seedu.address.ui.stub.UiManagerStub; class LogViewCommandTest { diff --git a/src/test/java/seedu/address/logic/commands/MonthViewCommandTest.java b/src/test/java/seedu/address/logic/commands/MonthViewCommandTest.java index c59875a96ed..9bc930efeb3 100644 --- a/src/test/java/seedu/address/logic/commands/MonthViewCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/MonthViewCommandTest.java @@ -5,9 +5,9 @@ import org.junit.jupiter.api.Test; -import seedu.address.commons.stub.UiManagerStub; import seedu.address.logic.UiManager; import seedu.address.logic.commands.exceptions.ArgumentException; +import seedu.address.ui.stub.UiManagerStub; class MonthViewCommandTest { diff --git a/src/test/java/seedu/address/logic/commands/WeekViewCommandTest.java b/src/test/java/seedu/address/logic/commands/WeekViewCommandTest.java index e83c7832a48..105e32d7594 100644 --- a/src/test/java/seedu/address/logic/commands/WeekViewCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/WeekViewCommandTest.java @@ -5,9 +5,9 @@ import org.junit.jupiter.api.Test; -import seedu.address.commons.stub.UiManagerStub; import seedu.address.logic.UiManager; import seedu.address.logic.commands.exceptions.ArgumentException; +import seedu.address.ui.stub.UiManagerStub; class WeekViewCommandTest { diff --git a/src/test/java/seedu/address/model/CalendarDateTest.java b/src/test/java/seedu/address/model/CalendarDateTest.java new file mode 100644 index 00000000000..aa51cf0425b --- /dev/null +++ b/src/test/java/seedu/address/model/CalendarDateTest.java @@ -0,0 +1,97 @@ +package seedu.address.model; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +class CalendarDateTest { + + @Test + void getDateTest() { + assertDoesNotThrow(() -> { + CalendarDate dayMonthYear = CalendarDate.fromDayMonthYearString("11/11/2019"); + assertEquals(dayMonthYear.getDay(), 11); + assertEquals(dayMonthYear.getMonth(), 11); + assertEquals(dayMonthYear.getYear(), 2019); + assertEquals(dayMonthYear.getEnglishMonth(), "November"); + assertEquals(dayMonthYear.getWeekIndex(), 1); + assertEquals(dayMonthYear.lengthOfMonth(), 30); + + CalendarDate monthYear = CalendarDate.fromMonthYearString("11/2019"); + assertEquals(monthYear.getDay(), 30); + assertEquals(monthYear.getMonth(), 11); + assertEquals(monthYear.getYear(), 2019); + assertEquals(monthYear.getEnglishMonth(), "November"); + assertEquals(monthYear.getWeekIndex(), 6); + assertEquals(monthYear.lengthOfMonth(), 30); + }); + } + + @Test + void sameDateTest() { + assertDoesNotThrow(() -> { + CalendarDate dayMonthYear = CalendarDate.fromDayMonthYearString("11/11/2019"); + dayMonthYear.sameDate(11, 11, 2019); + dayMonthYear.sameMonthYear(11, 2019); + + CalendarDate monthYear = CalendarDate.fromMonthYearString("10/2019"); + monthYear.sameDate(30, 11, 2019); + monthYear.sameMonthYear(11, 2019); + }); + } + + @Test + void changeDateTest() { + assertDoesNotThrow(() -> { + CalendarDate dayMonthYear = CalendarDate.fromDayMonthYearString("11/11/2019"); + dayMonthYear = dayMonthYear.previousDay(); + assertTrue(dayMonthYear.sameDate(10, 11, 2019)); + dayMonthYear = dayMonthYear.previousDays(15); + assertTrue(dayMonthYear.sameDate(26, 10, 2019)); + + dayMonthYear = dayMonthYear.nextDay(); + assertTrue(dayMonthYear.sameDate(27, 10, 2019)); + + dayMonthYear = dayMonthYear.firstDayOfTheMonth(); + assertTrue(dayMonthYear.sameDate(1, 10, 2019)); + + CalendarDate monthYear = CalendarDate.fromMonthYearString("11/2019"); + monthYear = monthYear.previousDay(); + assertTrue(monthYear.sameDate(29, 11, 2019)); + monthYear = monthYear.previousDays(33); + assertTrue(monthYear.sameDate(27, 10, 2019)); + + monthYear = monthYear.nextDay(); + assertTrue(monthYear.sameDate(28, 10, 2019)); + + monthYear = monthYear.firstDayOfTheMonth(); + assertTrue(monthYear.sameDate(1, 10, 2019)); + + }); + } + + @Test + void equalityTest() { + assertDoesNotThrow(() -> { + CalendarDate dayMonthYear = CalendarDate.fromDayMonthYearString("30/11/2019"); + CalendarDate monthYear = CalendarDate.fromMonthYearString("11/2019"); + assertEquals(dayMonthYear, monthYear); + + assertEquals(dayMonthYear.nextDay(), monthYear.nextDay()); + assertEquals(dayMonthYear.previousDays(100), monthYear.previousDays(100)); + }); + } + + @Test + void toStringTest() { + assertDoesNotThrow(() -> { + CalendarDate dayMonthYear = CalendarDate.fromDayMonthYearString("11/11/2019"); + CalendarDate monthYear = CalendarDate.fromMonthYearString("10/2019"); + assertEquals(dayMonthYear.toString(), "11/11/2019"); + assertEquals(monthYear.toString(), "31/10/2019"); + }); + } + +} diff --git a/src/test/java/seedu/address/ui/stub/CalendarPanelTest.java b/src/test/java/seedu/address/ui/stub/CalendarPanelTest.java new file mode 100644 index 00000000000..ed6f5a75476 --- /dev/null +++ b/src/test/java/seedu/address/ui/stub/CalendarPanelTest.java @@ -0,0 +1,69 @@ +package seedu.address.ui.stub; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.Test; + +import seedu.address.model.DateTime; +import seedu.address.model.events.EventSource; +import seedu.address.model.tasks.TaskSource; + +public class CalendarPanelTest { + + @Test + void combineList() { + List events = new ArrayList<>(); + List tasks = new ArrayList<>(); + + LocalDate date = LocalDate.parse("2019-11-07"); + Instant instant = date.atStartOfDay(ZoneId.systemDefault()).toInstant(); + LocalDate date1 = LocalDate.parse("2019-11-05"); + Instant instant1 = date1.atStartOfDay(ZoneId.systemDefault()).toInstant(); + LocalDate date2 = LocalDate.parse("2019-11-06"); + Instant instant2 = date2.atStartOfDay(ZoneId.systemDefault()).toInstant(); + LocalDate date3 = LocalDate.parse("2019-11-04"); + Instant instant3 = date3.atStartOfDay(ZoneId.systemDefault()).toInstant(); + + + EventSource event = EventSource.newBuilder( + "description", + DateTime.newBuilder(instant).build()) + .build(); + EventSource event1 = EventSource.newBuilder( + "description1", + DateTime.newBuilder(instant1).build()) + .build(); + + TaskSource task = TaskSource.newBuilder( + "description2") + .setDueDate(DateTime.newBuilder(instant2).build()) + .build(); + TaskSource task1 = TaskSource.newBuilder( + "description3") + .setDueDate(DateTime.newBuilder(instant3).build()) + .build(); + + events.add(event1); + events.add(event); + tasks.add(task1); + tasks.add(task); + + CalendarPanelStub calendarPanel = new CalendarPanelStub(); + + assertDoesNotThrow(() -> { + List lists = calendarPanel.combineList(events, tasks); + assertEquals(lists.get(0), task1); + assertEquals(lists.get(1), event1); + assertEquals(lists.get(2), task); + assertEquals(lists.get(3), event); + }); + + } +} diff --git a/src/test/java/seedu/address/logic/UiManagerTest.java b/src/test/java/seedu/address/ui/stub/UiManagerTest.java similarity index 53% rename from src/test/java/seedu/address/logic/UiManagerTest.java rename to src/test/java/seedu/address/ui/stub/UiManagerTest.java index fe79cece561..e0649821231 100644 --- a/src/test/java/seedu/address/logic/UiManagerTest.java +++ b/src/test/java/seedu/address/ui/stub/UiManagerTest.java @@ -1,21 +1,21 @@ -package seedu.address.logic; +package seedu.address.ui.stub; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.List; import org.junit.jupiter.api.Test; -import seedu.address.commons.stub.UiManagerStub; import seedu.address.model.DateTime; import seedu.address.model.ModelLists; import seedu.address.model.events.EventSource; import seedu.address.model.tasks.TaskSource; -import java.time.Instant; -import java.time.LocalDate; -import java.time.ZoneId; -import java.util.ArrayList; -import java.util.List; - class UiManagerTest { @Test @@ -24,29 +24,39 @@ void onModelListChangeTest() { List events = new ArrayList<>(); List tasks = new ArrayList<>(); - LocalDate date = LocalDate.parse("2019-11-04"); + LocalDate date = LocalDate.parse("2019-11-05"); Instant instant = date.atStartOfDay(ZoneId.systemDefault()).toInstant(); - LocalDate date1 = LocalDate.parse("2019-11-05"); + LocalDate date1 = LocalDate.parse("2019-11-04"); Instant instant1 = date1.atStartOfDay(ZoneId.systemDefault()).toInstant(); - events.add(EventSource.newBuilder( + EventSource event = EventSource.newBuilder( "description", DateTime.newBuilder(instant).build()) - .build()); - events.add(EventSource.newBuilder( + .build(); + EventSource event1 = EventSource.newBuilder( "description1", DateTime.newBuilder(instant1).build()) - .build()); + .build(); - tasks.add(TaskSource.newBuilder( + TaskSource task = TaskSource.newBuilder( "description") - .build()); - tasks.add(TaskSource.newBuilder( + .build(); + TaskSource task1 = TaskSource.newBuilder( "description1") - .build()); + .build(); + + events.add(event); + events.add(event1); + tasks.add(task); + tasks.add(task1); ModelLists modelLists = new ModelLists(events, tasks); - assertDoesNotThrow(() -> uiManager.onModelListChange(modelLists)); + assertDoesNotThrow(() -> { + ModelLists lists = uiManager.overrideOnModelListChange(modelLists); + assertEquals(lists.getEvents().get(0), event1); + assertEquals(lists.getEvents().get(1), event); + assertEquals(lists.getTasks().get(0), task); + assertEquals(lists.getTasks().get(1), task1); + }); } - } From 081fb43d680fbaab7a99f85ce91e119fa4ffda56 Mon Sep 17 00:00:00 2001 From: Kyzure Date: Wed, 6 Nov 2019 18:33:56 +0800 Subject: [PATCH 3/4] Added TimelineWeekView Stub and tests for it. --- .../address/ui/stub/CalendarPanelStub.java | 2 +- .../address/ui/stub/TimelineWeekViewStub.java | 64 +++++++++++++++++++ .../address/ui/stub/TimelineWeekViewTest.java | 54 ++++++++++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/main/java/seedu/address/ui/stub/TimelineWeekViewStub.java create mode 100644 src/test/java/seedu/address/ui/stub/TimelineWeekViewTest.java diff --git a/src/main/java/seedu/address/ui/stub/CalendarPanelStub.java b/src/main/java/seedu/address/ui/stub/CalendarPanelStub.java index 32962e12cd8..4089691cf56 100644 --- a/src/main/java/seedu/address/ui/stub/CalendarPanelStub.java +++ b/src/main/java/seedu/address/ui/stub/CalendarPanelStub.java @@ -14,7 +14,7 @@ * * @see CalendarPanel */ -class CalendarPanelStub extends CalendarPanel { +class CalendarPanelStub { /** * Returns a combined copy of list for event list and task list into an Object list to be used. diff --git a/src/main/java/seedu/address/ui/stub/TimelineWeekViewStub.java b/src/main/java/seedu/address/ui/stub/TimelineWeekViewStub.java new file mode 100644 index 00000000000..4a32d85aaed --- /dev/null +++ b/src/main/java/seedu/address/ui/stub/TimelineWeekViewStub.java @@ -0,0 +1,64 @@ +package seedu.address.ui.stub; + +import java.text.DateFormatSymbols; + +import seedu.address.model.CalendarDate; +import seedu.address.ui.panel.calendar.TimelineWeekView; + + +/** + * Represents a stub for testing purpose for TimelineWeekView. + * + * @see TimelineWeekView + */ +class TimelineWeekViewStub { + + private CalendarDate calendarDate; + + public TimelineWeekViewStub() {} + + public TimelineWeekViewStub(CalendarDate calendarDate) { + this.calendarDate = calendarDate; + } + + /** + * Returns the list of dates of the given week. Main purpose is for testing. + * + * @return A list of dates. + */ + public CalendarDate[] addWeek() { + CalendarDate[] calendarDates = new CalendarDate[7]; + int weekIndex = calendarDate.getWeekIndex(); + while (weekIndex > 1) { + calendarDate = calendarDate.previousDay(); + weekIndex--; + } + for (int i = 0; i < calendarDates.length; i++) { + calendarDates[i] = calendarDate; + calendarDate = calendarDate.nextDay(); + } + return calendarDates; + } + + public Integer getWeek(CalendarDate calendarDate) { + CalendarDate currentDate = calendarDate.firstDayOfTheMonth(); + Integer weekIndex = currentDate.getWeekIndex(); + currentDate = currentDate.previousDays(weekIndex - 1); + for (int week = 0; week < 6; week++) { + for (int day = 0; day < 7; day++) { + if (calendarDate.equals(currentDate)) { + return week + 1; + } + currentDate = currentDate.nextDay(); + } + } + // Not suppose to reach here. + return null; + } + + public String getEnglishWeekDate(Integer week, Integer month, Integer year) { + String monthStr = new DateFormatSymbols().getMonths()[month - 1].toLowerCase(); + monthStr = monthStr.substring(0, 1).toUpperCase() + monthStr.substring(1); + return "Week " + week + " of " + monthStr + " " + year; + } +} diff --git a/src/test/java/seedu/address/ui/stub/TimelineWeekViewTest.java b/src/test/java/seedu/address/ui/stub/TimelineWeekViewTest.java new file mode 100644 index 00000000000..e3d09df2058 --- /dev/null +++ b/src/test/java/seedu/address/ui/stub/TimelineWeekViewTest.java @@ -0,0 +1,54 @@ +package seedu.address.ui.stub; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +import seedu.address.model.CalendarDate; + +class TimelineWeekViewTest { + + @Test + void addWeekTest() { + assertDoesNotThrow(() -> { + TimelineWeekViewStub timelineWeekView = + new TimelineWeekViewStub(CalendarDate.fromDayMonthYearString("11/11/2019")); + CalendarDate[] calendarDates = { + CalendarDate.fromDayMonthYearString("11/11/2019"), + CalendarDate.fromDayMonthYearString("12/11/2019"), + CalendarDate.fromDayMonthYearString("13/11/2019"), + CalendarDate.fromDayMonthYearString("14/11/2019"), + CalendarDate.fromDayMonthYearString("15/11/2019"), + CalendarDate.fromDayMonthYearString("16/11/2019"), + CalendarDate.fromDayMonthYearString("17/11/2019") + }; + CalendarDate[] timelineCalendarDates = timelineWeekView.addWeek(); + + assertEquals(timelineCalendarDates.length, 7); + + for (int i = 0; i < timelineCalendarDates.length; i++) { + assertEquals(calendarDates[i], timelineCalendarDates[i]); + } + + }); + } + + @Test + void getWeekTest() { + assertDoesNotThrow(() -> { + TimelineWeekViewStub timelineWeekView = new TimelineWeekViewStub(); + assertEquals( + timelineWeekView.getWeek(CalendarDate.fromDayMonthYearString("11/11/2019")), + 3); + }); + } + + @Test + void getEnglishWeekDateTest() { + TimelineWeekViewStub timelineWeekView = new TimelineWeekViewStub(); + assertEquals( + timelineWeekView.getEnglishWeekDate(3, 11, 2019), + "Week 3 of November 2019"); + } +} From 844ede7c279220c8e8babebdbbadd88f29da74d7 Mon Sep 17 00:00:00 2001 From: Kyzure Date: Thu, 7 Nov 2019 02:08:33 +0800 Subject: [PATCH 4/4] Edited Sequence Diagram --- docs/diagrams/UiSequenceDiagram.puml | 89 ++++++++++++------- .../java/seedu/address/ui/MainWindow.java | 2 +- 2 files changed, 58 insertions(+), 33 deletions(-) diff --git a/docs/diagrams/UiSequenceDiagram.puml b/docs/diagrams/UiSequenceDiagram.puml index fbf1e22c991..4a903769876 100644 --- a/docs/diagrams/UiSequenceDiagram.puml +++ b/docs/diagrams/UiSequenceDiagram.puml @@ -1,6 +1,10 @@ @startuml !include style.puml +box Logic LOGIC_COLOR_T1 +participant ":UiManager" as UiManager LOGIC_COLOR +end box + box Ui UI_COLOR_T1 participant ":MainWindow" as MainWindow UI_COLOR participant ":CalendarPanel" as CalendarPanel UI_COLOR @@ -8,47 +12,68 @@ participant "ListPanel" as ListPanel UI_COLOR participant "LogPanel" as LogPanel UI_COLOR end box -box Model MODEL_COLOR_T1 -participant ":Model" as Model MODEL_COLOR -participant ":VersionedAddressBook" as VersionedAddressBook MODEL_COLOR -end box -[-> MainWindow : OnModelListChange(List) -activate LogicManager +'==== UiManager ====' +[-> UiManager : onModelListChange(lists) +activate UiManager +UiManager -> UiManager : sortDateEventList(events) +UiManager -> UiManager : sortDateTaskList(tasks) +UiManager -> UiManager : addEventIndex(events) +UiManager -> UiManager : addTaskIndex(tasks) -LogicManager -> AddressBookParser : parseCommand(undo) -activate AddressBookParser +'==== MainWindow ==== +UiManager -> MainWindow : onModelListChange(events, tasks, eventHash, taskHash) +activate MainWindow -create UndoCommand -AddressBookParser -> UndoCommand -activate UndoCommand +'==== CalendarPanel ==== +MainWindow -> CalendarPanel : onModelListChange(events, tasks, eventHash, taskHash) +activate CalendarPanel +CalendarPanel --> MainWindow +deactivate CalendarPanel +CalendarPanel -[hidden]--> CalendarPanel +'==== ListPanel ==== +MainWindow -> ListPanel : onEventListChange(events, eventHash) +activate ListPanel +ListPanel --> MainWindow +deactivate ListPanel +ListPanel -[hidden]--> ListPanel -UndoCommand --> AddressBookParser -deactivate UndoCommand +MainWindow -> ListPanel : onTaskListChange(tasks, taskHash) +activate ListPanel +ListPanel --> MainWindow +deactivate ListPanel +ListPanel -[hidden]--> ListPanel -AddressBookParser --> LogicManager : u -deactivate AddressBookParser +'==== MainWindow ==== +MainWindow --> UiManager +deactivate MainWindow +MainWindow -[hidden]--> MainWindow -LogicManager -> UndoCommand : execute() -activate UndoCommand +deactivate UiManager +UiManager -[hidden]--> UiManager -UndoCommand -> Model : undoAddressBook() -activate Model +'==== UiManager ====' +[-> UiManager : onUserOutput(output, colorTheme) +activate UiManager -Model -> VersionedAddressBook : undo() -activate VersionedAddressBook +'==== MainWindow ==== +UiManager -> MainWindow : onUserOutput(output. colorTheme) +activate MainWindow +MainWindow -> MainWindow : getColor(colorTheme) -VersionedAddressBook -> VersionedAddressBook :resetData(ReadOnlyAddressBook) -VersionedAddressBook --> Model : -deactivate VersionedAddressBook +'==== LogPanel ==== +MainWindow -> LogPanel : createLogBox(feedbackToUser, colorTheme) -Model --> UndoCommand -deactivate Model +activate LogPanel +LogPanel --> MainWindow +deactivate LogPanel +LogPanel -[hidden]--> LogPanel -UndoCommand --> LogicManager : result -deactivate UndoCommand -UndoCommand -[hidden]-> LogicManager : result -destroy UndoCommand +'==== MainWindow ==== +MainWindow -> MainWindow : createPopUpBox +MainWindow -[hidden]> MainWindow +MainWindow --> UiManager +deactivate MainWindow -[<--LogicManager -deactivate LogicManager +deactivate UiManager +UiManager -[hidden]--> UiManager @enduml diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 36f048257b2..68b57b74816 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -332,9 +332,9 @@ public void onModelListChange(List events, List tasks, HashMap eventHash, HashMap taskHash) { + this.calendarPanel.onModelListChange(events, tasks, eventHash, taskHash); this.listPanel.onEventListChange(events, eventHash); this.listPanel.onTaskListChange(tasks, taskHash); - this.calendarPanel.onModelListChange(events, tasks, eventHash, taskHash); } /**