Skip to content

Commit

Permalink
Fix minor typing errors and clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
kswk committed Sep 16, 2020
1 parent a9a8699 commit cff1396
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static Command parse(String input)
if (commandWordArray.length != 1) {
return new UnknownCommand(firstWord);
}
return new ByeCommand(firstWord, true);
return new ByeCommand(firstWord);
case LIST:
if (commandWordArray.length != 1) {
return new UnknownCommand(firstWord);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/duke/command/ByeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ public class ByeCommand extends Command {
/**
* Class constructor.
* @param command String parsed by Parser object.
* @param isExit Boolean indicating if chat bot should shut down.
*/
public ByeCommand(String command, boolean isExit) {
public ByeCommand(String command) {
super(command, true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/command/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public String execute(Storage storage, TaskList tasks, Ui ui) {

@Override
public boolean equals(Object obj) {
return obj instanceof ListCommand;
return obj instanceof HelpCommand;
}
}
34 changes: 25 additions & 9 deletions src/test/java/duke/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,67 @@
import duke.command.DeleteCommand;
import duke.command.DoneCommand;
import duke.command.FindCommand;
import duke.command.HelpCommand;
import duke.command.ListCommand;
import duke.command.UnknownCommand;
import duke.exception.DukeException;
import duke.exception.DukeEmptyArgumentException;
import duke.exception.DukeEmptyDescriptionException;

public class ParserTest {

@Test
public void byeTest() throws DukeException {
public void byeTest() throws DukeEmptyArgumentException,
DukeEmptyDescriptionException {
Command c = Parser.parse("bye");
assertEquals(c, new ByeCommand("bye", true));
assertEquals(c, new ByeCommand("bye"));
}

@Test
public void listTest() throws DukeException {
public void listTest() throws DukeEmptyArgumentException,
DukeEmptyDescriptionException {
Command c = Parser.parse("list");
assertEquals(c, new ListCommand("list"));
}

@Test
public void doneTest() throws DukeException {
public void doneTest() throws DukeEmptyArgumentException,
DukeEmptyDescriptionException {
Command c = Parser.parse("done 1");
assertEquals(c, new DoneCommand("done", "1"));
}

@Test
public void deleteTest() throws DukeException {
public void deleteTest() throws DukeEmptyArgumentException,
DukeEmptyDescriptionException {
Command c = Parser.parse("delete 1");
assertEquals(c, new DeleteCommand("delete", "1"));
}

@Test
public void addTest() throws DukeException {
public void addTest() throws DukeEmptyArgumentException,
DukeEmptyDescriptionException {
Command c = Parser.parse("todo borrow book");
assertEquals(c, new AddCommand("todo", "borrow book"));
}

@Test
public void unknownTest() throws DukeException {
public void unknownTest() throws DukeEmptyArgumentException,
DukeEmptyDescriptionException {
Command c = Parser.parse("unknown");
assertEquals(c, new UnknownCommand("unknown"));
}

@Test
public void findTest() throws DukeException {
public void findTest() throws DukeEmptyArgumentException,
DukeEmptyDescriptionException {
Command c = Parser.parse("find book");
assertEquals(c, new FindCommand("find", "book"));
}

@Test
public void helpTest() throws DukeEmptyArgumentException,
DukeEmptyDescriptionException {
Command c = Parser.parse("help");
assertEquals(c, new HelpCommand("help"));
}
}

0 comments on commit cff1396

Please sign in to comment.