From 9f5990481ede9ecc01ecd0f187a023128ce6bac5 Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 14:04:28 +0100 Subject: [PATCH 01/25] Core domain model complete. Ignore the extension model --- domain-model.md | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 domain-model.md diff --git a/domain-model.md b/domain-model.md new file mode 100644 index 000000000..67c196e14 --- /dev/null +++ b/domain-model.md @@ -0,0 +1,62 @@ +## Todo + +| Method | Member Variable | Scenario | Result | +|-----------------------------------------------|--------------------------------|-------------------------------------------------------------------------------|------------------------------------| +| add(String name) | HashMap tasks | Task with the provided name is not already in the todolist | true | +| | | Task with the provided name is already in the todolist | false | +| | | | | +| listTasks( ) | | There are tasks in the todolist | string with all tasks | +| | | There are no tasks in the todolist | string with error message | +| | | | | +| updateTaskStatus(String name, Boolean status) | | There is a task with the provided name and has the requested status | true | +| | | There is no task with the provided name or does not have the requested status | false | +| | | | | +| getCompletedTasks() | | There are completed tasks in the todolist | string with all completed tasks | +| | | There are no completed tasks in the todolist | string with error message | +| | | | | +| getNotCompletedTasks() | | There are uncompleted tasks in the todolist | string with all uncompleted tasks | +| | | There are no uncompleted tasks in the todolist | string with error message | +| | | | | +| SearchTask(String) | | There was a task with the provided name | string with the task | +| | | There was no task with the provided name | string with error message | +| | | | | +| removeTask(String) | | Task with the provided name is not in the todolist | true | +| | | Task with the provided name is in the todolist | false | +| | | | | +| taskDescending() | | There are tasks in the todolist | string in descending order by name | +| | | There are no tasks in the todolist | string with error message | +| | | | | +| taskAscending() | | There are tasks in the todolist | string in ascending order by name | +| | | There are no tasks in the todolist | string with error message | + + + +# Extension + +## Todo + +| Method | Member Variable | Scenario | Result | +|----------------------------------------------|-----------------------|----------|--------| +| add(String name) | ArrayList tasks | | | +| | id | | | +| listTasks( ) | | | | +| updateTaskStatus(Task task, Boolean state) | | | | +| | | | | +| getCompletedTasks() | | | | +| getNotCompletedTasks() | | | | +| SearchTask(Task task) | | | | +| removeTask(Task task) | | | | +| taskDescending() | | | | +| taskAscending() | | | | +| getTaskById(int id) | | | | +| updateTaskName(int id, String newName) | | | | +| updateTaskStatusById(int id, Boolean status) | | | | +| | | | | + +## Task + +| Method | Member Variable | Scenario | Result | +|--------|------------------|----------|--------| +| | | | | +| | Boolean complete | | | +| | String name | | | \ No newline at end of file From 8af3613b20110474a7efc6646694a493335e4abf Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 14:19:57 +0100 Subject: [PATCH 02/25] Tests for add() function complete --- .../java/com/booleanuk/core/TodoListTest.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 0bef779a4..4d5747ec4 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -5,9 +5,30 @@ class TodoListTest { @Test - public void exampleTest() { - String hello = "Hello"; - Assertions.assertEquals("Hello", hello); - Assertions.assertNotEquals("Goodbye", hello); + public void addTaskToListThatAlreadyExist() { + TodoList todoList = new TodoList(); + String taskName = "clean"; + + todoList.add("clean"); + todoList.add("wash"); + todoList.add("vacuum"); + todoList.add("walk the dog"); + + Assertions.assertFalse(todoList.add(taskName)); } + + @Test + public void addTaskToListThatDoesNotAlreadyExist() { + TodoList todoList = new TodoList(); + String taskName = "run"; + + todoList.add("clean"); + todoList.add("wash"); + todoList.add("vacuum"); + todoList.add("walk the dog"); + + Assertions.assertTrue(todoList.add(taskName)); + } + + } From 808747a77ebbb6da33214a4a22ae96268c7dde4c Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 14:25:56 +0100 Subject: [PATCH 03/25] Code for add() function complete and passed the tests. --- src/main/java/com/booleanuk/core/TodoList.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index 675adaf0b..1779e6d30 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -1,5 +1,16 @@ package com.booleanuk.core; +import java.util.HashMap; + public class TodoList { + public HashMap tasks = new HashMap<>(); + + public boolean add(String taskName){ + if(tasks.containsKey(taskName)){ + return false; + } + tasks.put(taskName, false); + return true; + } } From b7404aaace48d56383a00a84ba459aff23d29e6b Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 14:32:43 +0100 Subject: [PATCH 04/25] Tests for listTasks() function complete. --- .../java/com/booleanuk/core/TodoListTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 4d5747ec4..7ddcfd6d3 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -30,5 +30,30 @@ public void addTaskToListThatDoesNotAlreadyExist() { Assertions.assertTrue(todoList.add(taskName)); } + @Test + public void listAllTasksInTodolist() { + TodoList todoList = new TodoList(); + String taskName = "run"; + + todoList.add("clean"); + todoList.add("wash"); + todoList.add("vacuum"); + todoList.add("walk the dog"); + + Assertions.assertLinesMatch("clean, wash, vacuum, walk the dog", todoList.listTasks()); + } + + @Test + public void listAllTasksInTodolistWhenItIsEmpty() { + TodoList todoList = new TodoList(); + String taskName = "run"; + + todoList.add("clean"); + todoList.add("wash"); + todoList.add("vacuum"); + todoList.add("walk the dog"); + + Assertions.assertLinesMatch("Your todolist is empty", todoList.listTasks()); + } } From 6f76d74d5a5e3d244a9df8293b3dddea8bb5f07e Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 15:06:51 +0100 Subject: [PATCH 05/25] Tests for listTasks() function remade and listTasks() function was made. listTasks result was changed in domain model. --- domain-model.md | 4 ++-- .../java/com/booleanuk/core/TodoList.java | 18 +++++++++++++++++ .../java/com/booleanuk/core/TodoListTest.java | 20 +++++++++++-------- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/domain-model.md b/domain-model.md index 67c196e14..7f1979062 100644 --- a/domain-model.md +++ b/domain-model.md @@ -5,8 +5,8 @@ | add(String name) | HashMap tasks | Task with the provided name is not already in the todolist | true | | | | Task with the provided name is already in the todolist | false | | | | | | -| listTasks( ) | | There are tasks in the todolist | string with all tasks | -| | | There are no tasks in the todolist | string with error message | +| listTasks( ) | | There are tasks in the todolist | List with all tasks | +| | | There are no tasks in the todolist | List with error message | | | | | | | updateTaskStatus(String name, Boolean status) | | There is a task with the provided name and has the requested status | true | | | | There is no task with the provided name or does not have the requested status | false | diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index 1779e6d30..0076457ca 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -1,6 +1,8 @@ package com.booleanuk.core; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; public class TodoList { @@ -13,4 +15,20 @@ public boolean add(String taskName){ tasks.put(taskName, false); return true; } + + public List listTasks(){ + List strings = new ArrayList() {}; + String errorMsg = "Your todolist is empty"; + + + strings.addAll(tasks.keySet()); + + + if(strings.isEmpty()) { + strings.add(errorMsg); + return strings; + } + + return strings; + } } diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 7ddcfd6d3..1cae6c3df 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -3,6 +3,9 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.ArrayList; +import java.util.List; + class TodoListTest { @Test public void addTaskToListThatAlreadyExist() { @@ -33,27 +36,28 @@ public void addTaskToListThatDoesNotAlreadyExist() { @Test public void listAllTasksInTodolist() { TodoList todoList = new TodoList(); - String taskName = "run"; + List strings = new ArrayList() {}; + + todoList.add("clean"); todoList.add("wash"); todoList.add("vacuum"); todoList.add("walk the dog"); - Assertions.assertLinesMatch("clean, wash, vacuum, walk the dog", todoList.listTasks()); + strings.addAll(todoList.tasks.keySet()); + + Assertions.assertLinesMatch(strings, todoList.listTasks() ); } @Test public void listAllTasksInTodolistWhenItIsEmpty() { TodoList todoList = new TodoList(); - String taskName = "run"; + List strings = new ArrayList() {}; - todoList.add("clean"); - todoList.add("wash"); - todoList.add("vacuum"); - todoList.add("walk the dog"); + strings.add("Your todolist is empty"); - Assertions.assertLinesMatch("Your todolist is empty", todoList.listTasks()); + Assertions.assertLinesMatch(strings, todoList.listTasks() ); } } From 06bb7d183b1791d80aaab7c0e44130accfff8b86 Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 15:12:48 +0100 Subject: [PATCH 06/25] Tests for updateTaskStatus() function complete. --- .../java/com/booleanuk/core/TodoListTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 1cae6c3df..b2f0745c1 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -60,4 +60,32 @@ public void listAllTasksInTodolistWhenItIsEmpty() { Assertions.assertLinesMatch(strings, todoList.listTasks() ); } + @Test + public void updateTaskStatusWithExistingName(){ + TodoList todoList = new TodoList(); + String taskName = "clean"; + + todoList.add("clean"); + todoList.add("wash"); + todoList.add("vacuum"); + todoList.add("walk the dog"); + + Assertions.assertTrue(todoList.updateTaskStatus(taskName , true)); + + } + + @Test + public void updateTaskStatusWithNonExistingName(){ + TodoList todoList = new TodoList(); + String taskName = "watch tv"; + + todoList.add("clean"); + todoList.add("wash"); + todoList.add("vacuum"); + todoList.add("walk the dog"); + + Assertions.assertFalse(todoList.updateTaskStatus(taskName , true)); + + } + } From c18d1efc2e1c79c897e02cdf0ab0fa74439d29df Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 15:21:58 +0100 Subject: [PATCH 07/25] updateTaskStatus() function complete and 1 change in the domain model --- domain-model.md | 56 +++++++++---------- .../java/com/booleanuk/core/TodoList.java | 8 +++ 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/domain-model.md b/domain-model.md index 7f1979062..5441c35ec 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1,33 +1,33 @@ ## Todo -| Method | Member Variable | Scenario | Result | -|-----------------------------------------------|--------------------------------|-------------------------------------------------------------------------------|------------------------------------| -| add(String name) | HashMap tasks | Task with the provided name is not already in the todolist | true | -| | | Task with the provided name is already in the todolist | false | -| | | | | -| listTasks( ) | | There are tasks in the todolist | List with all tasks | -| | | There are no tasks in the todolist | List with error message | -| | | | | -| updateTaskStatus(String name, Boolean status) | | There is a task with the provided name and has the requested status | true | -| | | There is no task with the provided name or does not have the requested status | false | -| | | | | -| getCompletedTasks() | | There are completed tasks in the todolist | string with all completed tasks | -| | | There are no completed tasks in the todolist | string with error message | -| | | | | -| getNotCompletedTasks() | | There are uncompleted tasks in the todolist | string with all uncompleted tasks | -| | | There are no uncompleted tasks in the todolist | string with error message | -| | | | | -| SearchTask(String) | | There was a task with the provided name | string with the task | -| | | There was no task with the provided name | string with error message | -| | | | | -| removeTask(String) | | Task with the provided name is not in the todolist | true | -| | | Task with the provided name is in the todolist | false | -| | | | | -| taskDescending() | | There are tasks in the todolist | string in descending order by name | -| | | There are no tasks in the todolist | string with error message | -| | | | | -| taskAscending() | | There are tasks in the todolist | string in ascending order by name | -| | | There are no tasks in the todolist | string with error message | +| Method | Member Variable | Scenario | Result | +|-----------------------------------------------|--------------------------------|------------------------------------------------------------|------------------------------------| +| add(String name) | HashMap tasks | Task with the provided name is not already in the todolist | true | +| | | Task with the provided name is already in the todolist | false | +| | | | | +| listTasks( ) | | There are tasks in the todolist | List with all tasks | +| | | There are no tasks in the todolist | List with error message | +| | | | | +| updateTaskStatus(String name, Boolean status) | | There is a task with the provided name | true | +| | | There is no task with the provided name | false | +| | | | | +| getCompletedTasks() | | There are completed tasks in the todolist | string with all completed tasks | +| | | There are no completed tasks in the todolist | string with error message | +| | | | | +| getNotCompletedTasks() | | There are uncompleted tasks in the todolist | string with all uncompleted tasks | +| | | There are no uncompleted tasks in the todolist | string with error message | +| | | | | +| SearchTask(String) | | There was a task with the provided name | string with the task | +| | | There was no task with the provided name | string with error message | +| | | | | +| removeTask(String) | | Task with the provided name is not in the todolist | true | +| | | Task with the provided name is in the todolist | false | +| | | | | +| taskDescending() | | There are tasks in the todolist | string in descending order by name | +| | | There are no tasks in the todolist | string with error message | +| | | | | +| taskAscending() | | There are tasks in the todolist | string in ascending order by name | +| | | There are no tasks in the todolist | string with error message | diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index 0076457ca..930b6a2de 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -31,4 +31,12 @@ public List listTasks(){ return strings; } + + public boolean updateTaskStatus(String taskName, Boolean taskCompletion){ + if(tasks.containsKey(taskName)){ + tasks.replace(taskName, taskCompletion); + return true; + } + return false; + } } From 44d35f16adcc6f3c4544ff4a3cfebdc71d5f8030 Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 15:29:34 +0100 Subject: [PATCH 08/25] Tests for the updateTaskStatus() function complete and small change in the domain model --- domain-model.md | 56 +++++++++---------- .../java/com/booleanuk/core/TodoListTest.java | 34 +++++++++++ 2 files changed, 62 insertions(+), 28 deletions(-) diff --git a/domain-model.md b/domain-model.md index 5441c35ec..899facd4c 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1,33 +1,33 @@ ## Todo -| Method | Member Variable | Scenario | Result | -|-----------------------------------------------|--------------------------------|------------------------------------------------------------|------------------------------------| -| add(String name) | HashMap tasks | Task with the provided name is not already in the todolist | true | -| | | Task with the provided name is already in the todolist | false | -| | | | | -| listTasks( ) | | There are tasks in the todolist | List with all tasks | -| | | There are no tasks in the todolist | List with error message | -| | | | | -| updateTaskStatus(String name, Boolean status) | | There is a task with the provided name | true | -| | | There is no task with the provided name | false | -| | | | | -| getCompletedTasks() | | There are completed tasks in the todolist | string with all completed tasks | -| | | There are no completed tasks in the todolist | string with error message | -| | | | | -| getNotCompletedTasks() | | There are uncompleted tasks in the todolist | string with all uncompleted tasks | -| | | There are no uncompleted tasks in the todolist | string with error message | -| | | | | -| SearchTask(String) | | There was a task with the provided name | string with the task | -| | | There was no task with the provided name | string with error message | -| | | | | -| removeTask(String) | | Task with the provided name is not in the todolist | true | -| | | Task with the provided name is in the todolist | false | -| | | | | -| taskDescending() | | There are tasks in the todolist | string in descending order by name | -| | | There are no tasks in the todolist | string with error message | -| | | | | -| taskAscending() | | There are tasks in the todolist | string in ascending order by name | -| | | There are no tasks in the todolist | string with error message | +| Method | Member Variable | Scenario | Result | +|-----------------------------------------------|--------------------------------|------------------------------------------------------------|---------------------------------------| +| add(String name) | HashMap tasks | Task with the provided name is not already in the todolist | true | +| | | Task with the provided name is already in the todolist | false | +| | | | | +| listTasks( ) | | There are tasks in the todolist | List with all tasks | +| | | There are no tasks in the todolist | List with error message | +| | | | | +| updateTaskStatus(String name, Boolean status) | | There is a task with the provided name | true | +| | | There is no task with the provided name | false | +| | | | | +| getCompletedTasks() | | There are completed tasks in the todolist | List with all completed tasks | +| | | There are no completed tasks in the todolist | List with error message | +| | | | | +| getNotCompletedTasks() | | There are uncompleted tasks in the todolist | string with all uncompleted tasks | +| | | There are no uncompleted tasks in the todolist | string with error message | +| | | | | +| SearchTask(String) | | There was a task with the provided name | string with the task | +| | | There was no task with the provided name | string with error message | +| | | | | +| removeTask(String) | | Task with the provided name is not in the todolist | true | +| | | Task with the provided name is in the todolist | false | +| | | | | +| taskDescending() | | There are tasks in the todolist | string in descending order by name | +| | | There are no tasks in the todolist | string with error message | +| | | | | +| taskAscending() | | There are tasks in the todolist | string in ascending order by name | +| | | There are no tasks in the todolist | string with error message | diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index b2f0745c1..71aeb040d 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -88,4 +88,38 @@ public void updateTaskStatusWithNonExistingName(){ } + @Test + public void getCompletedTasksWhenNotEmpty(){ + TodoList todoList = new TodoList(); + List strings = new ArrayList() {}; + + todoList.add("clean"); + todoList.add("wash"); + todoList.add("vacuum"); + todoList.add("walk the dog"); + + todoList.updateTaskStatus("clean" , true); + todoList.updateTaskStatus("wash" , true); + + strings.add("clean"); + strings.add("wash"); + + Assertions.assertLinesMatch(strings, todoList.getCompletedTasks() ); + } + + @Test + public void getCompletedTasksWhenEmpty(){ + TodoList todoList = new TodoList(); + List strings = new ArrayList() {}; + + todoList.add("clean"); + todoList.add("wash"); + todoList.add("vacuum"); + todoList.add("walk the dog"); + + strings.add("You have no completed tasks"); + + Assertions.assertLinesMatch(strings, todoList.getCompletedTasks() ); + } + } From 0a9ea138b3e57f55d2fa718f821e267f1238c837 Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 15:51:49 +0100 Subject: [PATCH 09/25] getCompletedTasks() function code completed with small fixes in test code --- .../java/com/booleanuk/core/TodoList.java | 20 +++++++++++++++++++ .../java/com/booleanuk/core/TodoListTest.java | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index 930b6a2de..bf64bed57 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -39,4 +39,24 @@ public boolean updateTaskStatus(String taskName, Boolean taskCompletion){ } return false; } + + public List getCompletedTasks(){ + List strings = new ArrayList() {}; + String errorMsg = "You have no completed tasks"; + + + for (String task : tasks.keySet()){ + if(tasks.get(task)){ + strings.add(task); + + } + } + + if(strings.isEmpty()) { + strings.add(errorMsg); + return strings; + } + + return strings; + } } diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 71aeb040d..d529f14e7 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -101,8 +101,8 @@ public void getCompletedTasksWhenNotEmpty(){ todoList.updateTaskStatus("clean" , true); todoList.updateTaskStatus("wash" , true); - strings.add("clean"); strings.add("wash"); + strings.add("clean"); Assertions.assertLinesMatch(strings, todoList.getCompletedTasks() ); } From 7667e77971179440f16a37a3ae8f5489a6d0d64b Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 15:57:21 +0100 Subject: [PATCH 10/25] getUncompletedTasks test hopefully done. --- domain-model.md | 56 +++++++++---------- .../java/com/booleanuk/core/TodoListTest.java | 34 +++++++++++ 2 files changed, 62 insertions(+), 28 deletions(-) diff --git a/domain-model.md b/domain-model.md index 899facd4c..952fb2d5d 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1,33 +1,33 @@ ## Todo -| Method | Member Variable | Scenario | Result | -|-----------------------------------------------|--------------------------------|------------------------------------------------------------|---------------------------------------| -| add(String name) | HashMap tasks | Task with the provided name is not already in the todolist | true | -| | | Task with the provided name is already in the todolist | false | -| | | | | -| listTasks( ) | | There are tasks in the todolist | List with all tasks | -| | | There are no tasks in the todolist | List with error message | -| | | | | -| updateTaskStatus(String name, Boolean status) | | There is a task with the provided name | true | -| | | There is no task with the provided name | false | -| | | | | -| getCompletedTasks() | | There are completed tasks in the todolist | List with all completed tasks | -| | | There are no completed tasks in the todolist | List with error message | -| | | | | -| getNotCompletedTasks() | | There are uncompleted tasks in the todolist | string with all uncompleted tasks | -| | | There are no uncompleted tasks in the todolist | string with error message | -| | | | | -| SearchTask(String) | | There was a task with the provided name | string with the task | -| | | There was no task with the provided name | string with error message | -| | | | | -| removeTask(String) | | Task with the provided name is not in the todolist | true | -| | | Task with the provided name is in the todolist | false | -| | | | | -| taskDescending() | | There are tasks in the todolist | string in descending order by name | -| | | There are no tasks in the todolist | string with error message | -| | | | | -| taskAscending() | | There are tasks in the todolist | string in ascending order by name | -| | | There are no tasks in the todolist | string with error message | +| Method | Member Variable | Scenario | Result | +|-----------------------------------------------|--------------------------------|------------------------------------------------------------|-----------------------------------------| +| add(String name) | HashMap tasks | Task with the provided name is not already in the todolist | true | +| | | Task with the provided name is already in the todolist | false | +| | | | | +| listTasks( ) | | There are tasks in the todolist | List with all tasks | +| | | There are no tasks in the todolist | List with error message | +| | | | | +| updateTaskStatus(String name, Boolean status) | | There is a task with the provided name | true | +| | | There is no task with the provided name | false | +| | | | | +| getCompletedTasks() | | There are completed tasks in the todolist | List with all completed tasks | +| | | There are no completed tasks in the todolist | List with error message | +| | | | | +| getNotCompletedTasks() | | There are uncompleted tasks in the todolist | List with all uncompleted tasks | +| | | There are no uncompleted tasks in the todolist | List with error message | +| | | | | +| SearchTask(String) | | There was a task with the provided name | string with the task | +| | | There was no task with the provided name | string with error message | +| | | | | +| removeTask(String) | | Task with the provided name is not in the todolist | true | +| | | Task with the provided name is in the todolist | false | +| | | | | +| taskDescending() | | There are tasks in the todolist | string in descending order by name | +| | | There are no tasks in the todolist | string with error message | +| | | | | +| taskAscending() | | There are tasks in the todolist | string in ascending order by name | +| | | There are no tasks in the todolist | string with error message | diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index d529f14e7..34321eb0b 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -122,4 +122,38 @@ public void getCompletedTasksWhenEmpty(){ Assertions.assertLinesMatch(strings, todoList.getCompletedTasks() ); } + @Test + public void getUnCompletedTasksWhenEmpty(){ + TodoList todoList = new TodoList(); + List strings = new ArrayList() {}; + + todoList.add("clean"); + todoList.add("wash"); + todoList.add("vacuum"); + todoList.add("walk the dog"); + + strings.add("You have no uncompleted tasks"); + + Assertions.assertLinesMatch(strings, todoList.getUnCompletedTasks() ); + } + + @Test + public void getUnCompletedTasksWhenNotEmpty(){ + TodoList todoList = new TodoList(); + List strings = new ArrayList() {}; + + todoList.add("clean"); + todoList.add("wash"); + todoList.add("vacuum"); + todoList.add("walk the dog"); + + todoList.updateTaskStatus("clean" , true); + todoList.updateTaskStatus("wash" , true); + + strings.add("vacuum"); + strings.add("walk the dog"); + + Assertions.assertLinesMatch(strings, todoList.getUnCompletedTasks() ); + } + } From bebc4f12e09dec1a9c19f79a9f764ff99c1ec77e Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 16:00:09 +0100 Subject: [PATCH 11/25] getUncompletedTasks code complete. --- .../java/com/booleanuk/core/TodoList.java | 20 +++++++++++++++++++ .../java/com/booleanuk/core/TodoListTest.java | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index bf64bed57..cb449e2cb 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -59,4 +59,24 @@ public List getCompletedTasks(){ return strings; } + + public List getUnCompletedTasks(){ + List strings = new ArrayList() {}; + String errorMsg = "You have no uncompleted tasks"; + + + for (String task : tasks.keySet()){ + if(!tasks.get(task)){ + strings.add(task); + + } + } + + if(strings.isEmpty()) { + strings.add(errorMsg); + return strings; + } + + return strings; + } } diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 34321eb0b..4acc52243 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -132,6 +132,11 @@ public void getUnCompletedTasksWhenEmpty(){ todoList.add("vacuum"); todoList.add("walk the dog"); + todoList.updateTaskStatus("clean" , true); + todoList.updateTaskStatus("wash" , true); + todoList.updateTaskStatus("vacuum" , true); + todoList.updateTaskStatus("walk the dog" , true); + strings.add("You have no uncompleted tasks"); Assertions.assertLinesMatch(strings, todoList.getUnCompletedTasks() ); From 2a3764d71fa83c383afaff98fb0a1236f7fb8a40 Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 16:10:18 +0100 Subject: [PATCH 12/25] searchTask() tests complete --- .../java/com/booleanuk/core/TodoListTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 4acc52243..68a1d2e36 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -161,4 +161,38 @@ public void getUnCompletedTasksWhenNotEmpty(){ Assertions.assertLinesMatch(strings, todoList.getUnCompletedTasks() ); } + @Test + public void searchTaskThatDoesNotExist(){ + TodoList todoList = new TodoList(); + List strings = new ArrayList() {}; + String taskName = "wash"; + + todoList.add("clean"); + todoList.add("wash"); + todoList.add("vacuum"); + todoList.add("walk the dog"); + + strings.add("wash"); + + Assertions.assertLinesMatch(strings, todoList.searchTask(taskName) ); + + } + + @Test + public void searchTaskThatDoesExist(){ + TodoList todoList = new TodoList(); + List strings = new ArrayList() {}; + String taskName = "watch tv"; + + todoList.add("clean"); + todoList.add("wash"); + todoList.add("vacuum"); + todoList.add("walk the dog"); + + strings.add("There was no task with that name"); + + Assertions.assertLinesMatch(strings, todoList.searchTask(taskName) ); + + } + } From 2bc47e8d4465c780f61ecd6cee4708123735c6b0 Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 16:18:22 +0100 Subject: [PATCH 13/25] searchTask() function code complete and some fixes in the test. --- src/main/java/com/booleanuk/core/TodoList.java | 15 +++++++++++++++ .../java/com/booleanuk/core/TodoListTest.java | 8 ++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index cb449e2cb..f5daac2a0 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -79,4 +79,19 @@ public List getUnCompletedTasks(){ return strings; } + + public List searchTask(String taskName){ + List strings = new ArrayList() {}; + String message = "There was no task with that name"; + + + if(tasks.containsKey(taskName)){ + message = "There is a task with that name"; + strings.add(message); + return strings; + } + strings.add(message); + + return strings; + } } diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 68a1d2e36..f1fde0976 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -165,14 +165,14 @@ public void getUnCompletedTasksWhenNotEmpty(){ public void searchTaskThatDoesNotExist(){ TodoList todoList = new TodoList(); List strings = new ArrayList() {}; - String taskName = "wash"; + String taskName = "watch tv"; todoList.add("clean"); todoList.add("wash"); todoList.add("vacuum"); todoList.add("walk the dog"); - strings.add("wash"); + strings.add("There was no task with that name"); Assertions.assertLinesMatch(strings, todoList.searchTask(taskName) ); @@ -182,14 +182,14 @@ public void searchTaskThatDoesNotExist(){ public void searchTaskThatDoesExist(){ TodoList todoList = new TodoList(); List strings = new ArrayList() {}; - String taskName = "watch tv"; + String taskName = "wash"; todoList.add("clean"); todoList.add("wash"); todoList.add("vacuum"); todoList.add("walk the dog"); - strings.add("There was no task with that name"); + strings.add("There is a task with that name"); Assertions.assertLinesMatch(strings, todoList.searchTask(taskName) ); From 819af529e16502c7b292ea42cdeb1243485c8917 Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 16:21:20 +0100 Subject: [PATCH 14/25] removeTask() tests complete --- .../java/com/booleanuk/core/TodoListTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index f1fde0976..630edceb3 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -195,4 +195,34 @@ public void searchTaskThatDoesExist(){ } + @Test + public void removeTaskThatDoesExist(){ + TodoList todoList = new TodoList(); + String taskName = "wash"; + + todoList.add("clean"); + todoList.add("wash"); + todoList.add("vacuum"); + todoList.add("walk the dog"); + + + Assertions.assertTrue(todoList.removeTask(taskName)); + + } + + @Test + public void removeTaskThatDoesNotExist(){ + TodoList todoList = new TodoList(); + String taskName = "watch tv"; + + todoList.add("clean"); + todoList.add("wash"); + todoList.add("vacuum"); + todoList.add("walk the dog"); + + + Assertions.assertFalse(todoList.removeTask(taskName)); + + } + } From 14ea150e7b7de85e05e5e955cd225a2cfbf17bd1 Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 16:24:34 +0100 Subject: [PATCH 15/25] removeTask() function code complete --- src/main/java/com/booleanuk/core/TodoList.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index f5daac2a0..22236a42c 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -94,4 +94,12 @@ public List searchTask(String taskName){ return strings; } + + public boolean removeTask(String taskName){ + if(tasks.containsKey(taskName)){ + tasks.remove(taskName); + return true; + } + return false; + } } From 1c3dae96aeaa0399f2991856af743ca715a3cee1 Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 16:30:03 +0100 Subject: [PATCH 16/25] taskDescending() tests complete --- .../java/com/booleanuk/core/TodoListTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 630edceb3..1e4366733 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -225,4 +225,33 @@ public void removeTaskThatDoesNotExist(){ } + @Test + public void taskDescendingWhenNotEmpty(){ + TodoList todoList = new TodoList(); + List strings = new ArrayList() {}; + + todoList.add("clean"); + todoList.add("wash"); + todoList.add("vacuum"); + todoList.add("walk the dog"); + + strings.add("clean"); + strings.add("vacuum"); + strings.add("walks the dog"); + strings.add("Wash"); + + Assertions.assertLinesMatch(strings, todoList.taskDescending() ); + + } + + @Test + public void taskDescendingWhenEmpty(){ + TodoList todoList = new TodoList(); + List strings = new ArrayList() {}; + + strings.add("Not tasks available"); + + Assertions.assertLinesMatch(strings, todoList.taskDescending() ); + + } } From 4c259c726e9a8a8e1882eed2b486d03063086f87 Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 16:36:32 +0100 Subject: [PATCH 17/25] taskDescending() code complete --- src/main/java/com/booleanuk/core/TodoList.java | 18 +++++++++++++++--- .../java/com/booleanuk/core/TodoListTest.java | 6 +++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index 22236a42c..9ce13516e 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -1,8 +1,6 @@ package com.booleanuk.core; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +import java.util.*; public class TodoList { @@ -102,4 +100,18 @@ public boolean removeTask(String taskName){ } return false; } + + public List taskDescending(){ + List strings = new ArrayList(tasks.keySet()) {}; + String errorMsg = "No tasks available"; + + Collections.sort(strings); + + if(strings.isEmpty()){ + strings.add(errorMsg); + return strings; + } + + return strings; + } } diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 1e4366733..b56546850 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -237,8 +237,8 @@ public void taskDescendingWhenNotEmpty(){ strings.add("clean"); strings.add("vacuum"); - strings.add("walks the dog"); - strings.add("Wash"); + strings.add("walk the dog"); + strings.add("wash"); Assertions.assertLinesMatch(strings, todoList.taskDescending() ); @@ -249,7 +249,7 @@ public void taskDescendingWhenEmpty(){ TodoList todoList = new TodoList(); List strings = new ArrayList() {}; - strings.add("Not tasks available"); + strings.add("No tasks available"); Assertions.assertLinesMatch(strings, todoList.taskDescending() ); From 36d984e5dc8b604fb3156716d271bb0b46242f3c Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 16:39:50 +0100 Subject: [PATCH 18/25] tasksAscending() tests complete --- .../java/com/booleanuk/core/TodoList.java | 2 +- .../java/com/booleanuk/core/TodoListTest.java | 38 +++++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index 9ce13516e..ad4ecad4b 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -101,7 +101,7 @@ public boolean removeTask(String taskName){ return false; } - public List taskDescending(){ + public List tasksDescending(){ List strings = new ArrayList(tasks.keySet()) {}; String errorMsg = "No tasks available"; diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index b56546850..25b643b7a 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -226,7 +226,7 @@ public void removeTaskThatDoesNotExist(){ } @Test - public void taskDescendingWhenNotEmpty(){ + public void tasksDescendingWhenNotEmpty(){ TodoList todoList = new TodoList(); List strings = new ArrayList() {}; @@ -240,18 +240,48 @@ public void taskDescendingWhenNotEmpty(){ strings.add("walk the dog"); strings.add("wash"); - Assertions.assertLinesMatch(strings, todoList.taskDescending() ); + Assertions.assertLinesMatch(strings, todoList.tasksDescending() ); } @Test - public void taskDescendingWhenEmpty(){ + public void tasksDescendingWhenEmpty(){ TodoList todoList = new TodoList(); List strings = new ArrayList() {}; strings.add("No tasks available"); - Assertions.assertLinesMatch(strings, todoList.taskDescending() ); + Assertions.assertLinesMatch(strings, todoList.tasksDescending() ); + + } + + @Test + public void tasksAscendingWhenNotEmpty(){ + TodoList todoList = new TodoList(); + List strings = new ArrayList() {}; + + todoList.add("clean"); + todoList.add("wash"); + todoList.add("vacuum"); + todoList.add("walk the dog"); + + strings.add("walk the dog"); + strings.add("vacuum"); + strings.add("wash"); + strings.add("clean"); + + Assertions.assertLinesMatch(strings, todoList.tasksAscending() ); + + } + + @Test + public void tasksAscendingWhenEmpty(){ + TodoList todoList = new TodoList(); + List strings = new ArrayList() {}; + + strings.add("No tasks available"); + + Assertions.assertLinesMatch(strings, todoList.tasksAscending() ); } } From d7536ceaa270459f9d6c7c183b1d61724715ccaa Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 16:48:57 +0100 Subject: [PATCH 19/25] Core done! Fixed some mistakes in tasksAscending() tests and finished the code. --- src/main/java/com/booleanuk/core/TodoList.java | 16 ++++++++++++++++ .../java/com/booleanuk/core/TodoListTest.java | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index ad4ecad4b..b1bcb9f09 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -114,4 +114,20 @@ public List tasksDescending(){ return strings; } + + public List tasksAscending(){ + List strings = new ArrayList(tasks.keySet()) {}; + String errorMsg = "No tasks available"; + + Collections.sort(strings); + + Collections.reverse(strings); + + if(strings.isEmpty()){ + strings.add(errorMsg); + return strings; + } + + return strings; + } } diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 25b643b7a..f03936cda 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -265,9 +265,9 @@ public void tasksAscendingWhenNotEmpty(){ todoList.add("vacuum"); todoList.add("walk the dog"); + strings.add("wash"); strings.add("walk the dog"); strings.add("vacuum"); - strings.add("wash"); strings.add("clean"); Assertions.assertLinesMatch(strings, todoList.tasksAscending() ); From 62f3430ba45f4d921b5852a0b51933315edfb76e Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 16:50:39 +0100 Subject: [PATCH 20/25] Wilmer Winkler --- .../java/com/booleanuk/core/TodoListTest.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index f03936cda..d78ee7f92 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -36,7 +36,7 @@ public void addTaskToListThatDoesNotAlreadyExist() { @Test public void listAllTasksInTodolist() { TodoList todoList = new TodoList(); - List strings = new ArrayList() {}; + List strings = new ArrayList<>() {}; @@ -53,7 +53,7 @@ public void listAllTasksInTodolist() { @Test public void listAllTasksInTodolistWhenItIsEmpty() { TodoList todoList = new TodoList(); - List strings = new ArrayList() {}; + List strings = new ArrayList<>() {}; strings.add("Your todolist is empty"); @@ -91,7 +91,7 @@ public void updateTaskStatusWithNonExistingName(){ @Test public void getCompletedTasksWhenNotEmpty(){ TodoList todoList = new TodoList(); - List strings = new ArrayList() {}; + List strings = new ArrayList<>() {}; todoList.add("clean"); todoList.add("wash"); @@ -110,7 +110,7 @@ public void getCompletedTasksWhenNotEmpty(){ @Test public void getCompletedTasksWhenEmpty(){ TodoList todoList = new TodoList(); - List strings = new ArrayList() {}; + List strings = new ArrayList<>() {}; todoList.add("clean"); todoList.add("wash"); @@ -125,7 +125,7 @@ public void getCompletedTasksWhenEmpty(){ @Test public void getUnCompletedTasksWhenEmpty(){ TodoList todoList = new TodoList(); - List strings = new ArrayList() {}; + List strings = new ArrayList<>() {}; todoList.add("clean"); todoList.add("wash"); @@ -145,7 +145,7 @@ public void getUnCompletedTasksWhenEmpty(){ @Test public void getUnCompletedTasksWhenNotEmpty(){ TodoList todoList = new TodoList(); - List strings = new ArrayList() {}; + List strings = new ArrayList<>() {}; todoList.add("clean"); todoList.add("wash"); @@ -164,7 +164,7 @@ public void getUnCompletedTasksWhenNotEmpty(){ @Test public void searchTaskThatDoesNotExist(){ TodoList todoList = new TodoList(); - List strings = new ArrayList() {}; + List strings = new ArrayList<>() {}; String taskName = "watch tv"; todoList.add("clean"); @@ -181,7 +181,7 @@ public void searchTaskThatDoesNotExist(){ @Test public void searchTaskThatDoesExist(){ TodoList todoList = new TodoList(); - List strings = new ArrayList() {}; + List strings = new ArrayList<>() {}; String taskName = "wash"; todoList.add("clean"); @@ -228,7 +228,7 @@ public void removeTaskThatDoesNotExist(){ @Test public void tasksDescendingWhenNotEmpty(){ TodoList todoList = new TodoList(); - List strings = new ArrayList() {}; + List strings = new ArrayList<>() {}; todoList.add("clean"); todoList.add("wash"); @@ -247,7 +247,7 @@ public void tasksDescendingWhenNotEmpty(){ @Test public void tasksDescendingWhenEmpty(){ TodoList todoList = new TodoList(); - List strings = new ArrayList() {}; + List strings = new ArrayList<>() {}; strings.add("No tasks available"); @@ -258,7 +258,7 @@ public void tasksDescendingWhenEmpty(){ @Test public void tasksAscendingWhenNotEmpty(){ TodoList todoList = new TodoList(); - List strings = new ArrayList() {}; + List strings = new ArrayList<>() {}; todoList.add("clean"); todoList.add("wash"); @@ -277,7 +277,7 @@ public void tasksAscendingWhenNotEmpty(){ @Test public void tasksAscendingWhenEmpty(){ TodoList todoList = new TodoList(); - List strings = new ArrayList() {}; + List strings = new ArrayList<>() {}; strings.add("No tasks available"); From 25ad0d5c461803a54ed832f6bbf58b9cd6407ad4 Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 16:52:16 +0100 Subject: [PATCH 21/25] Small corrections to the domain model --- domain-model.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/domain-model.md b/domain-model.md index 952fb2d5d..c1af95ab5 100644 --- a/domain-model.md +++ b/domain-model.md @@ -17,17 +17,17 @@ | getNotCompletedTasks() | | There are uncompleted tasks in the todolist | List with all uncompleted tasks | | | | There are no uncompleted tasks in the todolist | List with error message | | | | | | -| SearchTask(String) | | There was a task with the provided name | string with the task | +| SearchTask(String) | | There was a task with the provided name | string with a message | | | | There was no task with the provided name | string with error message | | | | | | | removeTask(String) | | Task with the provided name is not in the todolist | true | | | | Task with the provided name is in the todolist | false | | | | | | -| taskDescending() | | There are tasks in the todolist | string in descending order by name | -| | | There are no tasks in the todolist | string with error message | +| taskDescending() | | There are tasks in the todolist | List in descending order by name | +| | | There are no tasks in the todolist | List with error message | | | | | | -| taskAscending() | | There are tasks in the todolist | string in ascending order by name | -| | | There are no tasks in the todolist | string with error message | +| taskAscending() | | There are tasks in the todolist | List in ascending order by name | +| | | There are no tasks in the todolist | List with error message | From f55454e9d9f2ea04db0592d835da1aaca35d3985 Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Thu, 9 Jan 2025 16:52:28 +0100 Subject: [PATCH 22/25] Small corrections to the domain model --- domain-model.md | 56 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/domain-model.md b/domain-model.md index c1af95ab5..b3132843b 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1,33 +1,33 @@ ## Todo -| Method | Member Variable | Scenario | Result | -|-----------------------------------------------|--------------------------------|------------------------------------------------------------|-----------------------------------------| -| add(String name) | HashMap tasks | Task with the provided name is not already in the todolist | true | -| | | Task with the provided name is already in the todolist | false | -| | | | | -| listTasks( ) | | There are tasks in the todolist | List with all tasks | -| | | There are no tasks in the todolist | List with error message | -| | | | | -| updateTaskStatus(String name, Boolean status) | | There is a task with the provided name | true | -| | | There is no task with the provided name | false | -| | | | | -| getCompletedTasks() | | There are completed tasks in the todolist | List with all completed tasks | -| | | There are no completed tasks in the todolist | List with error message | -| | | | | -| getNotCompletedTasks() | | There are uncompleted tasks in the todolist | List with all uncompleted tasks | -| | | There are no uncompleted tasks in the todolist | List with error message | -| | | | | -| SearchTask(String) | | There was a task with the provided name | string with a message | -| | | There was no task with the provided name | string with error message | -| | | | | -| removeTask(String) | | Task with the provided name is not in the todolist | true | -| | | Task with the provided name is in the todolist | false | -| | | | | -| taskDescending() | | There are tasks in the todolist | List in descending order by name | -| | | There are no tasks in the todolist | List with error message | -| | | | | -| taskAscending() | | There are tasks in the todolist | List in ascending order by name | -| | | There are no tasks in the todolist | List with error message | +| Method | Member Variable | Scenario | Result | +|-----------------------------------------------|--------------------------------|------------------------------------------------------------|------------------------------------------| +| add(String name) | HashMap tasks | Task with the provided name is not already in the todolist | true | +| | | Task with the provided name is already in the todolist | false | +| | | | | +| listTasks( ) | | There are tasks in the todolist | List with all tasks | +| | | There are no tasks in the todolist | List with error message | +| | | | | +| updateTaskStatus(String name, Boolean status) | | There is a task with the provided name | true | +| | | There is no task with the provided name | false | +| | | | | +| getCompletedTasks() | | There are completed tasks in the todolist | List with all completed tasks | +| | | There are no completed tasks in the todolist | List with error message | +| | | | | +| getNotCompletedTasks() | | There are uncompleted tasks in the todolist | List with all uncompleted tasks | +| | | There are no uncompleted tasks in the todolist | List with error message | +| | | | | +| SearchTask(String) | | There was a task with the provided name | string with a message | +| | | There was no task with the provided name | string with error message | +| | | | | +| removeTask(String) | | Task with the provided name is not in the todolist | true | +| | | Task with the provided name is in the todolist | false | +| | | | | +| taskDescending() | | There are tasks in the todolist | List in descending order by name | +| | | There are no tasks in the todolist | List with error message | +| | | | | +| taskAscending() | | There are tasks in the todolist | List in ascending order by name | +| | | There are no tasks in the todolist | List with error message | From 8f6a9859f51ed19f5ca4a40f052b1949c626c469 Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Mon, 13 Jan 2025 19:49:03 +0100 Subject: [PATCH 23/25] Domain model updated and extensionTests are done. --- domain-model.md | 43 ++++++------- .../java/com/booleanuk/extension/Task.java | 48 ++++++++++++++ .../extension/TodoListExtension.java | 24 +++++++ .../extension/TodoListExtensionTest.java | 64 +++++++++++++++++++ 4 files changed, 157 insertions(+), 22 deletions(-) create mode 100644 src/main/java/com/booleanuk/extension/Task.java 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/domain-model.md b/domain-model.md index b3132843b..5bc8328e5 100644 --- a/domain-model.md +++ b/domain-model.md @@ -35,28 +35,27 @@ ## Todo -| Method | Member Variable | Scenario | Result | -|----------------------------------------------|-----------------------|----------|--------| -| add(String name) | ArrayList tasks | | | -| | id | | | -| listTasks( ) | | | | -| updateTaskStatus(Task task, Boolean state) | | | | -| | | | | -| getCompletedTasks() | | | | -| getNotCompletedTasks() | | | | -| SearchTask(Task task) | | | | -| removeTask(Task task) | | | | -| taskDescending() | | | | -| taskAscending() | | | | -| getTaskById(int id) | | | | -| updateTaskName(int id, String newName) | | | | -| updateTaskStatusById(int id, Boolean status) | | | | -| | | | | +| Method | Member Variable | Scenario | Result | +|----------------------------------------------|-----------------------|---------------------------------------------------|--------| +| | ArrayList tasks | | | +| | | | | +| | | | | +| | | | | +| getTaskById(int id) | | Search after a task with an existing ID | String | +| | | Search after a task with no existing ID | String | +| | | | | +| updateTaskName(int id, String newName) | | Update a task that exists with a new name | true | +| | | Update a task that does not exist with a new name | false | +| | | | | +| updateTaskStatusById(int id, Boolean status) | | Update a task that exists to wished status | true | +| | | Update a task that exists to wished status | false | ## Task -| Method | Member Variable | Scenario | Result | -|--------|------------------|----------|--------| -| | | | | -| | Boolean complete | | | -| | String name | | | \ No newline at end of file +| Method | Member Variable | Scenario | Result | +|---------------------|------------------|----------|--------| +| | int id | | | +| | String name | | | +| | Boolean complete | | | +| | String details | | | +| Getters and setters | | | | \ No newline at end of file diff --git a/src/main/java/com/booleanuk/extension/Task.java b/src/main/java/com/booleanuk/extension/Task.java new file mode 100644 index 000000000..3511317af --- /dev/null +++ b/src/main/java/com/booleanuk/extension/Task.java @@ -0,0 +1,48 @@ +package com.booleanuk.extension; + +public class Task { + + private int id = 0; + private String name; + private Boolean complete; + private String details; + + public Task(String name, String details){ + id++; + this.details = details; + complete = false; + } + + public Boolean getComplete() { + return complete; + } + + public void setComplete(Boolean complete) { + this.complete = complete; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} 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..5801b366c --- /dev/null +++ b/src/main/java/com/booleanuk/extension/TodoListExtension.java @@ -0,0 +1,24 @@ +package com.booleanuk.extension; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; + +public class TodoListExtension { + + public ArrayList extensionTask = new ArrayList<>(); + + public String getTaskByID(int id){ + + return "s"; + } + + public Boolean updateTaskName(int id, String newName){ + return true; + } + + public Boolean updateTaskStatusById(int id, Boolean status){ + return true; + } +} 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..12a4e174f --- /dev/null +++ b/src/test/java/com/booleanuk/extension/TodoListExtensionTest.java @@ -0,0 +1,64 @@ +package com.booleanuk.extension; + +import com.booleanuk.core.TodoList; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +public class TodoListExtensionTest { + + + @Test + public void getTaskByUniqueId(){ + TodoListExtension todoList = new TodoListExtension(); + Task task1 = new Task("Clean", "Vacuum"); + Task task2 = new Task("Wash", "Wash clothes"); + Task task3 = new Task("Dishes", "Empty the dishwasher"); + Task task4 = new Task("Garbage", "Take out the garbage"); + + todoList.extensionTask.add(task1); + todoList.extensionTask.add(task2); + todoList.extensionTask.add(task3); + todoList.extensionTask.add(task4); + + String output = "ID: " + task2.getId() + ", Name: " + task2.getName() + ", Complete: " + task2.getComplete() + ", Details: " + task2.getDetails(); + + Assertions.assertEquals(output, todoList.getTaskByID(1)); + + } + + @Test + public void updateNameWithTaskId(){ + TodoListExtension todoList = new TodoListExtension(); + Task task1 = new Task("Clean", "Vacuum"); + Task task2 = new Task("Wash", "Wash clothes"); + Task task3 = new Task("Dishes", "Empty the dishwasher"); + Task task4 = new Task("Garbage", "Take out the garbage"); + + todoList.extensionTask.add(task1); + todoList.extensionTask.add(task2); + todoList.extensionTask.add(task3); + todoList.extensionTask.add(task4); + + Assertions.assertTrue(todoList.updateTaskName(2, "Dishwasher")); + + } + + @Test + public void changeStatusWithTaskId(){ + TodoListExtension todoList = new TodoListExtension(); + Task task1 = new Task("Clean", "Vacuum"); + Task task2 = new Task("Wash", "Wash clothes"); + Task task3 = new Task("Dishes", "Empty the dishwasher"); + Task task4 = new Task("Garbage", "Take out the garbage"); + + todoList.extensionTask.add(task1); + todoList.extensionTask.add(task2); + todoList.extensionTask.add(task3); + todoList.extensionTask.add(task4); + + Assertions.assertTrue(todoList.updateTaskStatusById(3, true)); + } +} From 8470a0f4437e3670a7c94bec15f21a6d896478b1 Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Mon, 13 Jan 2025 20:14:22 +0100 Subject: [PATCH 24/25] Extension done! --- domain-model.md | 15 ++++---- .../java/com/booleanuk/extension/Task.java | 22 ++++------- .../extension/TodoListExtension.java | 38 +++++++++++++++++-- .../extension/TodoListExtensionTest.java | 21 +++++++++- 4 files changed, 71 insertions(+), 25 deletions(-) diff --git a/domain-model.md b/domain-model.md index 5bc8328e5..082780687 100644 --- a/domain-model.md +++ b/domain-model.md @@ -52,10 +52,11 @@ ## Task -| Method | Member Variable | Scenario | Result | -|---------------------|------------------|----------|--------| -| | int id | | | -| | String name | | | -| | Boolean complete | | | -| | String details | | | -| Getters and setters | | | | \ No newline at end of file +| Method | Member Variable | Scenario | Result | +|---------------------|----------------------|----------|--------| +| | Static int idCounter | | | +| | int id | | | +| | String name | | | +| | Boolean complete | | | +| | String details | | | +| Getters and setters | | | | \ No newline at end of file diff --git a/src/main/java/com/booleanuk/extension/Task.java b/src/main/java/com/booleanuk/extension/Task.java index 3511317af..47a460a93 100644 --- a/src/main/java/com/booleanuk/extension/Task.java +++ b/src/main/java/com/booleanuk/extension/Task.java @@ -2,13 +2,15 @@ public class Task { - private int id = 0; + public static int idCounter = 0; + private int id; private String name; private Boolean complete; private String details; public Task(String name, String details){ - id++; + id = idCounter++; + this.name = name; this.details = details; complete = false; } @@ -25,18 +27,6 @@ public String getDetails() { return details; } - public void setDetails(String details) { - this.details = details; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - public String getName() { return name; } @@ -45,4 +35,8 @@ public void setName(String name) { this.name = name; } + public int getId() { + return id; + } + } diff --git a/src/main/java/com/booleanuk/extension/TodoListExtension.java b/src/main/java/com/booleanuk/extension/TodoListExtension.java index 5801b366c..6c485c075 100644 --- a/src/main/java/com/booleanuk/extension/TodoListExtension.java +++ b/src/main/java/com/booleanuk/extension/TodoListExtension.java @@ -10,15 +10,47 @@ public class TodoListExtension { public ArrayList extensionTask = new ArrayList<>(); public String getTaskByID(int id){ + String output = "No task with that ID was found"; + for(Task task : extensionTask){ + if(id == task.getId()){ + output = "ID: " + task.getId() + ", Name: " + task.getName() + ", Complete: " + task.getComplete() + ", Details: " + task.getDetails(); + } + } - return "s"; + return output; } public Boolean updateTaskName(int id, String newName){ - return true; + for(Task task : extensionTask){ + if(id == task.getId()){ + task.setName(newName); + } + } + + for(Task task : extensionTask){ + if(task.getName() == newName){ + task.setName(newName); + return true; + } + } + + return false; } public Boolean updateTaskStatusById(int id, Boolean status){ - return true; + for(Task task : extensionTask){ + if(id == task.getId()){ + task.setComplete(status); + } + } + + for(Task task : extensionTask){ + if(id == task.getId()){ + if(task.getComplete() == status){ + return true; + } + } + } + return false; } } diff --git a/src/test/java/com/booleanuk/extension/TodoListExtensionTest.java b/src/test/java/com/booleanuk/extension/TodoListExtensionTest.java index 12a4e174f..728fb4542 100644 --- a/src/test/java/com/booleanuk/extension/TodoListExtensionTest.java +++ b/src/test/java/com/booleanuk/extension/TodoListExtensionTest.java @@ -11,7 +11,7 @@ public class TodoListExtensionTest { @Test - public void getTaskByUniqueId(){ + public void getTaskByUniqueIdThatDoesExist(){ TodoListExtension todoList = new TodoListExtension(); Task task1 = new Task("Clean", "Vacuum"); Task task2 = new Task("Wash", "Wash clothes"); @@ -29,6 +29,25 @@ public void getTaskByUniqueId(){ } + @Test + public void getTaskByUniqueIdThatDoesNotExist(){ + TodoListExtension todoList = new TodoListExtension(); + Task task1 = new Task("Clean", "Vacuum"); + Task task2 = new Task("Wash", "Wash clothes"); + Task task3 = new Task("Dishes", "Empty the dishwasher"); + Task task4 = new Task("Garbage", "Take out the garbage"); + + todoList.extensionTask.add(task1); + todoList.extensionTask.add(task2); + todoList.extensionTask.add(task3); + todoList.extensionTask.add(task4); + + String output = "No task with that ID was found"; + + Assertions.assertEquals(output, todoList.getTaskByID(6)); + + } + @Test public void updateNameWithTaskId(){ TodoListExtension todoList = new TodoListExtension(); From d867897a842cfc2b459b48409dfe4fed6b74f97a Mon Sep 17 00:00:00 2001 From: Wilmer Winkler Date: Wed, 15 Jan 2025 16:43:17 +0100 Subject: [PATCH 25/25] Extension done! --- .../com/booleanuk/extension/TodoListExtension.java | 2 ++ .../booleanuk/extension/TodoListExtensionTest.java | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/booleanuk/extension/TodoListExtension.java b/src/main/java/com/booleanuk/extension/TodoListExtension.java index 6c485c075..19b10edca 100644 --- a/src/main/java/com/booleanuk/extension/TodoListExtension.java +++ b/src/main/java/com/booleanuk/extension/TodoListExtension.java @@ -53,4 +53,6 @@ public Boolean updateTaskStatusById(int id, Boolean status){ } return false; } + + } diff --git a/src/test/java/com/booleanuk/extension/TodoListExtensionTest.java b/src/test/java/com/booleanuk/extension/TodoListExtensionTest.java index 728fb4542..e1b016841 100644 --- a/src/test/java/com/booleanuk/extension/TodoListExtensionTest.java +++ b/src/test/java/com/booleanuk/extension/TodoListExtensionTest.java @@ -2,6 +2,7 @@ import com.booleanuk.core.TodoList; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.ArrayList; @@ -9,6 +10,10 @@ public class TodoListExtensionTest { + @BeforeEach + public void reset(){ + Task.idCounter = 0; + } @Test public void getTaskByUniqueIdThatDoesExist(){ @@ -27,6 +32,7 @@ public void getTaskByUniqueIdThatDoesExist(){ Assertions.assertEquals(output, todoList.getTaskByID(1)); + } @Test @@ -44,7 +50,8 @@ public void getTaskByUniqueIdThatDoesNotExist(){ String output = "No task with that ID was found"; - Assertions.assertEquals(output, todoList.getTaskByID(6)); + Assertions.assertEquals(output, todoList.getTaskByID(100)); + } @@ -63,6 +70,7 @@ public void updateNameWithTaskId(){ Assertions.assertTrue(todoList.updateTaskName(2, "Dishwasher")); + } @Test @@ -79,5 +87,7 @@ public void changeStatusWithTaskId(){ todoList.extensionTask.add(task4); Assertions.assertTrue(todoList.updateTaskStatusById(3, true)); + + } }