-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo_test.go
108 lines (100 loc) · 2.34 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"os"
"testing"
)
func TestStruct(t *testing.T) {
t.Log("TestStruct")
item := item{0, "Title", "Date", false}
if item.Id != 0 {
t.Error(item.Id != 0)
}
if item.Title != "Title" {
t.Error(item.Title != "Title")
}
if item.Date != "Date" {
t.Error(item.Date != "Date")
}
if item.Status != false {
t.Error(item.Status != false)
}
}
func TestAddDeleteItem(t *testing.T) {
t.Log("TestAddItem")
tdmap := TodoList{}
Title := "Complete assignment"
i1 := tdmap.addItem(Title)
if len(tdmap) != 1 {
t.Error("len(tdmap) != 1")
}
if tdmap[i1].Title != Title {
t.Error(tdmap[i1].Title, " != ", Title)
}
Title = "Complete assignment 2"
i2 := tdmap.addItem(Title)
if tdmap[i2].Title != Title {
t.Error(tdmap[i2].Title, " != ", Title)
}
tdmap.deleteItem(i1)
if len(tdmap) != 1 {
t.Error("len(tdmap) != 1")
}
if tdmap[i1] != nil {
t.Error("tdmap[0] != nil\n", tdmap[0].toString())
}
}
func TestMarkItem(t *testing.T) {
t.Log("TestMarkItem")
tdmap := TodoList{}
Title := "Complete assignment"
index := tdmap.addItem(Title)
if tdmap[index].Status != false {
t.Error("tdmap[0].Status != false")
}
tdmap.markItem(index)
if tdmap[index].Status != true {
t.Error("tdmap[0].Status != true")
}
tdmap.unMarkItem(index)
if tdmap[index].Status != false {
t.Error("tdmap[0].Status != false")
}
}
func TestJSONtoParse(t *testing.T) {
t.Log("TestJSON")
tdmap := TodoList{}
Title := "Complete assignment"
index := tdmap.addItem(Title)
json := tdmap[index].toJSON()
i := parseJSON(json)
if i.Id != tdmap[index].Id {
t.Error("i.Id != tdmap[index].Id")
}
if i.Title != tdmap[index].Title {
t.Error("i.Title != tdmap[index].Title")
}
if i.Date != tdmap[index].Date {
t.Error("i.Date != tdmap[index].Date")
}
if i.Status != tdmap[index].Status {
t.Error("i.Status != tdmap[index].Status")
}
}
func TestFileWriteRead(t *testing.T) {
t.Log("TestFileWriteRead")
filename := "test.txt"
tdmap := TodoList{}
index := tdmap.addItem("Complete assignment")
tdmap.addItem("Complete assignment 2")
tdmap.addItem("Complete assignment 3")
tdmap.writeToFile(filename)
tdmap2 := TodoList{}
readFromFile(tdmap2, filename)
if len(tdmap) != len(tdmap2) {
t.Error("len(tdmap) != len(tdmap2)")
}
if tdmap[index].Title != tdmap2[index].Title {
t.Error(tdmap[index].Title, " != ", tdmap2[index].Title)
}
os.Remove(filename)
}