Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
20a7794
First version domain model, from collaboration with peers
Jan 9, 2025
d47db52
testAddNewTaskToList red implementation
Jan 9, 2025
1830704
Added add method to pass testAddNewTaskToList green implementation. S…
Jan 9, 2025
7b563d9
Forgot to add test to check for already existing task, added now but …
Jan 9, 2025
e901abb
Added red testListAllTasks - no code
Jan 9, 2025
8724116
Corrected testListAllTasks
Jan 9, 2025
ad01e12
Add method listTasks to make testListAllTasks pass/be green + minor f…
Jan 9, 2025
2afd709
Added testListNoTask- red
Jan 9, 2025
aed16d6
Add code to make testListNoTask pass - green
Jan 9, 2025
f181fac
Add failing test testUpdateTaskStatusFalseToTrue - red
Jan 9, 2025
aae7916
Add method updateTaskStatus to pass testUpdateTaskStatusFalseToTrue …
Jan 9, 2025
868a461
Update method updateTaskStatus to pass more cases of testUpdateTask…
Jan 9, 2025
91bedff
Update method updateTaskStatus and test to pass more cases of testU…
Jan 9, 2025
4f817f3
Add failing testListCompletedTasks - red
Jan 9, 2025
01bc325
Update domain model and add not completed code for listCompletedTasks…
Jan 9, 2025
623b0af
Refactor TodoList to keep HashMap of tasks
Jan 16, 2025
962d34e
Add testListCompletedTasks - red
Jan 16, 2025
2321fe3
Add method listCompletedTasks - green
Jan 16, 2025
e85df57
Add testListNotCompletedTasks - red
Jan 16, 2025
316b049
Add method listNotCompletedTasks - green
Jan 16, 2025
e1a35e4
Add testSearchForTask - red
Jan 16, 2025
e9ac4b8
Add method searchForTask - green
Jan 16, 2025
0ba23e9
Add testRemoveTask - red
Jan 16, 2025
2f9b6f6
Add an actual task to remove in testRemoveTask - red
Jan 16, 2025
084bb71
Add method removeTask - green
Jan 16, 2025
cb63462
Refactor removeTask to verify task is actually removed from list - green
Jan 16, 2025
2393460
Refactor removeTask and test to verify task was on todolist before - …
Jan 16, 2025
bf463d5
Add testListAscending - red
Jan 16, 2025
5641ca6
Add method listAscending - green
Jan 16, 2025
ac48219
Add testListDescending - red
Jan 16, 2025
a8ead4e
Add method listDescending - green
Jan 16, 2025
729ddbd
Refactor listCompletedTasks and listNotCompletedTasks and their tests…
Jan 16, 2025
f8aa976
Refactor listAscending and listDescending and their tests to account …
Jan 16, 2025
3c5be4c
Update domain-model to reflect code
Jan 16, 2025
99e660f
Add updated domain model for extension and add testGetTaskById - red
Jan 20, 2025
4cab06c
Add Task object and getTaskById to pass test - green
Jan 21, 2025
819f201
Refactor getTaskById and test to cover incomplete tasks - green
Jan 21, 2025
2bd75bb
Add testUpdateTaskName - red
Jan 21, 2025
9ddfb63
Add method updateTaskName to pass test - green
Jan 21, 2025
008a123
Refactor testUpdateTaskName to include incomplete task - green
Jan 21, 2025
c680182
Add testUpdateTaskStatus - red
Jan 21, 2025
b45ddcf
Add method updateTaskStatus to pass test and add assertion for incomp…
Jan 21, 2025
067d363
Add testShoeDateTime for empty list - red
Jan 21, 2025
564506c
Add method showDateTime for empty list - green
Jan 21, 2025
78c341d
Refactor method showDateTime for non-empty list and add assertion for…
Jan 21, 2025
852996b
Update domain-model
Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Core TodoList class

