diff options
Diffstat (limited to 'todolist/todo_list_test.go')
| -rw-r--r-- | todolist/todo_list_test.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/todolist/todo_list_test.go b/todolist/todo_list_test.go index bd0f926..eefd99c 100644 --- a/todolist/todo_list_test.go +++ b/todolist/todo_list_test.go @@ -8,8 +8,42 @@ import ( func TestNextId(t *testing.T) { assert := assert.New(t) + todo := &Todo{Subject: "testing", Completed: false, Archived: false} list := &TodoList{} assert.Equal(1, list.NextId()) + list.Add(todo) + assert.Equal(2, list.NextId()) +} + +func TestNextIdWhenTodoDeleted(t *testing.T) { + assert := assert.New(t) + todo := &Todo{Subject: "testing", Completed: false, Archived: false} + todo2 := &Todo{Subject: "testing2", Completed: false, Archived: false} + todo3 := &Todo{Subject: "testing3", Completed: false, Archived: false} + list := &TodoList{} + + list.Add(todo) + list.Add(todo2) + list.Add(todo3) + + list.Delete(2) + assert.Equal(2, list.NextId()) + list.Add(todo2) + assert.Equal(4, list.NextId()) + list.Delete(1) + assert.Equal(1, list.NextId()) +} + +func TestMaxId(t *testing.T) { + assert := assert.New(t) + todo := &Todo{Subject: "testing", Completed: false, Archived: false} + todo2 := &Todo{Subject: "testing 2", Completed: false, Archived: false} + list := &TodoList{} + assert.Equal(0, list.MaxId()) + list.Add(todo) + assert.Equal(1, list.MaxId()) + list.Add(todo2) + assert.Equal(2, list.MaxId()) } func TestIndexOf(t *testing.T) { @@ -78,6 +112,23 @@ func TestUncomplete(t *testing.T) { assert.Equal(false, list.FindById(2).Completed) } +func TestGarbageCollect(t *testing.T) { + assert := assert.New(t) + list := &TodoList{} + todo := &Todo{Subject: "testing", Completed: false, Archived: true} + todo2 := &Todo{Subject: "testing2", Completed: false, Archived: false} + todo3 := &Todo{Subject: "testing3", Completed: false, Archived: true} + list.Add(todo) + list.Add(todo2) + list.Add(todo3) + + list.GarbageCollect() + + assert.Equal(len(list.Data), 1) + assert.Equal(1, list.NextId()) + assert.Equal(2, list.MaxId()) +} + func TestPrioritizeNotInTodosJson(t *testing.T) { assert := assert.New(t) store := &FileStore{FileLocation: "todos.json"} |
