Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assertions to Deadline and Event #1

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/duke/command/AddDeadlineCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class AddDeadlineCommand extends Command {
* @param by The due date of the deadline task.
*/
public AddDeadlineCommand(String taskDescription, String by) {
assert by.split(" ").length == 3 : "by String should contain should have 3 fields";
assert by.split(" ")[0].length() == 3 : "Month is represented as 3 letters";
assert by.split(" ")[1].length() <= 2 : "Date format should not have more than 2 characters";
assert by.split(" ")[2].length() == 4 : "Year format should have 4 characters";
this.taskDescription = taskDescription;
this.by = by;
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/duke/command/AddEventCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public class AddEventCommand extends Command {
*/
public AddEventCommand(String taskDescription, String from, String to) {
this.taskDescription = taskDescription;
assert from.split(" ").length == 3 : "by String should contain should have 3 fields";
assert from.split(" ")[0].length() == 3 : "Month is represented as 3 letters";
assert from.split(" ")[1].length() <= 2 : "Date format should not have more than 2 characters";
assert from.split(" ")[2].length() == 4 : "Year format should have 4 characters";
assert to.split(" ").length == 3 : "by String should contain should have 3 fields";
assert to.split(" ")[0].length() == 3 : "Month is represented as 3 letters";
assert to.split(" ")[1].length() <= 2 : "Date format should not have more than 2 characters";
assert to.split(" ")[2].length() == 4 : "Year format should have 4 characters";
this.from = from;
this.to = to;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/duke/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static Command parse(String input) throws DukeException {
if (eventData.length < 2) {
throw new DukeException("An event requires a /from (timedate) descriptor");
}

String[] period = eventData[1].split("/to ");
if (period.length < 2) {
throw new DukeException("An event requires a /to (timedate) descriptor");
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/duke/task/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public class Deadline extends Task {
*/
public Deadline(String task, boolean isDone, String due) throws DateTimeException {
super(task, isDone);
assert due.split(" ").length == 3 : "by String should contain should have 3 fields";
assert due.split(" ")[0].length() == 3 : "Month is represented as 3 letters";
assert due.split(" ")[1].length() <= 2 : "Date format should not have more than 2 characters";
assert due.split(" ")[2].length() == 4 : "Year format should have 4 characters";
this.due = due;
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/duke/task/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public class Event extends Task {
*/
public Event(String task, boolean isDone, String from, String to) throws DateTimeException {
super(task, isDone);
assert from.split(" ").length == 3 : "by String should contain should have 3 fields";
assert from.split(" ")[0].length() == 3 : "Month is represented as 3 letters";
assert from.split(" ")[1].length() <= 2 : "Date format should not have more than 2 characters";
assert from.split(" ")[2].length() == 4 : "Year format should have 4 characters";
assert to.split(" ").length == 3 : "by String should contain should have 3 fields";
assert to.split(" ")[0].length() == 3 : "Month is represented as 3 letters";
assert to.split(" ")[1].length() <= 2 : "Date format should not have more than 2 characters";
assert to.split(" ")[2].length() == 4 : "Year format should have 4 characters";
this.from = from;
this.to = to;
}
Expand Down