| Method | Member Variable | Scenario | Result |
|-------------------------------|--------------------------------|-------------------------------------------------------------------------------|-------------------------------------|
| add(String name) | HashMap<String, Boolean> 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) | | 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 |
| | | | |
| listCompletedTasks() | | There are completed tasks in the todolist | string with all completed tasks |
| | | There are no completed tasks in the todolist | string with error message |
| | | | |
| listNotCompletedTasks() | | There are uncompleted tasks in the todolist | string with all uncompleted tasks |
| | | There are no uncompleted tasks in the todolist | string with error message |
| | | | |
| searchForTask(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 was in todolist and has been removed | string with confirmation of removal |
| | | Task was not in todolist or could not be removed | string with error message |
| | | | |
| 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 TodoList class

| Method | Member Variables | Scenario | Result |
|-------------------------------------|------------------|------------------------------------------|-----------------------------|
| | ArrayList<Task> | | |
| | | | |
| getTaskById(int id) | | incomplete task | message string |
| | | completed task | message string |
| updateTaskName(int id, String name) | | incomplete task | message string |
| | | completed task | message string |
| updateTaskStatus(int id) | | task exists and has been completed | true |
| | | task exists and is not completed anymore | false |
| showDateTime() | | list has tasks | string of tasks |
| | | last has no tasks | string message for no tasks |

## Extension Task class

| Method | Member variables | Scenario | Result |
|---------|------------------|----------|--------|
| | int id | | |
| | String name | | |
| | boolean status | | |
| | String time | | |
| getters | | | |
| setters | | | |

109 changes: 109 additions & 0 deletions src/main/java/com/booleanuk/core/TodoList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,114 @@
package com.booleanuk.core;

import java.util.*;

public class TodoList {
private HashMap<String, Boolean> tasks;

public TodoList(HashMap<String, Boolean> tasks) {
this.tasks = new HashMap<>(tasks);
}

public Boolean add(String name) {
Boolean status = false;
if (!tasks.containsKey(name)) {
tasks.put(name, status);
return true;
}
return false;
}

public String listTasks() {
String output;
if (tasks.isEmpty()) {
output = "Todo-list is empty";
return output;
}
output = tasks.keySet().toString();
return output;
}

public Boolean updateTaskStatus(String name) {
if (!tasks.containsKey(name)) {
return false;
}
if (tasks.get(name).equals(false)) {
tasks.put(name, true);
return true;
} else if (tasks.get(name).equals(true)) {
tasks.put(name, false);
return true;
}
return false;
}

public String listCompletedTasks() {
if (tasks.containsValue(true)) {
StringBuilder completed = new StringBuilder();
for (Map.Entry<String, Boolean> task : tasks.entrySet()) {
if (task.getValue()) {
completed.append(task.getKey()).append(", ");
}
}
return completed.toString();
}
return "You have no completed tasks";
}

public String listNotCompletedTasks() {
if (tasks.containsValue(false)) {
StringBuilder completed = new StringBuilder();
for (Map.Entry<String, Boolean> task : tasks.entrySet()) {
if (!task.getValue()) {
completed.append(task.getKey()).append(", ");
}
}
return completed.toString();
}
return "You have no incomplete tasks";
}

public String searchForTask(String task) {
if (!tasks.containsKey(task)) {
return "Task could not be found";
}
return "Here's your task: " + task;
}

public String removeTask(String task) {
if (!tasks.containsKey(task)) {
return "This task is not on your todolist";
}
tasks.remove(task);
if (!tasks.containsKey(task)) {
return "Task removed successfully";
}
return "Could not remove task";
}

public String listAscending() {
if (!tasks.isEmpty()) {
StringBuilder ascending = new StringBuilder();
List<String> tasksNames = new ArrayList<>(tasks.keySet());
Collections.sort(tasksNames);
for (String task : tasksNames) {
ascending.append(task).append(", ");
}
return ascending.toString();
}
return "Your todolist is empty";
}

public String listDescending() {
if (!tasks.isEmpty()) {
StringBuilder ascending = new StringBuilder();
List<String> tasksNames = new ArrayList<>(tasks.keySet());
Collections.sort(tasksNames, Collections.reverseOrder());
for (String task : tasksNames) {
ascending.append(task).append(", ");
}
return ascending.toString();
}
return "Your todolist is empty";
}
}
50 changes: 50 additions & 0 deletions src/main/java/com/booleanuk/extension/ExtensionTodoList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.booleanuk.extension;

import java.util.ArrayList;

public class ExtensionTodoList {

private ArrayList<Task> tasks;

public ExtensionTodoList(ArrayList<Task> tasks) {
this.tasks = new ArrayList<>(tasks);
}

public String getTaskById(int id) {
String output;
Task task = this.tasks.get(id);
if (task.isStatus()) {
output = task.getName() + ", completed";
return output;
}
output = task.getName() + ", incomplete";
return output;
}

public String updateTaskName(int id, String name) {
Task task = this.tasks.get(id);
task.setName(name);
return "Task successfully updated to: " + task.getName();
}

public boolean updateTaskStatus(int id) {
Task task = this.tasks.get(id);
if (!task.isStatus()) {
task.setStatus(true);
return task.isStatus();
}
task.setStatus(false);
return task.isStatus();
}

public String showDateTime() {
StringBuilder output = new StringBuilder();
if (this.tasks.isEmpty()) {
return "Todolist is empty";
}
for (Task task : tasks) {
output.append("Task: ").append(task.getName()).append(", Created on: ").append(task.getTime()).append("\n");
}
return output.toString();
}
}
49 changes: 49 additions & 0 deletions src/main/java/com/booleanuk/extension/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.booleanuk.extension;

public class Task {
private static int nextId = 1;
private int id;
private String name;
private boolean status;
private String time;

public Task(String name, boolean status, String time) {
this.id = nextId;
nextId++;
this.name = name;
this.status = status;
this.time = time;
}

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;
}

public boolean isStatus() {
return status;
}

public void setStatus(boolean status) {
this.status = status;
}

public String getTime() {
return time;
}

public void setTime(String time) {
this.time = time;
}
}
85 changes: 81 additions & 4 deletions src/test/java/com/booleanuk/core/TodoListTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,90 @@
package com.booleanuk.core;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.HashMap;

