Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hoperawr committed Aug 27, 2020
1 parent 7103406 commit 716d80f
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Duke.Duke project template
# duke.duke project template

This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it.

Expand All @@ -15,7 +15,7 @@ Prerequisites: JDK 11, update Intellij to the most recent version.
1. Click `Open or Import`.
1. Select the project directory, and click `OK`
1. If there are any further prompts, accept the defaults.
1. After the importing is complete, locate the `src/main/java/Duke.Duke.java` file, right-click it, and choose `Run Duke.Duke.main()`. If the setup is correct, you should see something like the below:
1. After the importing is complete, locate the `src/main/java/duke.duke.java` file, right-click it, and choose `Run duke.duke.main()`. If the setup is correct, you should see something like the below:
```
Hello from
____ _
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package Duke;
package duke;

import java.time.LocalDate;
import java.time.LocalTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package Duke;
package duke;

import java.util.Scanner;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package Duke;
package duke;

public class DukeException extends Exception{
public DukeException(String message){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package Duke;
package duke;

import java.time.LocalDate;
import java.time.LocalTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package Duke;
package duke;

import java.io.FileWriter;
import java.nio.file.Files;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package Duke;
package duke;

public class Task {
boolean completed = false;
Expand All @@ -16,6 +16,7 @@ public class Task {
}



public Task completedTask(){
completed = true;
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package Duke;
package duke;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -81,4 +81,13 @@ public int countList(){
public void deleteAll(){
list = new ArrayList<>();
}


public static void main(String[] args) throws DukeException {
TaskList tasklist = new TaskList(new ArrayList<>());
tasklist.add("todo eat");
ToDo temp1 = new ToDo("eat");
ToDo temp2 = new ToDo("eat");
System.out.println(temp1.equals(temp2));
}
}
62 changes: 62 additions & 0 deletions src/main/java/duke/TaskListTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package duke;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.*;
import java.util.ArrayList;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TaskListTest {
TaskList taskList;

@BeforeEach
public void setUp(){
taskList = new TaskList(new ArrayList<>());
}


@Test
public void dummyTest(){
assertEquals(2, 2);
}

@Test
public void testAddToDo() throws DukeException {
taskList.add("todo eat");
assertEquals(taskList.countList(),1);
}

@Test
public void testAddDeadline() throws DukeException {
taskList.add("deadline /by 27/08/2020 2359");
assertEquals(taskList.countList(),1);
}

@Test
public void testAddEvent() throws DukeException {
taskList.add("event sleep /at 28/08/2020 0000-0800");
assertEquals(taskList.countList(),1);
}

@Test
public void delete() throws DukeException {
taskList.add("event sleep /at 28/08/2020 0000-0800");
taskList.add("deadline /by 27/08/2020 2359");
taskList.delete("delete 1");
assertEquals(taskList.countList(),1);
}

@Test
public void deleteAll() throws DukeException {
taskList.add("event sleep /at 28/08/2020 0000-0800");
taskList.add("deadline /by 27/08/2020 2359");
taskList.add("todo eat");
taskList.delete("delete all");
assertEquals(taskList.countList(),0);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package Duke;
package duke;

public class ToDo extends Task{

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Duke/Ui.java → src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package Duke;
package duke;

import java.util.List;

Expand Down
4 changes: 2 additions & 2 deletions text-ui-test/runtest.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ del ACTUAL.TXT
set JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8

REM compile the code into the bin folder
javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\Duke\*.java
javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\duke\*.java
IF ERRORLEVEL 1 (
echo ********** BUILD FAILURE **********
exit /b 1
)
REM no error here, errorlevel == 0

REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT
java -classpath ..\bin Duke.Duke < input.txt > ACTUAL.TXT
java -classpath ..\bin duke.duke < input.txt > ACTUAL.TXT

REM compare the output to the expected output
FC ACTUAL.TXT EXPECTED.TXT

0 comments on commit 716d80f

Please sign in to comment.