From d9004384ed4992200968a8ea06ec1f96ff65a384 Mon Sep 17 00:00:00 2001 From: Tuva Aarseth Date: Thu, 15 Aug 2024 09:36:20 +0200 Subject: [PATCH 01/12] Created domain model. --- domain-model.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 domain-model.md diff --git a/domain-model.md b/domain-model.md new file mode 100644 index 000000000..d3d0dd1e9 --- /dev/null +++ b/domain-model.md @@ -0,0 +1,59 @@ +# Todo list core + +## Core Requirements + +- I want to add tasks to my todo list. +- I want to see all the tasks in my todo list. +- I want to change the status of a task between incomplete and complete. +- I want to be able to get only the complete tasks. +- I want to be able to get only the incomplete tasks. +- I want to search for a task and receive a message that says it wasn't found if it doesn't exist. +- I want to remove tasks from my list. +- I want to see all the tasks in my list ordered alphabetically in ascending order. +- I want to see all the tasks in my list ordered alphabetically in descending order. + + +## TodoList Class + + + +| Member variable | Data type | +|-----------------|-------------------| +| `task` | `Task` | +| `todoList` | `ArrayList` | +| | | + +#### Task Class +| Member variable | Data type | +|-----------------|-----------| +| `taskName` | `String` | +| `taskStatus` | `String` | + + + + +| Method | Scenario | Output | +|---------------------------------|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------| +| `addTask(task)` | Task is added to todoList
Task is not added to todoList | `Return` true
`Return` false | +| `getTasks(todoList)` | todoList is not empty
todoList is empty | `Return` all tasks in todo list
`Return` "Todo list is empty." | +| `getCompletedTasks(todoList)` | todoList contains completed tasks
todoList does not contain completed tasks | `Return` tasks with status 'complete'
`Return` "No completed tasks in todo list." | +| `getIncompletedTasks(todoList)` | todoList contains uncompleted tasks
todoList does not contain uncompleted tasks | `Return` tasks with status 'incomplete'
`Return` "No uncompleted tasks in todo list." | +| `searchTask(todoList)` | Task exists in todoList
Task does not exist in todoList | `Return` task
`Return` "Task not found." | +| `changeStatus(task)` | Status is changed
Status remains unchanged | `Return` "Task status changed"
`Return` "Task status remains unchanged" | +| `removeTask` | Task exist in todoList
Task does not exist in todoList | `Return` "Task removed from todo list"
`Return` "Task not found." | +| `getTasksAscending` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in ascending order
`Return` "Todo list is empty." | +| `getTasksDescending` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in descending order
`Return` "Todo list is empty." | + + + + + + + + + + + + + +# Todo list extension \ No newline at end of file From c64638b7ca8a61fe02f249156c8eefa603741f32 Mon Sep 17 00:00:00 2001 From: Tuva Aarseth Date: Thu, 15 Aug 2024 09:48:44 +0200 Subject: [PATCH 02/12] Created test and dummy function for adding a task. --- domain-model.md | 2 +- src/main/java/com/booleanuk/core/TodoList.java | 8 ++++++++ src/test/java/com/booleanuk/core/TodoListTest.java | 8 ++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/domain-model.md b/domain-model.md index d3d0dd1e9..b1ed27b20 100644 --- a/domain-model.md +++ b/domain-model.md @@ -34,7 +34,7 @@ | Method | Scenario | Output | |---------------------------------|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------| -| `addTask(task)` | Task is added to todoList
Task is not added to todoList | `Return` true
`Return` false | +| `addTask(String)` | Task is added to todoList
Task is not added to todoList | `Return` true
`Return` false | | `getTasks(todoList)` | todoList is not empty
todoList is empty | `Return` all tasks in todo list
`Return` "Todo list is empty." | | `getCompletedTasks(todoList)` | todoList contains completed tasks
todoList does not contain completed tasks | `Return` tasks with status 'complete'
`Return` "No completed tasks in todo list." | | `getIncompletedTasks(todoList)` | todoList contains uncompleted tasks
todoList does not contain uncompleted tasks | `Return` tasks with status 'incomplete'
`Return` "No uncompleted tasks in todo list." | diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index 675adaf0b..d6debc9fd 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -2,4 +2,12 @@ public class TodoList { + public class Task{ + + } + + public Boolean addTask(String taskName){ + return true; + } + } diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 0bef779a4..8f684cba7 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -5,9 +5,9 @@ class TodoListTest { @Test - public void exampleTest() { - String hello = "Hello"; - Assertions.assertEquals("Hello", hello); - Assertions.assertNotEquals("Goodbye", hello); + public void testAddTask() { + TodoList todoList = new TodoList(); + + Assertions.assertTrue(todoList.addTask("Test task 1")); } } From 434f63b7121e2c97c67df5234a2ffbac0b1c2edc Mon Sep 17 00:00:00 2001 From: Tuva Aarseth Date: Thu, 15 Aug 2024 10:30:22 +0200 Subject: [PATCH 03/12] Created test and dummy function for getting tasks. --- .../java/com/booleanuk/core/TodoList.java | 8 +++++++ .../java/com/booleanuk/core/TodoListTest.java | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index d6debc9fd..80f50e683 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -1,13 +1,21 @@ package com.booleanuk.core; +import java.util.ArrayList; + public class TodoList { public class Task{ } + ArrayList todoList = new ArrayList<>(); + public Boolean addTask(String taskName){ return true; } + public String getTasks(ArrayList todoList){ + return "Todo list is empty"; + } + } diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 8f684cba7..b44968578 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -3,6 +3,8 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.ArrayList; + class TodoListTest { @Test public void testAddTask() { @@ -10,4 +12,23 @@ public void testAddTask() { Assertions.assertTrue(todoList.addTask("Test task 1")); } + + @Test + public void testGetTasks(){ + TodoList todoList = new TodoList(); + // Test if todo list is empty + Assertions.assertEquals("Todo list is empty", todoList.getTasks(todoList.todoList)); + + todoList.addTask("Test task 1"); + todoList.addTask("Test task 2"); + todoList.addTask("Test task 3"); + + ArrayList test = new ArrayList<>(); + test.add("Test task 1"); + test.add("Test task 2"); + test.add("Test task 3"); + // Test if todo list is not empty + Assertions.assertEquals(test.toString(), todoList.getTasks(todoList.todoList)); + } + } From f9d18081a2d3a83ea922335f0e650ecbe1fc8662 Mon Sep 17 00:00:00 2001 From: Tuva Aarseth Date: Thu, 15 Aug 2024 10:45:41 +0200 Subject: [PATCH 04/12] Created tests and dummy functions for task status change and get completed tasks. --- domain-model.md | 4 +-- .../java/com/booleanuk/core/TodoList.java | 10 ++++++- .../java/com/booleanuk/core/TodoListTest.java | 28 ++++++++++++++++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/domain-model.md b/domain-model.md index b1ed27b20..8f537ee9f 100644 --- a/domain-model.md +++ b/domain-model.md @@ -39,8 +39,8 @@ | `getCompletedTasks(todoList)` | todoList contains completed tasks
todoList does not contain completed tasks | `Return` tasks with status 'complete'
`Return` "No completed tasks in todo list." | | `getIncompletedTasks(todoList)` | todoList contains uncompleted tasks
todoList does not contain uncompleted tasks | `Return` tasks with status 'incomplete'
`Return` "No uncompleted tasks in todo list." | | `searchTask(todoList)` | Task exists in todoList
Task does not exist in todoList | `Return` task
`Return` "Task not found." | -| `changeStatus(task)` | Status is changed
Status remains unchanged | `Return` "Task status changed"
`Return` "Task status remains unchanged" | -| `removeTask` | Task exist in todoList
Task does not exist in todoList | `Return` "Task removed from todo list"
`Return` "Task not found." | +| `changeStatus(String)` | Status is changed
Status remains unchanged | `Return` "Task status changed"
`Return` "Task status remains unchanged" | +| `removeTask(String)` | Task exist in todoList
Task does not exist in todoList | `Return` "Task removed from todo list"
`Return` "Task not found." | | `getTasksAscending` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in ascending order
`Return` "Todo list is empty." | | `getTasksDescending` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in descending order
`Return` "Todo list is empty." | diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index 80f50e683..3d13dc3a8 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -15,7 +15,15 @@ public Boolean addTask(String taskName){ } public String getTasks(ArrayList todoList){ - return "Todo list is empty"; + return "Todo list is empty."; + } + + public String changeStatus(String taskName){ + return "Task status changed."; + } + + public String getCompletedTasks(ArrayList todoList){ + return "No completed tasks in todo list."; } } diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index b44968578..12f40d9a8 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -17,7 +17,7 @@ public void testAddTask() { public void testGetTasks(){ TodoList todoList = new TodoList(); // Test if todo list is empty - Assertions.assertEquals("Todo list is empty", todoList.getTasks(todoList.todoList)); + Assertions.assertEquals("Todo list is empty.", todoList.getTasks(todoList.todoList)); todoList.addTask("Test task 1"); todoList.addTask("Test task 2"); @@ -31,4 +31,30 @@ public void testGetTasks(){ Assertions.assertEquals(test.toString(), todoList.getTasks(todoList.todoList)); } + @Test + public void testChangeStatus() { + TodoList todoList = new TodoList(); + todoList.addTask("Test task 1"); + Assertions.assertEquals("Task status changed", todoList.changeStatus("Test task 1")); + + } + + @Test + public void testGetCompletedTasks() { + TodoList todoList = new TodoList(); + Assertions.assertEquals("No completed tasks in todo list.", todoList.getCompletedTasks(todoList.todoList)); + + + todoList.addTask("Test task 1"); + todoList.addTask("Test task 2"); + todoList.addTask("Test task 3"); + + todoList.changeStatus("Test task 1"); + + + Assertions.assertEquals("[Test task 1]", todoList.getCompletedTasks(todoList.todoList)); + } + + + } From 2d0ccf10aa1d35f5eaded537ac1ccb9b3c8eaf42 Mon Sep 17 00:00:00 2001 From: Tuva Aarseth Date: Thu, 15 Aug 2024 10:50:04 +0200 Subject: [PATCH 05/12] Created test and dummy function for getting uncompleted tasks. --- domain-model.md | 2 +- .../java/com/booleanuk/core/TodoList.java | 4 ++++ .../java/com/booleanuk/core/TodoListTest.java | 23 ++++++++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/domain-model.md b/domain-model.md index 8f537ee9f..45ad75826 100644 --- a/domain-model.md +++ b/domain-model.md @@ -37,7 +37,7 @@ | `addTask(String)` | Task is added to todoList
Task is not added to todoList | `Return` true
`Return` false | | `getTasks(todoList)` | todoList is not empty
todoList is empty | `Return` all tasks in todo list
`Return` "Todo list is empty." | | `getCompletedTasks(todoList)` | todoList contains completed tasks
todoList does not contain completed tasks | `Return` tasks with status 'complete'
`Return` "No completed tasks in todo list." | -| `getIncompletedTasks(todoList)` | todoList contains uncompleted tasks
todoList does not contain uncompleted tasks | `Return` tasks with status 'incomplete'
`Return` "No uncompleted tasks in todo list." | +| `getUncompletedTasks(todoList)` | todoList contains uncompleted tasks
todoList does not contain uncompleted tasks | `Return` tasks with status 'incomplete'
`Return` "No uncompleted tasks in todo list." | | `searchTask(todoList)` | Task exists in todoList
Task does not exist in todoList | `Return` task
`Return` "Task not found." | | `changeStatus(String)` | Status is changed
Status remains unchanged | `Return` "Task status changed"
`Return` "Task status remains unchanged" | | `removeTask(String)` | Task exist in todoList
Task does not exist in todoList | `Return` "Task removed from todo list"
`Return` "Task not found." | diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index 3d13dc3a8..9e9f8a2e5 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -26,4 +26,8 @@ public String getCompletedTasks(ArrayList todoList){ return "No completed tasks in todo list."; } + public String getUncompletedTasks(ArrayList todoList){ + return "No uncompleted tasks in todo list."; + } + } diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 12f40d9a8..f07415ecf 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -42,19 +42,36 @@ public void testChangeStatus() { @Test public void testGetCompletedTasks() { TodoList todoList = new TodoList(); - Assertions.assertEquals("No completed tasks in todo list.", todoList.getCompletedTasks(todoList.todoList)); - todoList.addTask("Test task 1"); todoList.addTask("Test task 2"); todoList.addTask("Test task 3"); + Assertions.assertEquals("No completed tasks in todo list.", todoList.getCompletedTasks(todoList.todoList)); todoList.changeStatus("Test task 1"); - Assertions.assertEquals("[Test task 1]", todoList.getCompletedTasks(todoList.todoList)); } + @Test + public void testGetUncompletedTasks() { + TodoList todoList = new TodoList(); + + todoList.addTask("Test task 1"); + todoList.changeStatus("Test task 1"); + + Assertions.assertEquals("No uncompleted tasks in todo list.", todoList.getUncompletedTasks(todoList.todoList)); + + todoList.addTask("Test task 2"); + todoList.addTask("Test task 3"); + + ArrayList test = new ArrayList<>(); + test.add("Test task 2"); + test.add("Test task 3"); + + Assertions.assertEquals(test.toString(), todoList.getUncompletedTasks(todoList.todoList)); + } + } From 6cfad67ec7996bcce514b9b6653fb15fe4f2e983 Mon Sep 17 00:00:00 2001 From: Tuva Aarseth Date: Thu, 15 Aug 2024 10:54:56 +0200 Subject: [PATCH 06/12] Created test and dummy function for searching for a task. --- domain-model.md | 2 +- src/main/java/com/booleanuk/core/TodoList.java | 4 ++++ src/test/java/com/booleanuk/core/TodoListTest.java | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/domain-model.md b/domain-model.md index 45ad75826..e055bfeb0 100644 --- a/domain-model.md +++ b/domain-model.md @@ -38,7 +38,7 @@ | `getTasks(todoList)` | todoList is not empty
todoList is empty | `Return` all tasks in todo list
`Return` "Todo list is empty." | | `getCompletedTasks(todoList)` | todoList contains completed tasks
todoList does not contain completed tasks | `Return` tasks with status 'complete'
`Return` "No completed tasks in todo list." | | `getUncompletedTasks(todoList)` | todoList contains uncompleted tasks
todoList does not contain uncompleted tasks | `Return` tasks with status 'incomplete'
`Return` "No uncompleted tasks in todo list." | -| `searchTask(todoList)` | Task exists in todoList
Task does not exist in todoList | `Return` task
`Return` "Task not found." | +| `searchTask(String)` | Task exists in todoList
Task does not exist in todoList | `Return` task
`Return` "Task not found." | | `changeStatus(String)` | Status is changed
Status remains unchanged | `Return` "Task status changed"
`Return` "Task status remains unchanged" | | `removeTask(String)` | Task exist in todoList
Task does not exist in todoList | `Return` "Task removed from todo list"
`Return` "Task not found." | | `getTasksAscending` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in ascending order
`Return` "Todo list is empty." | diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index 9e9f8a2e5..91e343273 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -30,4 +30,8 @@ public String getUncompletedTasks(ArrayList todoList){ return "No uncompleted tasks in todo list."; } + public String searchTask(String taskName){ + return "Task not found."; + } + } diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index f07415ecf..20c03d155 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -72,6 +72,20 @@ public void testGetUncompletedTasks() { Assertions.assertEquals(test.toString(), todoList.getUncompletedTasks(todoList.todoList)); } + @Test + public void testSearchTask() { + TodoList todoList = new TodoList(); + + Assertions.assertEquals("Task not found.", todoList.searchTask("Test task 1")); + + todoList.addTask("Test task 1"); + todoList.addTask("Test task 2"); + todoList.addTask("Test task 3"); + + + Assertions.assertEquals("[Test task 1]", todoList.searchTask("Test task 1")); + } + } From 5da10b8c2d8aa5645ba131b9041abc827d10eaa0 Mon Sep 17 00:00:00 2001 From: Tuva Aarseth Date: Thu, 15 Aug 2024 10:58:25 +0200 Subject: [PATCH 07/12] Created test and dummy function for removing task. --- domain-model.md | 4 +-- .../java/com/booleanuk/core/TodoList.java | 4 +++ .../java/com/booleanuk/core/TodoListTest.java | 30 ++++++++++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/domain-model.md b/domain-model.md index e055bfeb0..73967c46a 100644 --- a/domain-model.md +++ b/domain-model.md @@ -39,8 +39,8 @@ | `getCompletedTasks(todoList)` | todoList contains completed tasks
todoList does not contain completed tasks | `Return` tasks with status 'complete'
`Return` "No completed tasks in todo list." | | `getUncompletedTasks(todoList)` | todoList contains uncompleted tasks
todoList does not contain uncompleted tasks | `Return` tasks with status 'incomplete'
`Return` "No uncompleted tasks in todo list." | | `searchTask(String)` | Task exists in todoList
Task does not exist in todoList | `Return` task
`Return` "Task not found." | -| `changeStatus(String)` | Status is changed
Status remains unchanged | `Return` "Task status changed"
`Return` "Task status remains unchanged" | -| `removeTask(String)` | Task exist in todoList
Task does not exist in todoList | `Return` "Task removed from todo list"
`Return` "Task not found." | +| `changeStatus(String)` | Status is changed
Status remains unchanged | `Return` "Task status changed."
`Return` "Task status remains unchanged." | +| `removeTask(String)` | Task exist in todoList
Task does not exist in todoList | `Return` "Task removed from todo list."
`Return` "Task not found." | | `getTasksAscending` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in ascending order
`Return` "Todo list is empty." | | `getTasksDescending` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in descending order
`Return` "Todo list is empty." | diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index 91e343273..2978815c2 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -34,4 +34,8 @@ public String searchTask(String taskName){ return "Task not found."; } + public String removeTask(String taskName){ + return "Task not found."; + } + } diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 20c03d155..dc3070164 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -35,7 +35,7 @@ public void testGetTasks(){ public void testChangeStatus() { TodoList todoList = new TodoList(); todoList.addTask("Test task 1"); - Assertions.assertEquals("Task status changed", todoList.changeStatus("Test task 1")); + Assertions.assertEquals("Task status changed.", todoList.changeStatus("Test task 1")); } @@ -86,6 +86,34 @@ public void testSearchTask() { Assertions.assertEquals("[Test task 1]", todoList.searchTask("Test task 1")); } + @Test + public void testRemoveTask() { + TodoList todoList = new TodoList(); + + Assertions.assertEquals("Task not found.", todoList.removeTask("Test task 1")); + + todoList.addTask("Test task 1"); + todoList.addTask("Test task 2"); + todoList.addTask("Test task 3"); + + + Assertions.assertEquals("Task removed from todo list.", todoList.removeTask("Test task 1")); + } + + @Test + public void testRemoveTask() { + TodoList todoList = new TodoList(); + + Assertions.assertEquals("Task not found.", todoList.removeTask("Test task 1")); + + todoList.addTask("Test task 1"); + todoList.addTask("Test task 2"); + todoList.addTask("Test task 3"); + + + Assertions.assertEquals("Task removed from todo list.", todoList.removeTask("Test task 1")); + } + } From 0495416fdb1d5e721502b1eddd420b704aa61918 Mon Sep 17 00:00:00 2001 From: Tuva Aarseth Date: Thu, 15 Aug 2024 11:09:11 +0200 Subject: [PATCH 08/12] Created tests and dummy function for sorting todo list. --- .../java/com/booleanuk/core/TodoList.java | 8 +++++ .../java/com/booleanuk/core/TodoListTest.java | 32 +++++++++++++++---- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index 2978815c2..13bf8b526 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -38,4 +38,12 @@ public String removeTask(String taskName){ return "Task not found."; } + public String getTasksAscending(){ + return "Todo list is empty."; + } + + public String getTasksDescending(){ + return "Todo list is empty."; + } + } diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index dc3070164..1353f2881 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -101,19 +101,39 @@ public void testRemoveTask() { } @Test - public void testRemoveTask() { + public void testGetTasksAscending() { TodoList todoList = new TodoList(); - Assertions.assertEquals("Task not found.", todoList.removeTask("Test task 1")); + Assertions.assertEquals("Todo list is empty.", todoList.getTasksAscending()); - todoList.addTask("Test task 1"); - todoList.addTask("Test task 2"); - todoList.addTask("Test task 3"); + todoList.addTask("C task 1"); + todoList.addTask("A task 2"); + todoList.addTask("F task 3"); + ArrayList test = new ArrayList<>(); + test.add("A task 2"); + test.add("C task 2"); + test.add("F task 2"); - Assertions.assertEquals("Task removed from todo list.", todoList.removeTask("Test task 1")); + Assertions.assertEquals(test.toString(), todoList.getTasksAscending()); } + @Test + public void testGetTasksDescending() { + TodoList todoList = new TodoList(); + + Assertions.assertEquals("Todo list is empty.", todoList.getTasksDescending()); + + todoList.addTask("C task 1"); + todoList.addTask("A task 2"); + todoList.addTask("F task 3"); + ArrayList test = new ArrayList<>(); + test.add("F task 2"); + test.add("C task 2"); + test.add("A task 2"); + + Assertions.assertEquals(test.toString(), todoList.getTasksDescending()); + } } From db14d46b2d1fdf6ccd0d531a72e5d6027e7df84e Mon Sep 17 00:00:00 2001 From: Tuva Aarseth Date: Thu, 15 Aug 2024 17:47:30 +0200 Subject: [PATCH 09/12] Completed core requirements. --- domain-model.md | 22 ++-- .../java/com/booleanuk/core/TodoList.java | 115 +++++++++++++++--- .../java/com/booleanuk/core/TodoListTest.java | 32 ++--- 3 files changed, 129 insertions(+), 40 deletions(-) diff --git a/domain-model.md b/domain-model.md index 73967c46a..44efcd2cd 100644 --- a/domain-model.md +++ b/domain-model.md @@ -32,17 +32,17 @@ -| Method | Scenario | Output | -|---------------------------------|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------| -| `addTask(String)` | Task is added to todoList
Task is not added to todoList | `Return` true
`Return` false | -| `getTasks(todoList)` | todoList is not empty
todoList is empty | `Return` all tasks in todo list
`Return` "Todo list is empty." | -| `getCompletedTasks(todoList)` | todoList contains completed tasks
todoList does not contain completed tasks | `Return` tasks with status 'complete'
`Return` "No completed tasks in todo list." | -| `getUncompletedTasks(todoList)` | todoList contains uncompleted tasks
todoList does not contain uncompleted tasks | `Return` tasks with status 'incomplete'
`Return` "No uncompleted tasks in todo list." | -| `searchTask(String)` | Task exists in todoList
Task does not exist in todoList | `Return` task
`Return` "Task not found." | -| `changeStatus(String)` | Status is changed
Status remains unchanged | `Return` "Task status changed."
`Return` "Task status remains unchanged." | -| `removeTask(String)` | Task exist in todoList
Task does not exist in todoList | `Return` "Task removed from todo list."
`Return` "Task not found." | -| `getTasksAscending` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in ascending order
`Return` "Todo list is empty." | -| `getTasksDescending` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in descending order
`Return` "Todo list is empty." | +| Method | Scenario | Output | +|-------------------------|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------| +| `addTask(String)` | Task is added to todoList
Task is not added to todoList | `Return` true
`Return` false | +| `getTasks()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list
`Return` "Todo list is empty." | +| `getCompletedTasks()` | todoList contains completed tasks
todoList does not contain completed tasks | `Return` tasks with status 'complete'
`Return` "No completed tasks in todo list." | +| `getUncompletedTasks()` | todoList contains uncompleted tasks
todoList does not contain uncompleted tasks | `Return` tasks with status 'incomplete'
`Return` "No uncompleted tasks in todo list." | +| `searchTask(String)` | Task exists in todoList
Task does not exist in todoList | `Return` task
`Return` "Task not found." | +| `changeStatus(String)` | Status is changed
Status remains unchanged | `Return` "Task status changed."
`Return` "Task status remains unchanged." | +| `removeTask(String)` | Task exist in todoList
Task does not exist in todoList | `Return` "Task removed from todo list."
`Return` "Task not found." | +| `getTasksAscending()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in ascending order
`Return` "Todo list is empty." | +| `getTasksDescending()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in descending order
`Return` "Todo list is empty." | diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index 13bf8b526..6e5bdd120 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -1,49 +1,136 @@ package com.booleanuk.core; -import java.util.ArrayList; +import java.util.*; public class TodoList { - public class Task{ - + public static class Task{ + public String taskName; + public String taskStatus; } ArrayList todoList = new ArrayList<>(); public Boolean addTask(String taskName){ + Task task = new Task(); + task.taskName=taskName; + task.taskStatus="Incomplete"; + this.todoList.add(task); return true; } - public String getTasks(ArrayList todoList){ - return "Todo list is empty."; + public String getTasks(){ + if (!this.todoList.isEmpty()){ + ArrayList taskNames = new ArrayList<>(); + for (Task task : todoList) { + taskNames.add(task.taskName); + } + return taskNames.toString(); + }else { + return "Todo list is empty."; + } } - public String changeStatus(String taskName){ - return "Task status changed."; + public String setCompleted(String taskName){ + Task task = new Task(); + task.taskStatus = "Completed"; + task.taskName = taskName; + + for (int i=0;i todoList){ - return "No completed tasks in todo list."; + public String getCompletedTasks(){ + ArrayList completedTasks = new ArrayList<>(); + for (Task task : todoList) { + if (task.taskStatus.equals("Completed")) { + completedTasks.add(task.taskName); + } + } + if (!completedTasks.isEmpty()){ + return completedTasks.toString(); + }else { + return "No completed tasks in todo list."; + } } - public String getUncompletedTasks(ArrayList todoList){ - return "No uncompleted tasks in todo list."; + public String getUncompletedTasks(){ + ArrayList uncompletedTasks = new ArrayList<>(); + for (Task task : todoList) { + if (task.taskStatus.equals("Incomplete")) { + uncompletedTasks.add(task.taskName); + } + } + if (!uncompletedTasks.isEmpty()){ + return uncompletedTasks.toString(); + }else { + return "No uncompleted tasks in todo list."; + } } public String searchTask(String taskName){ + for (Task task : todoList) { + if (taskName.equals(task.taskName)) { + return "Task '" + taskName + "' is " + task.taskStatus; + } + } return "Task not found."; } - public String removeTask(String taskName){ + public String removeTask(String taskName) { + for (int i = 0; i < todoList.size(); i++) { + if (taskName.equals((todoList.get(i)).taskName)) { + todoList.remove(i); + return "Task removed from todo list."; + } + } return "Task not found."; } public String getTasksAscending(){ - return "Todo list is empty."; + if (!this.todoList.isEmpty()){ + ArrayList taskNames = new ArrayList<>(); + for (Task task : todoList) { + taskNames.add(task.taskName); + } + Collections.sort(taskNames); + return taskNames.toString(); + }else { + return "Todo list is empty."; + } } public String getTasksDescending(){ - return "Todo list is empty."; + Comparator reverseComparator = Comparator.reverseOrder(); + if (!this.todoList.isEmpty()){ + ArrayList taskNames = new ArrayList<>(); + for (Task task : todoList) { + taskNames.add(task.taskName); + } + taskNames.sort(reverseComparator); + return taskNames.toString(); + }else { + return "Todo list is empty."; + } } } diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 1353f2881..162bc594b 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -9,7 +9,6 @@ class TodoListTest { @Test public void testAddTask() { TodoList todoList = new TodoList(); - Assertions.assertTrue(todoList.addTask("Test task 1")); } @@ -17,7 +16,7 @@ public void testAddTask() { public void testGetTasks(){ TodoList todoList = new TodoList(); // Test if todo list is empty - Assertions.assertEquals("Todo list is empty.", todoList.getTasks(todoList.todoList)); + Assertions.assertEquals("Todo list is empty.", todoList.getTasks()); todoList.addTask("Test task 1"); todoList.addTask("Test task 2"); @@ -28,14 +27,17 @@ public void testGetTasks(){ test.add("Test task 2"); test.add("Test task 3"); // Test if todo list is not empty - Assertions.assertEquals(test.toString(), todoList.getTasks(todoList.todoList)); + Assertions.assertEquals(test.toString(), todoList.getTasks()); } @Test public void testChangeStatus() { TodoList todoList = new TodoList(); + Assertions.assertEquals("Task not found.", todoList.setCompleted("Test task 1")); todoList.addTask("Test task 1"); - Assertions.assertEquals("Task status changed.", todoList.changeStatus("Test task 1")); + Assertions.assertEquals("Task status is now 'Completed'.", todoList.setCompleted("Test task 1")); + + Assertions.assertEquals("Task status is now 'Incomplete'.", todoList.setUncompleted("Test task 1")); } @@ -46,11 +48,11 @@ public void testGetCompletedTasks() { todoList.addTask("Test task 1"); todoList.addTask("Test task 2"); todoList.addTask("Test task 3"); - Assertions.assertEquals("No completed tasks in todo list.", todoList.getCompletedTasks(todoList.todoList)); + Assertions.assertEquals("No completed tasks in todo list.", todoList.getCompletedTasks()); - todoList.changeStatus("Test task 1"); + todoList.setCompleted("Test task 1"); - Assertions.assertEquals("[Test task 1]", todoList.getCompletedTasks(todoList.todoList)); + Assertions.assertEquals("[Test task 1]", todoList.getCompletedTasks()); } @Test @@ -58,9 +60,9 @@ public void testGetUncompletedTasks() { TodoList todoList = new TodoList(); todoList.addTask("Test task 1"); - todoList.changeStatus("Test task 1"); + todoList.setCompleted("Test task 1"); - Assertions.assertEquals("No uncompleted tasks in todo list.", todoList.getUncompletedTasks(todoList.todoList)); + Assertions.assertEquals("No uncompleted tasks in todo list.", todoList.getUncompletedTasks()); todoList.addTask("Test task 2"); todoList.addTask("Test task 3"); @@ -69,7 +71,7 @@ public void testGetUncompletedTasks() { test.add("Test task 2"); test.add("Test task 3"); - Assertions.assertEquals(test.toString(), todoList.getUncompletedTasks(todoList.todoList)); + Assertions.assertEquals(test.toString(), todoList.getUncompletedTasks()); } @Test @@ -83,7 +85,7 @@ public void testSearchTask() { todoList.addTask("Test task 3"); - Assertions.assertEquals("[Test task 1]", todoList.searchTask("Test task 1")); + Assertions.assertEquals("Task 'Test task 1' is Incomplete", todoList.searchTask("Test task 1")); } @Test @@ -112,8 +114,8 @@ public void testGetTasksAscending() { ArrayList test = new ArrayList<>(); test.add("A task 2"); - test.add("C task 2"); - test.add("F task 2"); + test.add("C task 1"); + test.add("F task 3"); Assertions.assertEquals(test.toString(), todoList.getTasksAscending()); } @@ -129,8 +131,8 @@ public void testGetTasksDescending() { todoList.addTask("F task 3"); ArrayList test = new ArrayList<>(); - test.add("F task 2"); - test.add("C task 2"); + test.add("F task 3"); + test.add("C task 1"); test.add("A task 2"); Assertions.assertEquals(test.toString(), todoList.getTasksDescending()); From 79873f78f2af4146f6cd1109cdc0aec755e4848b Mon Sep 17 00:00:00 2001 From: Tuva Aarseth Date: Thu, 15 Aug 2024 18:31:08 +0200 Subject: [PATCH 10/12] Created domain model for extension. --- domain-model.md | 60 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/domain-model.md b/domain-model.md index 44efcd2cd..c7fbe3fc4 100644 --- a/domain-model.md +++ b/domain-model.md @@ -32,28 +32,56 @@ -| Method | Scenario | Output | -|-------------------------|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------| -| `addTask(String)` | Task is added to todoList
Task is not added to todoList | `Return` true
`Return` false | -| `getTasks()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list
`Return` "Todo list is empty." | -| `getCompletedTasks()` | todoList contains completed tasks
todoList does not contain completed tasks | `Return` tasks with status 'complete'
`Return` "No completed tasks in todo list." | -| `getUncompletedTasks()` | todoList contains uncompleted tasks
todoList does not contain uncompleted tasks | `Return` tasks with status 'incomplete'
`Return` "No uncompleted tasks in todo list." | -| `searchTask(String)` | Task exists in todoList
Task does not exist in todoList | `Return` task
`Return` "Task not found." | -| `changeStatus(String)` | Status is changed
Status remains unchanged | `Return` "Task status changed."
`Return` "Task status remains unchanged." | -| `removeTask(String)` | Task exist in todoList
Task does not exist in todoList | `Return` "Task removed from todo list."
`Return` "Task not found." | -| `getTasksAscending()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in ascending order
`Return` "Todo list is empty." | -| `getTasksDescending()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in descending order
`Return` "Todo list is empty." | - - - - +| Method | Scenario | Output | +|--------------------------|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------| +| `addTask(String)` | Task is added to todoList
Task is not added to todoList | `Return` true
`Return` false | +| `getTasks()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list
`Return` "Todo list is empty." | +| `getCompletedTasks()` | todoList contains completed tasks
todoList does not contain completed tasks | `Return` tasks with status 'complete'
`Return` "No completed tasks in todo list." | +| `getUncompletedTasks()` | todoList contains uncompleted tasks
todoList does not contain uncompleted tasks | `Return` tasks with status 'incomplete'
`Return` "No uncompleted tasks in todo list." | +| `searchTask(String)` | Task exists in todoList
Task does not exist in todoList | `Return` task
`Return` "Task not found." | +| `setCompleted(String)` | Task exists in todoList
Task does not exist in todoList | `Return` "Task status is now 'Completed'."
`Return` "Task not found." | +| `setUncompleted(String)` | Task exists in todoList
Task does not exist in todoList | `Return` "Task status is now 'Incomplete'."
`Return` "Task not found." | +| `removeTask(String)` | Task exist in todoList
Task does not exist in todoList | `Return` "Task removed from todo list."
`Return` "Task not found." | +| `getTasksAscending()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in ascending order
`Return` "Todo list is empty." | +| `getTasksDescending()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in descending order
`Return` "Todo list is empty." | + + +# Todo list extension +| Member variable | Data type | +|-----------------|-------------------| +| `task` | `Task` | +| `todoList` | `ArrayList` | +| `idCounter` | `int` | +#### Task Class +| Member variable | Data type | +|-----------------|-----------------| +| `taskId` | `int` | +| `taskName` | `String` | +| `taskStatus` | `String` | +| `dateTime` | `LocalDateTime` | +| Method | Scenario | Output | +|-----------------------------|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------| +| `addTask(String)` | Task is added to todoList
Task is not added to todoList | `Return` true
`Return` false | +| `getTasks()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list
`Return` "Todo list is empty." | +| `getCompletedTasks()` | todoList contains completed tasks
todoList does not contain completed tasks | `Return` tasks with status 'complete'
`Return` "No completed tasks in todo list." | +| `getUncompletedTasks()` | todoList contains uncompleted tasks
todoList does not contain uncompleted tasks | `Return` tasks with status 'incomplete'
`Return` "No uncompleted tasks in todo list." | +| `searchTask(String)` | Task exists in todoList
Task does not exist in todoList | `Return` task
`Return` "Task not found." | +| `setCompleted(String)` | Task exists in todoList
Task does not exist in todoList | `Return` "Task status is now 'Completed'."
`Return` "Task not found." | +| `setUncompleted(String)` | Task exists in todoList
Task does not exist in todoList | `Return` "Task status is now 'Incomplete'."
`Return` "Task not found." | +| `removeTask(String)` | Task exist in todoList
Task does not exist in todoList | `Return` "Task removed from todo list."
`Return` "Task not found." | +| `getTasksAscending()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in ascending order
`Return` "Todo list is empty." | +| `getTasksDescending()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in descending order
`Return` "Todo list is empty." | +| `getTaskById(int)` | Task exists in todoList
Task does not exist in todoList | `Return` task
`Return` "Task not found." | +| `editTaskName(int, String)` | Task exists in todoList
Task does not exist in todoList | `Return` "Task name changed."
`Return` "Task not found." | +| `setCompletedById(int)` | Task exists in todoList
Task does not exist in todoList | `Return` "Task status is now 'Completed'."
`Return` "Task not found." | +| `setUncompletedById(int)` | Task exists in todoList
Task does not exist in todoList | `Return` "Task status is now 'Incomplete'."
`Return` "Task not found." | +| `getCreationDateTime(int)` | Task exists in todoList
Task does not exist in todoList | `Return` "Task was created at 'DateTime'"
`Return` "Task not found." | -# Todo list extension \ No newline at end of file From 649a3a98c09300da55978fa7f44b781ebeb0df66 Mon Sep 17 00:00:00 2001 From: Tuva Aarseth Date: Thu, 15 Aug 2024 18:59:53 +0200 Subject: [PATCH 11/12] Created tests for extension requirements. --- .../extension/TodoListExtension.java | 6 ++ .../extension/TodoListExtensionTest.java | 56 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/main/java/com/booleanuk/extension/TodoListExtension.java create mode 100644 src/test/java/com/booleanuk/extension/TodoListExtensionTest.java diff --git a/src/main/java/com/booleanuk/extension/TodoListExtension.java b/src/main/java/com/booleanuk/extension/TodoListExtension.java new file mode 100644 index 000000000..dd75f427e --- /dev/null +++ b/src/main/java/com/booleanuk/extension/TodoListExtension.java @@ -0,0 +1,6 @@ +package com.booleanuk.extension; + +public class TodoListExtension { + + +} diff --git a/src/test/java/com/booleanuk/extension/TodoListExtensionTest.java b/src/test/java/com/booleanuk/extension/TodoListExtensionTest.java new file mode 100644 index 000000000..ceca1ab81 --- /dev/null +++ b/src/test/java/com/booleanuk/extension/TodoListExtensionTest.java @@ -0,0 +1,56 @@ +package com.booleanuk.extension; + +import com.booleanuk.core.TodoList; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.time.LocalDateTime; + +public class TodoListExtensionTest { + @Test + public void testGetTaskById() { + TodoListExtension todoList = new TodoListExtension(); + + todoList.addTask("Test task 1"); + todoList.addTask("Test task 2"); + todoList.addTask("Test task 3"); + + Assertions.assertEquals("Test task 2", todoList.getTaskById(2)); + } + @Test + public void testEditTaskName() { + TodoListExtension todoList = new TodoListExtension(); + + todoList.addTask("Test task 1"); + todoList.addTask("Test task 2"); + todoList.addTask("Test task 3"); + + Assertions.assertEquals("Task name changed.", todoList.editTaskName(2, "Edited name")); + Assertions.assertEquals("Edited name", todoList.getTaskById(2)); + } + + @Test + public void testChangeStatus() { + TodoListExtension todoList = new TodoListExtension(); + Assertions.assertEquals("Task not found.", todoList.setCompletedById(2)); + + todoList.addTask("Test task 1"); + todoList.addTask("Test task 2"); + todoList.addTask("Test task 3"); + Assertions.assertEquals("Task status is now 'Completed'.", todoList.setCompletedById(2)); + + Assertions.assertEquals("Task status is now 'Incomplete'.", todoList.setUncompletedById(2)); + } + + @Test + public void testGetCreationDateTime() { + TodoListExtension todoList = new TodoListExtension(); + + todoList.addTask("Test task 1"); + todoList.addTask("Test task 2"); + String timeNow = LocalDateTime.now().withNano(0).withSecond(0).toString(); + todoList.addTask("Test task 3"); + + Assertions.assertEquals(timeNow, todoList.getCreationDateTime(2)); + } +} From e2275b99cdab1e1a77ef70b03449cae47858114c Mon Sep 17 00:00:00 2001 From: Tuva Aarseth Date: Fri, 16 Aug 2024 01:44:29 +0200 Subject: [PATCH 12/12] Completed extension requirements. Added comments and refactored code and domain modelfor clarity. --- domain-model.md | 34 +-- .../extension/TodoListExtension.java | 234 ++++++++++++++++++ .../java/com/booleanuk/core/TodoListTest.java | 43 ++-- .../extension/TodoListExtensionTest.java | 29 ++- 4 files changed, 299 insertions(+), 41 deletions(-) diff --git a/domain-model.md b/domain-model.md index c7fbe3fc4..7621b35c9 100644 --- a/domain-model.md +++ b/domain-model.md @@ -65,23 +65,23 @@ -| Method | Scenario | Output | -|-----------------------------|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------| -| `addTask(String)` | Task is added to todoList
Task is not added to todoList | `Return` true
`Return` false | -| `getTasks()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list
`Return` "Todo list is empty." | -| `getCompletedTasks()` | todoList contains completed tasks
todoList does not contain completed tasks | `Return` tasks with status 'complete'
`Return` "No completed tasks in todo list." | -| `getUncompletedTasks()` | todoList contains uncompleted tasks
todoList does not contain uncompleted tasks | `Return` tasks with status 'incomplete'
`Return` "No uncompleted tasks in todo list." | -| `searchTask(String)` | Task exists in todoList
Task does not exist in todoList | `Return` task
`Return` "Task not found." | -| `setCompleted(String)` | Task exists in todoList
Task does not exist in todoList | `Return` "Task status is now 'Completed'."
`Return` "Task not found." | -| `setUncompleted(String)` | Task exists in todoList
Task does not exist in todoList | `Return` "Task status is now 'Incomplete'."
`Return` "Task not found." | -| `removeTask(String)` | Task exist in todoList
Task does not exist in todoList | `Return` "Task removed from todo list."
`Return` "Task not found." | -| `getTasksAscending()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in ascending order
`Return` "Todo list is empty." | -| `getTasksDescending()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in descending order
`Return` "Todo list is empty." | -| `getTaskById(int)` | Task exists in todoList
Task does not exist in todoList | `Return` task
`Return` "Task not found." | -| `editTaskName(int, String)` | Task exists in todoList
Task does not exist in todoList | `Return` "Task name changed."
`Return` "Task not found." | -| `setCompletedById(int)` | Task exists in todoList
Task does not exist in todoList | `Return` "Task status is now 'Completed'."
`Return` "Task not found." | -| `setUncompletedById(int)` | Task exists in todoList
Task does not exist in todoList | `Return` "Task status is now 'Incomplete'."
`Return` "Task not found." | -| `getCreationDateTime(int)` | Task exists in todoList
Task does not exist in todoList | `Return` "Task was created at 'DateTime'"
`Return` "Task not found." | +| Method | Scenario | Output | +|-----------------------------|-------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------| +| `addTask(String)` | Task is added to todoList
Task is not added to todoList | `Return` true
`Return` false | +| `getTasks()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list
`Return` "Todo list is empty." | +| `getCompletedTasks()` | todoList contains completed tasks
todoList does not contain completed tasks | `Return` tasks with status 'complete'
`Return` "No completed tasks in todo list." | +| `getUncompletedTasks()` | todoList contains uncompleted tasks
todoList does not contain uncompleted tasks | `Return` tasks with status 'incomplete'
`Return` "No uncompleted tasks in todo list." | +| `searchTask(String)` | Task exists in todoList
Task does not exist in todoList | `Return` task
`Return` "Task not found." | +| `setCompleted(String)` | Task exists in todoList
Task does not exist in todoList | `Return` "Task status is now 'Completed'."
`Return` "Task not found." | +| `setUncompleted(String)` | Task exists in todoList
Task does not exist in todoList | `Return` "Task status is now 'Incomplete'."
`Return` "Task not found." | +| `removeTask(String)` | Task exist in todoList
Task does not exist in todoList | `Return` "Task removed from todo list."
`Return` "Task not found." | +| `getTasksAscending()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in ascending order
`Return` "Todo list is empty." | +| `getTasksDescending()` | todoList is not empty
todoList is empty | `Return` all tasks in todo list in descending order
`Return` "Todo list is empty." | +| `getTaskById(int)` | Task exists in todoList
Task does not exist in todoList
todoList is empty | `Return` task
`Return` "Task not found."
`Return` "Todo list is empty." | +| `editTaskName(int, String)` | Task exists in todoList
Task does not exist in todoList
todoList is empty | `Return` "Task name changed."
`Return` "Task not found."
`Return` "Todo list is empty." | +| `setCompletedById(int)` | Task exists in todoList
Task does not exist in todoList
todoList is empty | `Return` "Task status is now 'Completed'."
`Return` "Task not found."
`Return` "Todo list is empty." | +| `setUncompletedById(int)` | Task exists in todoList
Task does not exist in todoList
todoList is empty | `Return` "Task status is now 'Incomplete'."
`Return` "Task not found."
`Return` "Todo list is empty." | +| `getCreationDateTime(int)` | Task exists in todoList
Task does not exist in todoList
todoList is empty | `Return` "Task was created at 'DateTime'"
`Return` "Task not found."
`Return` "Todo list is empty." | diff --git a/src/main/java/com/booleanuk/extension/TodoListExtension.java b/src/main/java/com/booleanuk/extension/TodoListExtension.java index dd75f427e..d7394b203 100644 --- a/src/main/java/com/booleanuk/extension/TodoListExtension.java +++ b/src/main/java/com/booleanuk/extension/TodoListExtension.java @@ -1,6 +1,240 @@ package com.booleanuk.extension; +import com.booleanuk.core.TodoList; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; + public class TodoListExtension { + public static class Task{ + public int taskId; + public String taskName; + public String taskStatus; + public LocalDateTime dateTime; + } + + ArrayList todoList = new ArrayList<>(); + int idCounter = 1; + + // Extension methods + + public String getTaskById(int taskId){ + if (!todoList.isEmpty()){ + for (Task task : todoList) { + if (taskId == task.taskId) { + return "'" + task.taskName + "' is " + task.taskStatus; + } + } + return "Task not found."; + } + else { + return "Todo list is empty."; + } + } + + public String editTaskName(int taskId, String newTaskName){ + if (!todoList.isEmpty()){ + for (int i=0;i taskNames = new ArrayList<>(); + for (Task task : todoList) { + taskNames.add(task.taskName); + } + return taskNames.toString(); + }else { + return "Todo list is empty."; + } + } + + public String setCompleted(String taskName){ + Task task = new Task(); + task.taskStatus = "Completed"; + task.taskName = taskName; + + for (int i=0;i completedTasks = new ArrayList<>(); + for (Task task : todoList) { + if (task.taskStatus.equals("Completed")) { + completedTasks.add(task.taskName); + } + } + if (!completedTasks.isEmpty()){ + return completedTasks.toString(); + }else { + return "No completed tasks in todo list."; + } + } + + public String getUncompletedTasks(){ + ArrayList uncompletedTasks = new ArrayList<>(); + for (Task task : todoList) { + if (task.taskStatus.equals("Incomplete")) { + uncompletedTasks.add(task.taskName); + } + } + if (!uncompletedTasks.isEmpty()){ + return uncompletedTasks.toString(); + }else { + return "No uncompleted tasks in todo list."; + } + } + + public String searchTask(String taskName){ + for (Task task : todoList) { + if (taskName.equals(task.taskName)) { + return "Task '" + taskName + "' is " + task.taskStatus; + } + } + return "Task not found."; + } + + public String removeTask(String taskName) { + for (int i = 0; i < todoList.size(); i++) { + if (taskName.equals((todoList.get(i)).taskName)) { + todoList.remove(i); + return "Task removed from todo list."; + } + } + return "Task not found."; + } + + public String getTasksAscending(){ + if (!this.todoList.isEmpty()){ + ArrayList taskNames = new ArrayList<>(); + for (Task task : todoList) { + taskNames.add(task.taskName); + } + Collections.sort(taskNames); + return taskNames.toString(); + }else { + return "Todo list is empty."; + } + } + public String getTasksDescending(){ + Comparator reverseComparator = Comparator.reverseOrder(); + if (!this.todoList.isEmpty()){ + ArrayList taskNames = new ArrayList<>(); + for (Task task : todoList) { + taskNames.add(task.taskName); + } + taskNames.sort(reverseComparator); + return taskNames.toString(); + }else { + return "Todo list is empty."; + } + } } diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 162bc594b..509ffbcb9 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -9,34 +9,42 @@ class TodoListTest { @Test public void testAddTask() { TodoList todoList = new TodoList(); + + // Test that task is added to list Assertions.assertTrue(todoList.addTask("Test task 1")); + Assertions.assertEquals("[Test task 1]", todoList.getTasks()); } @Test public void testGetTasks(){ TodoList todoList = new TodoList(); - // Test if todo list is empty + + // Test if return is correct when list is empty Assertions.assertEquals("Todo list is empty.", todoList.getTasks()); + // Test if tasks are retrieved todoList.addTask("Test task 1"); todoList.addTask("Test task 2"); todoList.addTask("Test task 3"); - ArrayList test = new ArrayList<>(); test.add("Test task 1"); test.add("Test task 2"); test.add("Test task 3"); - // Test if todo list is not empty Assertions.assertEquals(test.toString(), todoList.getTasks()); } @Test public void testChangeStatus() { TodoList todoList = new TodoList(); + + // Test if return is correct when task does not exist Assertions.assertEquals("Task not found.", todoList.setCompleted("Test task 1")); + + // Test that the status is changed to complete todoList.addTask("Test task 1"); Assertions.assertEquals("Task status is now 'Completed'.", todoList.setCompleted("Test task 1")); + // Test that the status is changed to incomplete Assertions.assertEquals("Task status is now 'Incomplete'.", todoList.setUncompleted("Test task 1")); } @@ -45,32 +53,33 @@ public void testChangeStatus() { public void testGetCompletedTasks() { TodoList todoList = new TodoList(); + // Test that no tasks are retrieved if no tasks have status complete todoList.addTask("Test task 1"); todoList.addTask("Test task 2"); todoList.addTask("Test task 3"); Assertions.assertEquals("No completed tasks in todo list.", todoList.getCompletedTasks()); + // Test that tasks with status complete are retrieved todoList.setCompleted("Test task 1"); - - Assertions.assertEquals("[Test task 1]", todoList.getCompletedTasks()); + todoList.setCompleted("Test task 3"); + Assertions.assertEquals("[Test task 1, Test task 3]", todoList.getCompletedTasks()); } @Test public void testGetUncompletedTasks() { TodoList todoList = new TodoList(); + // Test that no tasks are retrieved if no tasks have status incomplete todoList.addTask("Test task 1"); todoList.setCompleted("Test task 1"); - Assertions.assertEquals("No uncompleted tasks in todo list.", todoList.getUncompletedTasks()); + // Test that tasks with status incomplete are retrieved todoList.addTask("Test task 2"); todoList.addTask("Test task 3"); - ArrayList test = new ArrayList<>(); test.add("Test task 2"); test.add("Test task 3"); - Assertions.assertEquals(test.toString(), todoList.getUncompletedTasks()); } @@ -78,13 +87,13 @@ public void testGetUncompletedTasks() { public void testSearchTask() { TodoList todoList = new TodoList(); + // Test if return is correct when task does not exist Assertions.assertEquals("Task not found.", todoList.searchTask("Test task 1")); + // Test if correct task is retrieved by task name todoList.addTask("Test task 1"); todoList.addTask("Test task 2"); todoList.addTask("Test task 3"); - - Assertions.assertEquals("Task 'Test task 1' is Incomplete", todoList.searchTask("Test task 1")); } @@ -92,31 +101,32 @@ public void testSearchTask() { public void testRemoveTask() { TodoList todoList = new TodoList(); + // Test if return is correct when task does not exist Assertions.assertEquals("Task not found.", todoList.removeTask("Test task 1")); + // Test if task is removed from list todoList.addTask("Test task 1"); todoList.addTask("Test task 2"); todoList.addTask("Test task 3"); - - Assertions.assertEquals("Task removed from todo list.", todoList.removeTask("Test task 1")); + Assertions.assertEquals("[Test task 2, Test task 3]", todoList.getTasks()); } @Test public void testGetTasksAscending() { TodoList todoList = new TodoList(); + // Test if return is correct when list is empty Assertions.assertEquals("Todo list is empty.", todoList.getTasksAscending()); + // Test if tasks are retrieved in ascending order todoList.addTask("C task 1"); todoList.addTask("A task 2"); todoList.addTask("F task 3"); - ArrayList test = new ArrayList<>(); test.add("A task 2"); test.add("C task 1"); test.add("F task 3"); - Assertions.assertEquals(test.toString(), todoList.getTasksAscending()); } @@ -124,18 +134,17 @@ public void testGetTasksAscending() { public void testGetTasksDescending() { TodoList todoList = new TodoList(); + // Test if return is correct when list is empty Assertions.assertEquals("Todo list is empty.", todoList.getTasksDescending()); + // Test if tasks are retrieved in descending order todoList.addTask("C task 1"); todoList.addTask("A task 2"); todoList.addTask("F task 3"); - ArrayList test = new ArrayList<>(); test.add("F task 3"); test.add("C task 1"); test.add("A task 2"); - Assertions.assertEquals(test.toString(), todoList.getTasksDescending()); } - } diff --git a/src/test/java/com/booleanuk/extension/TodoListExtensionTest.java b/src/test/java/com/booleanuk/extension/TodoListExtensionTest.java index ceca1ab81..09a2bcbc6 100644 --- a/src/test/java/com/booleanuk/extension/TodoListExtensionTest.java +++ b/src/test/java/com/booleanuk/extension/TodoListExtensionTest.java @@ -11,34 +11,49 @@ public class TodoListExtensionTest { public void testGetTaskById() { TodoListExtension todoList = new TodoListExtension(); + // Test if return is correct when list is empty + Assertions.assertEquals("Todo list is empty.", todoList.getTaskById(2)); + + // Test if return is correct when task does not exist todoList.addTask("Test task 1"); + Assertions.assertEquals("Task not found.", todoList.getTaskById(2)); + + // Test if correct task is retrieved by id todoList.addTask("Test task 2"); todoList.addTask("Test task 3"); - - Assertions.assertEquals("Test task 2", todoList.getTaskById(2)); + Assertions.assertEquals("'Test task 2' is Incomplete", todoList.getTaskById(2)); } @Test public void testEditTaskName() { TodoListExtension todoList = new TodoListExtension(); + // Test if name is updated by providing id and new name todoList.addTask("Test task 1"); todoList.addTask("Test task 2"); todoList.addTask("Test task 3"); + Assertions.assertEquals("Task name changed to 'Edited name'", todoList.editTaskName(2, "Edited name")); - Assertions.assertEquals("Task name changed.", todoList.editTaskName(2, "Edited name")); - Assertions.assertEquals("Edited name", todoList.getTaskById(2)); + // Double check that the new name is set correct in the task object + Assertions.assertEquals("'Edited name' is Incomplete", todoList.getTaskById(2)); } @Test public void testChangeStatus() { TodoListExtension todoList = new TodoListExtension(); - Assertions.assertEquals("Task not found.", todoList.setCompletedById(2)); + // Test if return is correct when list is empty + Assertions.assertEquals("Task list is empty.", todoList.setCompletedById(2)); + + // Test if return is correct when task does not exist todoList.addTask("Test task 1"); + Assertions.assertEquals("Task not found.", todoList.setCompletedById(2)); + + // Test that the status is changed to complete todoList.addTask("Test task 2"); todoList.addTask("Test task 3"); Assertions.assertEquals("Task status is now 'Completed'.", todoList.setCompletedById(2)); + // Test that the status is changed to incomplete Assertions.assertEquals("Task status is now 'Incomplete'.", todoList.setUncompletedById(2)); } @@ -46,11 +61,11 @@ public void testChangeStatus() { public void testGetCreationDateTime() { TodoListExtension todoList = new TodoListExtension(); + // Test that the creation datetime is retrieved todoList.addTask("Test task 1"); todoList.addTask("Test task 2"); String timeNow = LocalDateTime.now().withNano(0).withSecond(0).toString(); todoList.addTask("Test task 3"); - - Assertions.assertEquals(timeNow, todoList.getCreationDateTime(2)); + Assertions.assertEquals("Task created at '" + timeNow + "' is Incomplete", todoList.getCreationDateTime(2)); } }