diff --git a/src/main/domain-model.md b/src/main/domain-model.md new file mode 100644 index 000000000..f4d4c2d80 --- /dev/null +++ b/src/main/domain-model.md @@ -0,0 +1,62 @@ +Requirements +as a user i want +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. + + + +I want to add tasks to my todo list. + + +| Classes | Members | Methods | Scenario | Outputs | +|----------------------------------------------------|-------------------|---------------|----------------------------------|---------| +| `TodoList(List of Task objects (Also A object??))` | (`Task (Object)`) | `Add(Task())` | Add a task to todolist (success) | true | + +I want to see all the tasks in my todo list. + + + +| Classes | Members | Methods | Scenario | Outputs | +|----------------------------------|-------------------|-----------|--------------------------|---------------------------------| +| `TodoList(List of Task objects)` | (`Task (Object)`) | `show()` | if todolist is empty | false | +| | | | if todolist is has tasks | return tasks in todolist (true) | + +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. + + +| Classes | Members | Methods | Scenario | Outputs | +|----------------------------------------------------|-------------------|-------------------------|-----------------------------------------------|--------------------------------| +| `TodoList(List of Task objects)` | (`Task (Object)`) | `changeStatus(Task() )` | if todolist has a task which is not completed | "Task turned to completed" | +| | | | if todolist has a task which is completed | "Task turned to not completed" | +| | | | if task is null | "task not found" | +| | | | | | +| `TodoList(List of Task objects)` | (`Task (Object)`) | `show()` | if todolist is empty | false | +| | | | if todolist is has tasks | return tasks in todolist | +| `TodoList(List of Task objects (Also A object??))` | (`Task (Object)`) | `Add(Task())` | Add a task to todolist (success) | true | +| | | | if task not exist | false | +| | | `completed()` | if zero completed tasks | false | +| | | | if there are completed tasks | true | +| | | `notCompleted()` | if all tasks completed or zero tasks | false | +| | | | if there are incompleted tasks | todolist with the tasks | +| | | `search(Task())` | if task is found | true | +| | | `remove(Task())` | if task is not found | false | +| | | | if task is found | returns the deleted task | +| | | `ascending()` | if todo list is empty | false | +| | | | if todo list has tasks | true | +| | | `descending()` | if todo list is empty | false | +| | | | if todo list has tasks | true | +| | | | | | + + diff --git a/src/main/java/com/booleanuk/core/Task.java b/src/main/java/com/booleanuk/core/Task.java new file mode 100644 index 000000000..560e80d5a --- /dev/null +++ b/src/main/java/com/booleanuk/core/Task.java @@ -0,0 +1,38 @@ +package com.booleanuk.core; + +public class Task { + public String title; + public String description; + public boolean status; + //Assertions.assertEquals(newtask, todo.search("Do Homework")); + // Assertions.assertEquals(newtask2, todo.search("Make Food")); + + + public Task(String title, String description, boolean status) { + this.title = title; + this.description = description; + this.status = status; + } + + public Task() { + this.title = "TheTitle"; + this.description = "The Description"; + this.status = false; + } + + public String show(){ + return "Here is the tasks\n"+ title +" " +description + " is it done? " + ((status) ? " JA " : " nei "); + } + + public boolean isStatus() { + return status; + } + + public void setStatus(boolean status) { + this.status = status; + } + + public String getTitle() { + return title; + } +} diff --git a/src/main/java/com/booleanuk/core/TodoList.java b/src/main/java/com/booleanuk/core/TodoList.java index 675adaf0b..ac79e8c2f 100644 --- a/src/main/java/com/booleanuk/core/TodoList.java +++ b/src/main/java/com/booleanuk/core/TodoList.java @@ -1,5 +1,135 @@ package com.booleanuk.core; -public class TodoList { +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +public class TodoList { //should I use public variables or private? + public ArrayList tasks; + + + public TodoList(Task tasks) { + this.tasks = new ArrayList(); + this.tasks.add(tasks); + + } + + public boolean addtask(Task addedtask){ + this.tasks.add(addedtask); + // this.tasks.set(0, new Task()); + return true; + + } + public boolean show(){ + for (Task task: tasks){ + task.show(); + + } + return true; + } + + + + public String changeStatus(Task addedtask){ + if (addedtask.isStatus()){ + addedtask.setStatus(false); + return "Task turned to not completed"; + } + addedtask.setStatus(true); + return "Task turned to completed"; + } + + public boolean completed(){ + boolean found = false; + for (Task task: tasks){ + if (task.isStatus()){ + task.show(); + found = true; + } + + } + return found; + } + public boolean notCompleted(){ + boolean found = false; + for (Task task: tasks){ + if (!task.isStatus()){ + task.show(); + found = true; + } + + } + return found; + } + public boolean search(String query){ + for (Task task: tasks){ + if (Objects.equals(task.getTitle(), query)){ + task.show(); + return true; + } + } + return false; + } + public boolean remove(String title){ + + for (Task task: tasks){ + if (Objects.equals(task.getTitle(), title)){ + task.show(); + tasks.remove((task)); + return true; + } + } + return false; + } + public boolean ascending(){ + Task[] toBeSorted = new Task[tasks.size()]; + Task temp; + + for (int i = 0; i < toBeSorted.length; i ++) { + toBeSorted[i] = tasks.get(i); + } + + for (int i = 0; i < tasks.size(); i ++) { + for (int j = i + 1; j < tasks.size(); j ++) { + + if (toBeSorted[i].description.compareTo(toBeSorted[j].description) > 0) { + temp = toBeSorted[i]; + toBeSorted[i] = toBeSorted[j]; + toBeSorted[j] = temp; + } + } + } + List ascending = new ArrayList<>(); + ascending.addAll(List.of(toBeSorted)); + return true; + + } + public boolean descending(){ + if (tasks.isEmpty()){ + return false; + } + + Task[] toBeSorted = new Task[tasks.size()]; + Task temp; + + for (int i = 0; i < toBeSorted.length; i ++) { + toBeSorted[i] = tasks.get(i); + } + + for (int i = 0; i < tasks.size(); i ++) { + for (int j = i + 1; j < tasks.size(); j ++) { + + if (toBeSorted[i].description.compareTo(toBeSorted[j].description) < 0) { + temp = toBeSorted[i]; + toBeSorted[i] = toBeSorted[j]; + toBeSorted[j] = temp; + } + } + } + List descending = new ArrayList<>(); + descending.addAll(List.of(toBeSorted)); + return true; + } } diff --git a/src/test/java/com/booleanuk/core/TodoListTest.java b/src/test/java/com/booleanuk/core/TodoListTest.java index 0bef779a4..d4c65e138 100644 --- a/src/test/java/com/booleanuk/core/TodoListTest.java +++ b/src/test/java/com/booleanuk/core/TodoListTest.java @@ -5,9 +5,186 @@ class TodoListTest { @Test - public void exampleTest() { - String hello = "Hello"; - Assertions.assertEquals("Hello", hello); - Assertions.assertNotEquals("Goodbye", hello); + public void addTasksTest() { + Task newtask = new Task("TheTitle", "The Description", false); + + TodoList todo = new TodoList(newtask); + Assertions.assertEquals(true, todo.addtask(newtask)); + + } + @Test + public void showTasksTest() { + Task newtask = new Task("TheTitle", "The Description", false); + + TodoList todo = new TodoList(newtask); + Task newtask2 = new Task("TheTitle2", "The Description111", true); + Assertions.assertEquals(true, todo.show()); + + todo.addtask(newtask); + Assertions.assertEquals(true, todo.show()); + todo.addtask(newtask2); + Assertions.assertEquals(true, todo.show()); + + } + @Test + public void ChangeStatusTest() { + Task newtask = new Task("TheTitle", "The Description", false); + + newtask.setStatus(false); + TodoList todo = new TodoList(newtask); + + + Assertions.assertEquals("Task turned to completed", todo.changeStatus(newtask)); + Assertions.assertEquals("Task turned to not completed", todo.changeStatus(newtask)); + + + } + @Test + public void showCompletedTest() { + Task newtask = new Task("TheTitle", "The Description", false); + newtask.setStatus(false); + + + + TodoList todo = new TodoList(newtask); + Task newtask2 = new Task("TheTitle22", "The Description222", false); + + + + todo.addtask(newtask2); + Assertions.assertEquals(false, todo.completed()); + + newtask.setStatus(true); + + + Assertions.assertEquals(new TodoList(newtask).addtask(newtask), todo.completed()); + + + + + } + + @Test + public void showNotCompletedTest() { + Task newtask = new Task("TheTitle", "The Description", true); + + TodoList todo = new TodoList(newtask); + Assertions.assertEquals(false, todo.notCompleted()); + + Task newtask2 = new Task("TheTitle", "The Description", false); + + + todo.addtask(newtask2); + + Assertions.assertEquals(true, todo.notCompleted()); + } + + @Test + public void searchTest() { + Task newtask = new Task("Make Food", "The Description", false); + + TodoList todo = new TodoList(newtask); + + Task newtask2 = new Task("Do Homework", "The Description", false); + + Assertions.assertEquals(false, todo.search("Buy Gifts")); + + + todo.addtask(newtask2); + Assertions.assertEquals(false, todo.search("Buy Gifts")); + Assertions.assertEquals(false, todo.search("D H")); + Assertions.assertEquals(false, todo.search("Mak food")); + Assertions.assertEquals(false, todo.search("Do Laundry")); + Assertions.assertEquals(false, todo.search("Eat cakes")); + Assertions.assertEquals(false, todo.search("Buy a kebab")); + + + Assertions.assertEquals(true, todo.search("Do Homework")); + Assertions.assertEquals(true, todo.search("Make Food")); + } + + @Test + public void removeTest() { + Task newtask = new Task("Do Homework", "The Description", false); + + TodoList todo = new TodoList(newtask); + + Task newtask2 = new Task("Make Food", "The Description", false); + Assertions.assertEquals(false, todo.remove("Buy Gifts")); + + + todo.addtask(newtask2); + Assertions.assertEquals(false, todo.remove("Buy Gifts")); + Assertions.assertEquals(false, todo.remove("D H")); + Assertions.assertEquals(false, todo.remove("Mak food")); + Assertions.assertEquals(false, todo.remove("Do Laundry")); + Assertions.assertEquals(false, todo.remove("Eat cakes")); + Assertions.assertEquals(false, todo.remove("Buy a kebab")); + + + Assertions.assertEquals(true, todo.remove("Do Homework")); + + Assertions.assertEquals(false, todo.remove("Do Homework")); + Assertions.assertEquals(true, todo.remove("Make Food")); + Assertions.assertEquals(false, todo.remove("Make Food")); + } + + @Test + public void ascendingTest() { + Task newtask = new Task("TheTitle", "The Description", false); + + TodoList todo = new TodoList(newtask); + todo.remove(("TheTitle")); + Assertions.assertEquals(true, todo.ascending()); + + Task newtask2 = new Task("A", "The Description", false); + Task newtask3 = new Task("B", "The Description", false); + Task newtask4 = new Task("C", "The Description", false); + + + + + + todo.addtask(newtask2); + todo.addtask(newtask3); + todo.addtask(newtask4); + todo.addtask(newtask); + Assertions.assertEquals(true, todo.ascending()); + + + + + + + + } + @Test + public void descendingTest() { + Task newtask = new Task("TheTitle", "The Description", false); + + TodoList todo = new TodoList(newtask); + todo.remove(("TheTitle")); + Assertions.assertEquals(true, todo.ascending()); + + Task newtask2 = new Task("A", "The Description", false); + Task newtask3 = new Task("B", "The Description", false); + Task newtask4 = new Task("C", "The Description", false); + + + + + + todo.addtask(newtask2); + todo.addtask(newtask3); + todo.addtask(newtask4); + todo.addtask(newtask); + Assertions.assertEquals(true, todo.ascending()); + + + + + + } + }