This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
forked from nus-cs2103-AY2223S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from lhy-hoyin/branch-SortEvent
New feature: Sort Events
- Loading branch information
Showing
10 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ezschedule.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import ezschedule.logic.commands.exceptions.CommandException; | ||
import ezschedule.model.Model; | ||
|
||
/** | ||
* Sort all events in the scheduler in chronological order. | ||
*/ | ||
public class SortCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "sort"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Events sorted in order."; | ||
|
||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
model.sortEvents(); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
src/test/java/ezschedule/logic/commands/SortCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package ezschedule.logic.commands; | ||
|
||
import static ezschedule.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static ezschedule.testutil.TypicalEvents.getTypicalScheduler; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import ezschedule.model.Model; | ||
import ezschedule.model.ModelManager; | ||
import ezschedule.model.Scheduler; | ||
import ezschedule.model.UserPrefs; | ||
import ezschedule.model.event.Event; | ||
import ezschedule.testutil.EventBuilder; | ||
import ezschedule.testutil.SchedulerBuilder; | ||
import ezschedule.testutil.TypicalEvents; | ||
|
||
public class SortCommandTest { | ||
|
||
private Model model = new ModelManager(getTypicalScheduler(), new UserPrefs()); | ||
|
||
@Test | ||
public void execute_typicalEventsAbcd_success() { | ||
String expectedMessage = SortCommand.MESSAGE_SUCCESS; | ||
|
||
Scheduler scheduler = new SchedulerBuilder() | ||
.withEvent(TypicalEvents.CARNIVAL) | ||
.withEvent(TypicalEvents.ART) | ||
.withEvent(TypicalEvents.DRAG) | ||
.withEvent(TypicalEvents.BOAT) | ||
.build(); | ||
Model givenModel = new ModelManager(scheduler, new UserPrefs()); | ||
|
||
assertCommandSuccess(new SortCommand(), givenModel, expectedMessage, model); | ||
} | ||
|
||
@Test | ||
public void execute_typicalEventAEventB_success() { | ||
String expectedMessage = SortCommand.MESSAGE_SUCCESS; | ||
|
||
Model givenModel = new ModelManager( | ||
new SchedulerBuilder() | ||
.withEvent(TypicalEvents.EVENT_B) | ||
.withEvent(TypicalEvents.EVENT_A) | ||
.build(), | ||
new UserPrefs()); | ||
|
||
Model expectedModel = new ModelManager( | ||
new SchedulerBuilder() | ||
.withEvent(TypicalEvents.EVENT_A) | ||
.withEvent(TypicalEvents.EVENT_B) | ||
.build(), | ||
new UserPrefs()); | ||
|
||
assertCommandSuccess(new SortCommand(), givenModel, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_customEventsSameDate_success() { | ||
String expectedMessage = SortCommand.MESSAGE_SUCCESS; | ||
|
||
// Events are build with default date, end time | ||
Event e1 = new EventBuilder().withName("e1").withStartTime("12:34").build(); | ||
Event e2 = new EventBuilder().withName("e2").withStartTime("21:43").build(); | ||
|
||
Model givenModel = new ModelManager( | ||
new SchedulerBuilder().withEvent(e2).withEvent(e1).build(), | ||
new UserPrefs()); | ||
|
||
Model expectedModel = new ModelManager( | ||
new SchedulerBuilder().withEvent(e1).withEvent(e2).build(), | ||
new UserPrefs()); | ||
|
||
assertCommandSuccess(new SortCommand(), givenModel, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_customEventsSameTime_success() { | ||
String expectedMessage = SortCommand.MESSAGE_SUCCESS; | ||
|
||
// Events are build with default date, end time | ||
Event e1 = new EventBuilder().withName("e1").withDate("2023-05-01").build(); | ||
Event e2 = new EventBuilder().withName("e2").withDate("2023-05-02").build(); | ||
|
||
Model givenModel = new ModelManager( | ||
new SchedulerBuilder().withEvent(e2).withEvent(e1).build(), | ||
new UserPrefs()); | ||
|
||
Model expectedModel = new ModelManager( | ||
new SchedulerBuilder().withEvent(e1).withEvent(e2).build(), | ||
new UserPrefs()); | ||
|
||
assertCommandSuccess(new SortCommand(), givenModel, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_customEvents_success() { | ||
String expectedMessage = SortCommand.MESSAGE_SUCCESS; | ||
|
||
// Events are build with default date, end time | ||
// e1 have earlier date, later time | ||
// e2 have later date, earlier time | ||
// e1 is expected to come before e2 | ||
Event e1 = new EventBuilder() | ||
.withName("e1") | ||
.withDate("2023-05-01") | ||
.withStartTime("21:43") | ||
.build(); | ||
Event e2 = new EventBuilder() | ||
.withName("e2") | ||
.withDate("2023-05-02") | ||
.withStartTime("12:34") | ||
.build(); | ||
|
||
Model givenModel = new ModelManager( | ||
new SchedulerBuilder().withEvent(e2).withEvent(e1).build(), | ||
new UserPrefs()); | ||
|
||
Model expectedModel = new ModelManager( | ||
new SchedulerBuilder().withEvent(e1).withEvent(e2).build(), | ||
new UserPrefs()); | ||
|
||
assertCommandSuccess(new SortCommand(), givenModel, expectedMessage, expectedModel); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters