-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_test.go
96 lines (84 loc) · 2.23 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import "testing"
func TestAddTodo(t *testing.T) {
todos := []todo{}
addFlag := "some todo"
val := add(todos, addFlag)
if len(val) != 1 {
t.Errorf("could not add a todo")
}
}
func TestCompleteTodoWithCompleteFlag(t *testing.T) {
todos := []todo{todo{Description: "a", Completed: false}}
completeFlag := 0
val := complete(todos, completeFlag)
if val[0].Completed != true {
t.Error("expected completed to be true, got false")
}
}
func TestUnCompleteTodoWithCompleteFlag(t *testing.T) {
todos := []todo{todo{Description: "a", Completed: true}}
completeFlag := 0
val := complete(todos, completeFlag)
if val[0].Completed != false {
t.Error("expected completed to be false, got true")
}
}
func TestNoCompleteTodoWithNegativeOneCompleteFlag(t *testing.T) {
todos := []todo{todo{Description: "a", Completed: false}}
completeFlag := -1
val := complete(todos, completeFlag)
if val[0].Completed != false {
t.Error("expected completed to be false, got true")
}
}
func TestRemoveTodoWithRemoveFlag(t *testing.T) {
todos := defaultTodos()
removeFlag := 1
val := remove(todos, removeFlag)
if len(val) != 2 {
t.Error("did not remove todo")
}
}
func TestNoRemoveTodoWithNoRemoveFlag(t *testing.T) {
todos := defaultTodos()
removeFlag := -1
val := remove(todos, removeFlag)
if len(val) != 3 {
t.Error("unexpectedly removed todo")
}
}
var listWithCompletion = []struct {
List []todo
Show bool
Only bool
Length int
Message string
}{
{todosWithCompletion(), false, false, 3, "showed completed when should not"},
{todosWithCompletion(), true, false, 4, "wrong number of todos with show completed"},
{todosWithCompletion(), false, true, 2, "wrong number of todos with only completed"},
}
func TestListWithCompletion(t *testing.T) {
for _, lwc := range listWithCompletion {
val := list(lwc.List, lwc.Show, lwc.Only)
// list adds a header row
if len(val) != lwc.Length {
t.Error(lwc.Message)
}
}
}
func todosWithCompletion() []todo {
return []todo{
todo{Description: "a", Completed: false},
todo{Description: "b", Completed: false},
todo{Description: "c", Completed: true},
}
}
func defaultTodos() []todo {
return []todo{
todo{Description: "a"},
todo{Description: "b"},
todo{Description: "c"},
}
}