diff --git a/tdd-todo-list.CSharp.Main/ToDoList.cs b/tdd-todo-list.CSharp.Main/ToDoList.cs index 835cb600..a236a7fc 100644 --- a/tdd-todo-list.CSharp.Main/ToDoList.cs +++ b/tdd-todo-list.CSharp.Main/ToDoList.cs @@ -8,5 +8,110 @@ namespace tdd_todo_list.CSharp.Main { public class TodoList { + public List _list; + public List _status; + + public TodoList() + { + _list = new List(); + _status = new List(); + } + + public bool AddTask(string task) + { + _list.Add(task); + _status.Add(false); + return true; + } + + public bool ShowAllTasks() + { + for (int i = 0; i < _list.Count; i++) + { + Console.WriteLine($"Task: {_list[i]}, Status: {_status[i]}"); + } + return true; + } + + public bool UpdateStatus(string task) + { + int inx = _list.IndexOf(task); + + if (inx == -1) { return false; } + + _status[inx] = true; + return true; + } + + public bool ShowCompleteTasks() + { + for (int i = 0; i < _list.Count; i++) + { + if (_status[i]) + { + Console.WriteLine($"Task: {_list[i]}, Status: {_status[i]}"); + } + } + return true; + } + + public bool ShowInCompleteTasks() + { + for (int i = 0; i < _list.Count; i++) + { + if (!_status[i]) + { + Console.WriteLine($"Task: {_list[i]}, Status: {_status[i]}"); + } + } + return true; + } + + public string SearchTask(string task) + { + string result = "Task Not Found"; + + int inx = _list.IndexOf(task); + + if (inx == -1) { return result; } + + result = $"The task, {task}, has been found at index {inx}"; + return result; + } + + + public bool RemoveTask(string task) + { + int inx = _list.IndexOf(task); + + if (inx == -1) { return false; } + + _list.RemoveAt(inx); + _status.RemoveAt(inx); + return true; + } + + public bool ShowAllTasksAlphabeticallyAcending() + { + List alphabeticalList = new List(_list); + alphabeticalList.Sort(StringComparer.OrdinalIgnoreCase); + for (int i = 0; i < _list.Count; i++) + { + Console.WriteLine($"Task: {alphabeticalList[i]}"); + } + return true; + } + + public bool ShowAllTasksAlphabeticallyDecending() + { + List alphabeticalList = new List(_list); + alphabeticalList.Sort(StringComparer.OrdinalIgnoreCase); + alphabeticalList.Reverse(); + for (int i = 0; i < _list.Count; i++) + { + Console.WriteLine($"Task: {alphabeticalList[i]}"); + } + return true; + } } } diff --git a/tdd-todo-list.CSharp.Test/CoreTests.cs b/tdd-todo-list.CSharp.Test/CoreTests.cs index 084cce19..2ed6f7ab 100644 --- a/tdd-todo-list.CSharp.Test/CoreTests.cs +++ b/tdd-todo-list.CSharp.Test/CoreTests.cs @@ -6,12 +6,100 @@ namespace tdd_todo_list.CSharp.Test [TestFixture] public class CoreTests { + [Test] + public void TestAdd() + { + TodoList core = new TodoList(); + Assert.That(core._list.Count, Is.EqualTo(0)); + core.AddTask("Clean"); + Assert.That(core._list.Count, Is.EqualTo(1)); + core.AddTask("Tidy"); + Assert.That(core._list.Count, Is.EqualTo(2)); + } + + [Test] + public void TestShowAll() + { + TodoList core = new TodoList(); + core.AddTask("Clean"); + core.AddTask("Tidy"); + Assert.That(core.ShowAllTasks, Is.True); + } + + + [Test] + public void TestUpdate() + { + TodoList core = new TodoList(); + core.AddTask("Clean"); + core.AddTask("Tidy"); + Assert.That(core._status[0], Is.False); + Assert.That(core._status[1], Is.False); + core.UpdateStatus("Clean"); + Assert.That(core._status[0], Is.True); + Assert.That(core._status[1], Is.False); + } + + [Test] + public void TestUpdateOfTaskNotOnList() + { + TodoList core = new TodoList(); + core.AddTask("Clean"); + Assert.That(core._status[0], Is.False); + core.UpdateStatus("clean"); + Assert.That(core._status[0], Is.False); + Assert.That(core.UpdateStatus("shop"), Is.False); + } [Test] - public void FirstTest() + public void TestShowOnly() { TodoList core = new TodoList(); - Assert.Pass(); + core.AddTask("Clean"); + core.AddTask("Tidy"); + core.UpdateStatus("Clean"); + Assert.That(core.ShowCompleteTasks(), Is.True); + Assert.That(core.ShowInCompleteTasks(), Is.True); } + + [Test] + public void TestSearch() + { + TodoList core = new TodoList(); + core.AddTask("Clean"); + core.AddTask("Tidy"); + Assert.That(core.SearchTask("Clean"), Is.EqualTo("The task, Clean, has been found at index 0")); + Assert.That(core.SearchTask("clean"), Is.EqualTo("Task Not Found")); + } + + + [Test] + public void TestRemove() + { + TodoList core = new TodoList(); + Assert.That(core._list.Count, Is.EqualTo(0)); + core.AddTask("Clean"); + Assert.That(core._list.Count, Is.EqualTo(1)); + core.AddTask("Tidy"); + Assert.That(core._list.Count, Is.EqualTo(2)); + + Assert.That(core.RemoveTask("tidyclean"), Is.False); + + core.RemoveTask("Clean"); + Assert.That(core._list.Count, Is.EqualTo(1)); + core.RemoveTask("Tidy"); + Assert.That(core._list.Count, Is.EqualTo(0)); + } + + [Test] + public void TestSorting() + { + TodoList core = new TodoList(); + core.AddTask("Clean"); + core.AddTask("Tidy"); + Assert.That(core.ShowAllTasksAlphabeticallyAcending(), Is.True); + Assert.That(core.ShowAllTasksAlphabeticallyDecending(), Is.True); + } + } } \ No newline at end of file