Skip to content

Commit

Permalink
Improve test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Goh-Li-Ting committed Sep 22, 2023
1 parent c906f96 commit d2817e4
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 33 deletions.
11 changes: 0 additions & 11 deletions src/main/java/chatbuddy/task/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

/**
* Deadline represents a Deadline object in ChatBuddy.
Expand All @@ -29,16 +28,6 @@ public Deadline(String description, LocalDate by) {
this.by = by;
}

/**
* Returns a boolean representing whether the task is due within a week.
*
* @return True if the deadline is due within a week, false otherwise.
*/
@Override
public boolean isWithinAWeek() {
return by.isBefore(LocalDate.now().plus(1, ChronoUnit.WEEKS));
}

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by.format(FORMATTER_DATE_OUTPUT) + ")";
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/chatbuddy/task/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

/**
* Event represents an Event object in ChatBuddy.
Expand Down Expand Up @@ -33,16 +32,6 @@ public Event(String description, LocalDateTime from, LocalDateTime to) {
this.to = to;
}

/**
* Returns a boolean representing whether the event starts within a week.
*
* @return True if the event starts within a week, false otherwise.
*/
@Override
public boolean isWithinAWeek() {
return from.isBefore(LocalDateTime.now().plus(1, ChronoUnit.WEEKS));
}

@Override
public String toString() {
return String.format(
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/chatbuddy/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@ public String getTag() {
return tag.equals("") ? "" : " #" + tag;
}

/**
* Returns a boolean representing whether the task is due or an event starts within a week.
*
* @return True if task is due or starts within a week, false otherwise.
*/
public boolean isWithinAWeek() {
return false;
}

@Override
public String toString() {
return String.format("[%1s] %2s", getStatusIcon(), description) + getTag();
Expand Down
113 changes: 111 additions & 2 deletions src/test/java/chatbuddy/parser/ParserTest.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,136 @@
package chatbuddy.parser;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.fail;

import org.junit.jupiter.api.Test;

import chatbuddy.ChatBuddyException;
import chatbuddy.command.Command;
import chatbuddy.command.DeadlineCommand;
import chatbuddy.command.DeleteCommand;
import chatbuddy.command.EventCommand;
import chatbuddy.command.ExitCommand;
import chatbuddy.command.FindCommand;
import chatbuddy.command.ListCommand;
import chatbuddy.command.MarkCommand;
import chatbuddy.command.TagCommand;
import chatbuddy.command.TodoCommand;
import chatbuddy.command.UnmarkCommand;

public class ParserTest {
@Test
public void parse_listCommandWord_listCommandReturned() {
try {
Command command = Parser.parse("list");
assertEquals(ListCommand.class, command.getClass());
assertInstanceOf(ListCommand.class, command);
} catch (ChatBuddyException e) {
fail();
}

try {
Command command = Parser.parse("list abcdefg");
assertEquals(ListCommand.class, command.getClass());
assertInstanceOf(ListCommand.class, command);
} catch (ChatBuddyException e) {
fail();
}
}

@Test
public void parse_exitCommandWord_exitCommandReturned() {
try {
Command command = Parser.parse("bye");
assertInstanceOf(ExitCommand.class, command);
} catch (ChatBuddyException e) {
fail();
}
}

@Test
public void parse_todoCommandWord_todoCommandReturned() {
try {
Command command = Parser.parse("todo hw");
assertInstanceOf(TodoCommand.class, command);
} catch (ChatBuddyException e) {
fail();
}
}

@Test
public void parse_deadlineCommandWord_deadlineCommandReturned() {
try {
Command command = Parser.parse("deadline do homework /by 02/09/2023");
assertInstanceOf(DeadlineCommand.class, command);
} catch (ChatBuddyException e) {
fail();
}
}

@Test
public void parse_deleteCommandWord_deleteCommandReturned() {
try {
Command command = Parser.parse("delete 1");
assertInstanceOf(DeleteCommand.class, command);
} catch (ChatBuddyException e) {
fail();
}
}

@Test
public void parse_markCommandWord_markCommandReturned() {
try {
Command command = Parser.parse("mark 1");
assertInstanceOf(MarkCommand.class, command);
} catch (ChatBuddyException e) {
fail();
}
}

@Test
public void parse_unmarkCommandWord_unmarkCommandReturned() {
try {
Command command = Parser.parse("unmark 1");
assertInstanceOf(UnmarkCommand.class, command);
} catch (ChatBuddyException e) {
fail();
}
}

@Test
public void parse_findCommandWord_findCommandReturned() {
try {
Command command = Parser.parse("find hw");
assertInstanceOf(FindCommand.class, command);
} catch (ChatBuddyException e) {
fail();
}
}

@Test
public void parse_tagCommandWord_tagCommandReturned() {
try {
Command command = Parser.parse("tag 1 urgent");
assertInstanceOf(TagCommand.class, command);
} catch (ChatBuddyException e) {
fail();
}

try {
Command command = Parser.parse("tag 1");
assertInstanceOf(TagCommand.class, command);
} catch (ChatBuddyException e) {
fail();
}
}

@Test
public void parse_eventCommandWord_eventCommandReturned() {
try {
Command command = Parser.parse(
"event birthday party /from 03/09/2023 1400 /to 03/09/2023 1700"
);
assertInstanceOf(EventCommand.class, command);
} catch (ChatBuddyException e) {
fail();
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/chatbuddy/task/EventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public class EventTest {
private LocalDateTime to = LocalDateTime.parse("01/09/2023 1732", DateTimeFormatter.ofPattern("dd/MM/yyyy HHmm"));
private Event event = new Event("event1", from, to);

@Test
public void toString_correctString() {
assertEquals("[E][ ] event1 (from: 01 Sep 2023 1000 to: 01 Sep 2023 1732)", event.toString());
}

@Test
public void getInformationForSaving() {
assertEquals("E | 0 | event1 | | 01/09/2023 1000 | 01/09/2023 1732", event.getInformationForSaving());
Expand Down

0 comments on commit d2817e4

Please sign in to comment.