Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 30 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

# TodoList class

| Members | Methods | Scenarios | Result |
|------------------------|--------------------------------------------------------|----------------------------------|-----------------------------|
| ArrayList\<Task> tasks | boolean add(Task task) | Task is already in list | False |
| | | Task is not in list | True |
| | ArrayList\<Task> viewTasks() | | Return entire todo list |
| | ArrayList\<Task> viewIncompleteTasks() | | Return incomplete task list |
| | ArrayList\<Task> viewCompleteTasks() | | Return complete task list |
| | Task searchTask(Task task) | Task not found | Return null + error message |
| | | Task found | Return task |
| | void removeTask(Task task) | Task to be removed doesn't exist | Do nothing |
| | | Task to be removed exists | Remove task from todo list |
| | ArrayList\<String> alphabeticallyAscView() | | Return sorted todo list |
| | ArrayList\<String> alphabeticallyDescView() | | Return sorted todo list |
| | void updateTaskNameByID(UUID uid, String newName) | Invalid ID or task doesn't exist | Do nothing |
| | | Valid ID and task exists | Update the task name |
| | void updateTaskStatusByID(UUID uid, boolean newStatus) | Invalid ID or task doesn't exist | Do nothing |
| | | Valid ID and task exists | Update the task status |
| | TaskExtension getTaskByID(UUID uid) | Invalid ID or task doesn't exist | Do nothing |
| | | Valid ID and task exists | Return the task by ID |

# Task class

| Members | Methods | Scenarios | Result |
|------------------|-----------------------------------|-----------------|-------------------------------|
| boolean complete | void changeStatus(boolean status) | status is true | Member complete becomes true |
| String name | | status is false | Member complete becomes false |
| UUID uid | | | |
16 changes: 16 additions & 0 deletions src/main/java/com/booleanuk/core/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.booleanuk.core;

public class Task {
String name;
boolean complete;

public Task(String name) {
this.name = name;
this.complete = false;

}

public void changeStatus(boolean status) {
this.complete = status;
}
}
72 changes: 72 additions & 0 deletions src/main/java/com/booleanuk/core/TodoList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,77 @@
package com.booleanuk.core;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Comparator;

public class TodoList {

ArrayList<Task> tasks = new ArrayList<>();


public boolean add(Task task) {
if (!tasks.contains(task)) {
tasks.add(task);
return true;
}
return false;
}

public ArrayList<Task> viewTasks() {
return tasks;
}

public ArrayList<Task> viewIncompleteTasks() {
ArrayList<Task> incomplete = new ArrayList<>();
for (Task task : this.tasks) {
if (!task.complete) {
incomplete.add(task);
}
}
return incomplete;
}

public ArrayList<Task> viewCompleteTasks() {
ArrayList<Task> complete = new ArrayList<>();
for (Task task : this.tasks) {
if (task.complete) {
complete.add(task);
}
}
return complete;
}

Task searchTask(Task task) {
if(tasks.contains(task)) {
return task;
}
System.out.println("Task not found!");
return null;
}

void removeTask(Task task) {
this.tasks.remove(task);

}

ArrayList<String> alphabeticallyAscView() {
ArrayList<String> results = new ArrayList<>();
for (Task task : this.tasks) {
results.add(task.name);

}
results.sort(null);
return results;
}

ArrayList<String> alphabeticallyDescView() {
ArrayList<String> results = new ArrayList<>();
for (Task task : this.tasks) {
results.add(task.name);

}
results.sort(Comparator.reverseOrder());
return results;
}

}
20 changes: 20 additions & 0 deletions src/main/java/com/booleanuk/extension/TaskExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.booleanuk.extension;
import java.util.UUID;

public class TaskExtension {
String name;
boolean complete;
UUID uid;

public TaskExtension(String name) {
this.name = name;
this.complete = false;
this.uid = UUID.randomUUID();

}

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

}
101 changes: 101 additions & 0 deletions src/main/java/com/booleanuk/extension/TodoListExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.booleanuk.extension;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.UUID;

