Skip to content

Commit

Permalink
Update tests to follow code standards
Browse files Browse the repository at this point in the history
  • Loading branch information
SlothyCat committed Sep 20, 2024
1 parent 22162d3 commit f8a65e0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 22 deletions.
5 changes: 1 addition & 4 deletions nimbus.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
T | 1 | read book
E | 1 | appointment | 22/8/2024 1700 - 22/8/2024 1900
T | 0 | sleep
D | 0 | quiz | 25/9/2024 1000
E | 0 | floor event | 25/9/2024 1400 - 25/9/2024 1900
44 changes: 34 additions & 10 deletions src/test/java/nimbus/command/AddCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,47 +1,71 @@
package nimbus.command;


import nimbus.ui.TaskList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

import nimbus.exception.WrongInputException;
import nimbus.ui.TaskList;

import static org.junit.jupiter.api.Assertions.*;

/**
* Tests method in add Command
*/
public class AddCommandTest {

/**
* Tests if todoTask can be added correctly
*/
@Test
public void testAddCommandTodoTask() {
public void testAddCommand_todoTask() {
String userInput = "todo Tutorial";
TaskList taskList = new TaskList();
new AddCommand(userInput, taskList).execute();
assertEquals("[T][ ] Tutorial",
taskList.getTaskList().get(0).toString().trim());
}

/**
* Tests if deadlineTask can be added correctly
*/
@Test
public void testAddCommandDeadlineTask() {
public void testAddCommand_deadlineTask() {
String userInput = "deadline Tutorial /by 22/8/2024 1200";
TaskList taskList = new TaskList();
new AddCommand(userInput, taskList).execute();
assertEquals("[D][ ] Tutorial (by: Aug 22 2024 12:00 pm)",
assertEquals("[D][ ] Tutorial (by: Aug 22 2024 12:00 pm)",
taskList.getTaskList().get(0).toString().trim());
}

/**
* Tests if eventTask can be added correctly
*/
@Test
public void testAddCommandEventTask() {
public void testAddCommand_eventTask() {
String userInput = "event appointment /from 22/8/2024 1200 /to 22/8/2024 1400";
TaskList taskList = new TaskList();
new AddCommand(userInput, taskList).execute();
assertEquals("[E][ ] appointment (from: Aug 22 2024 12:00 pm to: Aug 22 2024 2:00 pm)",
taskList.getTaskList().get(0).toString().trim());
}

/**
* Tests if exception thrown if wrong description
*/
@Test
public void testAddCommandWrongDescription() {
public void testAddCommand_wrongDescription() {
String userInput = "random";
TaskList taskList = new TaskList();
new AddCommand(userInput, taskList).execute();

WrongInputException exception = assertThrows(WrongInputException.class, () -> {
new AddCommand(userInput, taskList).execute();
});

String expectedMessage = "Sorry Nimbus don't understand what you are saying QwQ \n"
+ "Try using todo, deadline or event!";
assertTrue(exception.getMessage().contains(expectedMessage));

assertEquals(0, taskList.getTaskList().size());
}
}
32 changes: 24 additions & 8 deletions src/test/java/nimbus/command/DeleteCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package nimbus.command;

import nimbus.ui.TaskList;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import nimbus.ui.TaskList;

/**
* Checks if methods in DeleteCommand is working
*/
public class DeleteCommandTest {
/**
* Tests if one task can be deleted
*/
@Test
public void testDeleteCommandOneTask() {
public void testDeleteCommand_oneTask() {
TaskList taskList = new TaskList();
new AddCommand("todo Tutorial", taskList).execute();

Expand All @@ -16,8 +23,11 @@ public void testDeleteCommandOneTask() {
assertEquals(0, taskList.getTaskList().size());
}

/**
* Tests if multiple tasks can be deleted
*/
@Test
public void testDeleteCommandManyTasks() {
public void testDeleteCommand_manyTasks() {
TaskList taskList = new TaskList();
new AddCommand("todo Tutorial", taskList).execute();
new AddCommand("deadline Tutorial /by 22/8/2024 1800", taskList).execute();
Expand All @@ -28,25 +38,31 @@ public void testDeleteCommandManyTasks() {
taskList.getTaskList().get(0).toString().trim());
}

/**
* Tests if delete command can check if it is the wrong input
*/
@Test
public void testDeleteCommandWrongUserInput() {
public void testDeleteCommand_wrongUserInput() {
TaskList taskList = new TaskList();
new AddCommand("todo Tutorial", taskList).execute();
new AddCommand("deadline Tutorial /by 22/8/2024 1800", taskList).execute();

String userInput = "delete";
new DeleteCommand(userInput, taskList).execute();
assertEquals(2,taskList.getTaskList().size());
assertEquals(2, taskList.getTaskList().size());
}

/**
* Tests if delete command can check if index given is out of range
*/
@Test
public void testDeleteCommandOutOfRange() {
public void testDeleteCommand_outOfRange() {
TaskList taskList = new TaskList();
new AddCommand("todo Tutorial", taskList).execute();
new AddCommand("deadline Tutorial /by 22/8/2024 1800", taskList).execute();

String userInput = "delete 3";
new DeleteCommand(userInput, taskList).execute();
assertEquals(2,taskList.getTaskList().size());
assertEquals(2, taskList.getTaskList().size());
}
}

0 comments on commit f8a65e0

Please sign in to comment.