Skip to content

Commit

Permalink
Merge pull request #2 from raydenlim/branch-A-Assertions
Browse files Browse the repository at this point in the history
A-Assertions
  • Loading branch information
raydenlim authored Sep 15, 2023
2 parents 30a4a56 + e80e73b commit a1291c5
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 15 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ dependencies {
}

configurations {
// Define a configuration named 'runtime' that selects the appropriate classifier
runtime {
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
Expand Down Expand Up @@ -72,15 +71,17 @@ test {
}

application {
mainClass.set("duke.Duke")
mainClass.set("app.Launcher")
}

shadowJar {
archiveBaseName = "duke"
archiveFileName = 'duke.jar'
archiveClassifier = null
dependsOn("distZip", "distTar")
}

run {
standardInput = System.in
enableAssertions = true;
}
13 changes: 5 additions & 8 deletions data/tasks.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
[T][ ] hehe
[T][ ] lol
[A][ ] lol
[A][ ] move
[A][ ] move1
[A][ ] move2
[A][ ] move 21
[A][ ] move22
[A][ ] hehe
[D][ ] (by: now)
[A][ ] airubg
[D][ ] ugbia (by: efuba woubjs)
[A][ ] ff
2 changes: 1 addition & 1 deletion src/main/java/Command/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public AddCommand(Task taskToAdd) {
*/
@Override
public String execute(TaskList taskList, Ui ui, Storage storage) throws DukeException {
assert taskToAdd != null : "Task to add cannot be null.";
taskList.addTask(taskToAdd);
storage.saveTask(taskList.getTasks());
return ui.showTaskAdded(taskToAdd, taskList.getTaskCount());

}
}
2 changes: 2 additions & 0 deletions src/main/java/Command/DeadLineCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public DeadLineCommand(String description, String by) {
*/
@Override
public String execute(TaskList taskList, Ui ui, Storage storage) throws DukeException {
assert description != null : "Description cannot be null.";
assert by != null : "by attribute cannot be null.";
DeadLine deadline = new DeadLine(description, by);
taskList.addTask(deadline);
storage.saveTask(taskList.getTasks());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/Command/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public DeleteCommand(int taskIndex) {
@Override
public String execute(TaskList taskList, Ui ui, Storage storage) throws DukeException {
try {
assert taskIndex > 0 && taskIndex < taskList.getTaskCount() : "Invalid task index/ out of range";
Task removedTask = taskList.deleteTask(taskIndex);
storage.saveTask(taskList.getTasks());
return ui.showDeletedTask(removedTask, taskList.getTaskCount());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/Command/EchoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public EchoCommand(String message) {
*/
@Override
public String execute(TaskList taskList, Ui ui, Storage storage) throws DukeException {
assert message != null : "You cant echo nothing :(";
return ui.showEcho(message);
}
}
3 changes: 3 additions & 0 deletions src/main/java/Command/EventCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public EventCommand(String description, String from, String to) {
*/
@Override
public String execute(TaskList taskList, Ui ui, Storage storage) throws DukeException {
assert description != null : "Description cannot be null.";
assert from != null : "from attribute cannot be null.";
assert to != null : "to attribute cannot be null.";
Event event = new Event(description, from, to);
taskList.addTask(event);
storage.saveTask(taskList.getTasks());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/Command/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public FindCommand(String keyword) {
*/
@Override
public String execute(TaskList taskList, Ui ui, Storage storage) throws DukeException {
assert keyword != null : "Search word cannot be null.";
return ui.showMatchingTasks(taskList.findTasks(keyword));
}
}
1 change: 1 addition & 0 deletions src/main/java/Command/MarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public String execute(TaskList taskList, Ui ui, Storage storage) throws DukeExce
if (taskIndex < 0 || taskIndex >= taskList.getTaskCount()) {
throw new DukeException("Invalid task index.");
}
assert taskIndex >= 0 && taskIndex < taskList.getTaskCount() : "Invalid task index.";

try {
Task taskToMark = taskList.getTasks().get(taskIndex);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/Command/ToDoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public ToDoCommand(Task taskToDo) {
*/
@Override
public String execute(TaskList taskList, Ui ui, Storage storage) throws DukeException {
assert taskToDo != null : "Task todo cannot be null.";
taskList.addTask(taskToDo);
storage.saveTask(taskList.getTasks());
return ui.showTaskAdded(taskToDo, taskList.getTaskCount());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/Command/UnmarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public String execute(TaskList taskList, Ui ui, Storage storage) throws DukeExce
if (taskIndex < 0 || taskIndex >= taskList.getTaskCount()) {
throw new DukeException("Invalid task index.");
}
assert taskIndex >= 0 && taskIndex < taskList.getTaskCount() : "Invalid task index.";

try {
Task taskToUnmark = taskList.getTasks().get(taskIndex);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/Duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public Duke(String filePath) throws DukeException, FileNotFoundException {
scanner = new Scanner(System.in);
taskList = new TaskList();
ui = new Ui();
assert directoryPath != null : "Directory path cannot be empty";
assert textPath != null : "Text path cannot be empty";
storage = new Storage(directoryPath, textPath, taskList);
storage.loadTasks();
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/Parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ public static Command parse(String input) throws DukeException {
String[] words = input.split(" ");
String command = words[0].toLowerCase();

if (words.length < 2 && !command.equals("bye") && !command.equals("list") && !command.equals("help")) {
throw new DukeException("The description of the command cannot be empty.");
}

switch (command) {
case "bye":
return new ByeCommand();
Expand All @@ -108,6 +104,9 @@ public static Command parse(String input) throws DukeException {
Task todoTask = new ToDo(todoDesc);
return new ToDoCommand(todoTask);
case "add":
if (words.length < 2) {
throw new DukeException("Please specify a task to add.");
}
String addDesc = input.substring(4).trim();
Task addTask = new Add(addDesc);
return new AddCommand(addTask);
Expand Down Expand Up @@ -150,6 +149,9 @@ public static Command parse(String input) throws DukeException {
String echoText = input.substring(5).trim(); // Extract the text
return new EchoCommand(echoText);
case "delete":
if (words.length < 2) {
throw new DukeException("Please provide me a task index to delete");
}
int taskNumToDel = Integer.parseInt(words[1]) - 1;
return new DeleteCommand(taskNumToDel);
case "help":
Expand Down

0 comments on commit a1291c5

Please sign in to comment.