diff options
| author | Grant Ammons <gammons@gmail.com> | 2017-03-03 17:42:27 -0500 |
|---|---|---|
| committer | Grant Ammons <gammons@gmail.com> | 2017-03-03 17:42:27 -0500 |
| commit | f6c9296952b062803a4991d3f97f76d61b0cc488 (patch) | |
| tree | cc2e8250401f1fe37578a5b537e8f42fd454d6a3 /todolist/todo_list_test.go | |
| parent | be32789ec53ebe0a2141cf4d13696280ef79ee7f (diff) | |
Add garbage collection feature
* Add `todo gc`, which will delete all archived todos.
* `NextId` will now take the first available id, rather than just the MaxId + 1.
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 8a40b14..eb0bc84 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) { @@ -77,3 +111,20 @@ func TestUncomplete(t *testing.T) { list.Uncomplete(2) 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()) +} |