class TodoListTest {

private TodoList todoList;

@BeforeEach
public void setUp() {
HashMap<String, Boolean> tasks = new HashMap<>() {{
put("Tidy up", false);
put("Lunch", true);
}};
todoList = new TodoList(tasks);
}

@Test
public void testAddNewTaskToList() {
Assertions.assertTrue(todoList.add("Sleep"));
}

@Test
public void testAddOldTaskToList() {
Assertions.assertFalse(todoList.add("Lunch"));
}

@Test
public void testListAllTasks() {
Assertions.assertEquals("[Tidy up, Lunch]", todoList.listTasks());
}

@Test
public void testListNoTask() {
HashMap<String, Boolean> noTasks = new HashMap<>();
TodoList todoList = new TodoList(noTasks);
Assertions.assertEquals("Todo-list is empty", todoList.listTasks());
}

@Test
public void testUpdateTaskStatus() {
Assertions.assertTrue(todoList.updateTaskStatus("Tidy up"));
Assertions.assertTrue(todoList.updateTaskStatus("Lunch"));
}

@Test
public void testListCompletedTasks() {
Assertions.assertEquals("Lunch, ", todoList.listCompletedTasks());
todoList.removeTask("Lunch");
Assertions.assertEquals("You have no completed tasks", todoList.listCompletedTasks());
}

@Test
public void testListNotCompletedTasks() {
Assertions.assertEquals("Tidy up, ", todoList.listNotCompletedTasks());
todoList.removeTask("Tidy up");
Assertions.assertEquals("You have no incomplete tasks", todoList.listNotCompletedTasks());
}

@Test
public void testSearchForTask() {
Assertions.assertEquals("Task could not be found", todoList.searchForTask("Shower"));
}

@Test
public void testRemoveTask() {
Assertions.assertEquals("Task removed successfully", todoList.removeTask("Lunch"));
Assertions.assertEquals("This task is not on your todolist", todoList.removeTask("Shower"));
}

@Test
public void testListsAscending() {
Assertions.assertEquals("Lunch, Tidy up, ", todoList.listAscending());
todoList.removeTask("Lunch");
todoList.removeTask("Tidy up");
Assertions.assertEquals("Your todolist is empty", todoList.listAscending());
}

@Test
public void exampleTest() {
String hello = "Hello";
Assertions.assertEquals("Hello", hello);
Assertions.assertNotEquals("Goodbye", hello);
public void testListsDescending() {
Assertions.assertEquals("Tidy up, Lunch, ", todoList.listDescending());
todoList.removeTask("Lunch");
todoList.removeTask("Tidy up");
Assertions.assertEquals("Your todolist is empty", todoList.listDescending());
}
}
Loading
Loading