-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo_test.go
79 lines (61 loc) · 1.14 KB
/
todo_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
package main
import (
"math/rand"
"testing"
"time"
)
func TestAppendTodo(t *testing.T) {
repo := TodoRepo{}
rand.Seed(time.Now().UnixNano())
id := rand.Intn(50)
todo := Todo{
text: "test todo",
id: id,
}
repo, i := AppendTodo(repo, todo)
if len(repo) != 1 {
t.Error("should add 1 todo in the repo")
}
if i != id+1 {
t.Error("should return the next id")
}
}
func TestEditTodo(t *testing.T) {
rand.Seed(time.Now().UnixNano())
id := rand.Intn(50)
todo := Todo{
text: "test todo",
id: id,
}
repo := TodoRepo{todo}
newText := "new todo"
_, repo, updatedTodo := EditTodoText(repo, todo.id, newText)
if updatedTodo.text != newText {
t.Error("Should update a todo by its id")
}
}
func TestRemoveTodo(t *testing.T) {
repo := TodoRepo{
Todo{
text: "removable todo",
id: 4,
},
}
_, repo = RemoveTodo(repo, 4)
if len(repo) != 0 {
t.Error("Should remove a todo by it's id")
}
}
func TestToggleDone(t *testing.T) {
repo := TodoRepo{
Todo{
text: "removable todo",
id: 4,
done: false,
},
}
repo, todo, _ := ToggleDone(repo, 4)
if !todo.done {
t.Error("Should be true (done)")
}
}