public class TodoListExtension {

ArrayList<TaskExtension> tasks = new ArrayList<>();


public boolean add(TaskExtension task) {
if (!tasks.contains(task)) {
tasks.add(task);
return true;
}
return false;
}

public ArrayList<TaskExtension> viewTasks() {
return tasks;
}

public ArrayList<TaskExtension> viewIncompleteTasks() {
ArrayList<TaskExtension> incomplete = new ArrayList<>();
for (TaskExtension task : this.tasks) {
if (!task.complete) {
incomplete.add(task);
}
}
return incomplete;
}

public ArrayList<TaskExtension> viewCompleteTasks() {
ArrayList<TaskExtension> complete = new ArrayList<>();
for (TaskExtension task : this.tasks) {
if (task.complete) {
complete.add(task);
}
}
return complete;
}

public TaskExtension searchTask(TaskExtension task) {
if(tasks.contains(task)) {
return task;
}
System.out.println("Task not found!");
return null;
}

public void removeTask(TaskExtension task) {
this.tasks.remove(task);

}

ArrayList<String> alphabeticallyAscView() {
ArrayList<String> names = new ArrayList<>();
for (TaskExtension task : this.tasks) {
names.add(task.name);

}
names.sort(null);
return names;
}

ArrayList<String> alphabeticallyDescView() {
ArrayList<String> names = new ArrayList<>();
for (TaskExtension task : this.tasks) {
names.add(task.name);

}
names.sort(Comparator.reverseOrder());
return names;
}

public void updateTaskNameByID(UUID uid, String newName) {
for (TaskExtension task : this.tasks) {
if (task.uid == uid) {
task.name = newName;
}
}
}

public void updateTaskStatusByID(UUID uid, boolean newStatus) {
for (TaskExtension task : this.tasks) {
if (task.uid == uid) {
task.changeStatus(newStatus);
}
}
}

TaskExtension getTaskByID(UUID uid) {
for (TaskExtension task : this.tasks) {
if (task.uid == uid) {
return task;
}
} return null;
}

}
18 changes: 18 additions & 0 deletions src/test/java/com/booleanuk/core/TaskTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.booleanuk.core;

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

class TaskTest {
@Test
public void testStatusChanges(){
Task testTask = new Task("TestTask");
testTask.changeStatus(true);
Assertions.assertTrue(testTask.complete);
testTask.changeStatus(false);
Assertions.assertFalse(testTask.complete);
}



}
113 changes: 109 additions & 4 deletions src/test/java/com/booleanuk/core/TodoListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,116 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Array;
import java.util.ArrayList;

class TodoListTest {
@Test
public void exampleTest() {
String hello = "Hello";
Assertions.assertEquals("Hello", hello);
Assertions.assertNotEquals("Goodbye", hello);
public void checkForTaskInList() {
Task task = new Task("Test");
TodoList todo = new TodoList();
Assertions.assertTrue(todo.add(task));
Assertions.assertFalse(todo.add(task));

}

@Test
public void checkViewTask() {
Task task = new Task("Test");
TodoList todo = new TodoList();
ArrayList<Task> empty = new ArrayList<>();
Assertions.assertIterableEquals(empty, todo.viewTasks());
todo.add(task);
empty.add(task);
Assertions.assertIterableEquals(empty, todo.viewTasks());

}

@Test
public void checkIncompleteTaskView() {
TodoList todo = new TodoList();
Task taskIncomplete = new Task("Task incomplete");
Task taskComplete = new Task("Task complete");
taskComplete.changeStatus(true);
todo.add(taskIncomplete);
todo.add(taskComplete);
Assertions.assertNotEquals(todo.viewTasks(), todo.viewIncompleteTasks());
}

@Test
public void checkCompleteTaskView() {
TodoList todo = new TodoList();
Task taskIncomplete = new Task("Task incomplete");
Task taskComplete = new Task("Task complete");
taskComplete.changeStatus(true);
todo.add(taskIncomplete);
todo.add(taskComplete);
Assertions.assertNotEquals(todo.viewTasks(), todo.viewCompleteTasks());
}

@Test
public void testSearchTaskName() {
TodoList todo = new TodoList();
Task example = new Task("Example");

Assertions.assertNotEquals(example, todo.searchTask(example));
todo.add(example);

Assertions.assertEquals(example, todo.searchTask(example));

}

@Test
public void testRemoveTask() {
TodoList todo = new TodoList();
Task example = new Task("Example");
Task example2 = new Task("Example2");

todo.add(example);
ArrayList<Task> tasks = todo.viewTasks();
todo.removeTask(example2);
Assertions.assertEquals(tasks, todo.viewTasks());

todo.add(example2);
int tasks_size = todo.tasks.size();
todo.removeTask(example2);
Assertions.assertNotEquals(todo.tasks.size(), tasks_size);

}

@Test
public void testAscending() {
TodoList todo = new TodoList();
Task a = new Task("A");
Task z = new Task("Zebra");
Task f = new Task("Fair");

todo.add(z);
todo.add(f);
todo.add(a);

Assertions.assertNotEquals(todo.viewTasks().get(0).name, todo.alphabeticallyAscView().get(0));
Assertions.assertEquals(todo.viewTasks().get(1).name, todo.alphabeticallyAscView().get(1));
Assertions.assertNotEquals(todo.viewTasks().get(2).name, todo.alphabeticallyAscView().get(2));

}


@Test
public void testDescending() {
TodoList todo = new TodoList();
Task a = new Task("A");
Task z = new Task("Zebra");
Task f = new Task("Fair");

todo.add(z);
todo.add(f);
todo.add(a);

Assertions.assertEquals(todo.viewTasks().get(0).name, todo.alphabeticallyDescView().get(0));
Assertions.assertEquals(todo.viewTasks().get(1).name, todo.alphabeticallyDescView().get(1));
Assertions.assertEquals(todo.viewTasks().get(2).name, todo.alphabeticallyDescView().get(2));

}

}
Loading
Loading