diff options
| author | Grant Ammons <gammons@gmail.com> | 2017-03-07 08:50:00 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-03-07 08:50:00 -0500 |
| commit | b735a0cc90c6df666f59b7ee302dae27a6a7afeb (patch) | |
| tree | 8dc6d5376e1bf422a1aa693c27f505721741a1f0 /todolist/todo_list_test.go | |
| parent | 34931b46ed9ebb06e9555d6e62c98c70dc460d59 (diff) | |
| parent | 5763376a7ef50a116f9585ffd280bbf8e37621d3 (diff) | |
Merge pull request #37 from gammons/garbage-collect
Add garbage collection feature
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"} |
