forked from ladydascalie/termodoro
/
main_test.go
126 lines (107 loc) · 2.68 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package pomodoro
import (
"strings"
"testing"
"time"
)
const (
layout string = "Jan 01 2006 at 15:04:01"
)
func TestNewPomodoro(t *testing.T) {
n := NewPomodoro()
if n.Active != true {
t.Fail()
}
t.Log("\n", n.Active)
}
func TestGetCurrentTime(t *testing.T) {
ti := GetCurrentTime().Format(layout)
t.Log("\n", ti)
}
func TestSetStartTime(t *testing.T) {
po := NewPomodoro()
SetStartTime(po)
}
func TestGetStartTime(t *testing.T) {
po := NewPomodoro()
SetStartTime(po)
st := GetStartTime(po)
t.Log("\n", st)
}
func TestGetPomodoroDuration(t *testing.T) {
po := NewPomodoro()
SetStartTime(po)
time.Sleep(1 * time.Microsecond)
pd := GetPomodoroDuration(po)
t.Log("\n", pd)
}
func TestAddPomodoroDuration(t *testing.T) {
n := NewPomodoro()
n.Start = GetCurrentTime()
AddPomodoroDuration(n)
t.Log("\n", n.Start, n.End)
}
func TestPomodoroTimer(t *testing.T) {
var duration time.Duration = 1
ti := Timer(duration, time.Microsecond)
if ti != false {
t.Fail()
}
}
func TestFormatDate(t *testing.T) {
date, time := FormatDate(2015, time.January, 1, 0, 0)
t.Log("\nDate string:", date, "\ntime.Time format:", time)
if date != "Jan 01 2015 at 00:00:01" {
t.Fail()
}
}
func TestNewDefaultPomodoro(t *testing.T) {
// Prepare a custom pomodoro
n := NewDefaultPomodoro()
st := n.Start.Format(layout)
ed := n.End.Format(layout)
ac := n.Active
// Dates can't be empty
// // Pomodoro must be active
if st == "" || ed == "" {
t.Fail()
} else if ac != true {
t.Fail()
}
t.Log("\n", n.Active, "\n", n.Start, "\n", n.End)
}
func TestFormatOutput(t *testing.T) {
n := NewPomodoro()
n.Active = true
// Pass the string to the bit bucket operator (underscore) since we are not going to use it in the test
_, n.Start = FormatDate(2015, time.January, 1, 0, 0)
AddPomodoroDuration(n)
expected := []string{"active", "Jan 01 2015 at 00:00:01", "Jan 01 2015 at 00:25:01"}
got := FormatOutput(n)
for i := 0; i < len(got); i++ {
// INFO: godoc -http=":6060"
// http://localhost:6060/ref/spec#Index_expressions
if strings.Compare(expected[i], got[i]) != 0 {
t.Fail()
t.Log(strings.Compare(expected[i], got[i]))
}
t.Log("\nExpected:", expected[i], "\nReceived:", got[i])
}
if len(expected) != len(got) {
t.Fail()
t.Log("\n Expected:", len(expected), "but got:", len(got))
}
}
// func TestTickerSince(t *testing.T) {
// n := NewPomodoro()
// n.Active = true
// _, n.Start = FormatDate(2015, time.January, 1, 0, 0)
// _, n.End = FormatDate(2015, time.January, 1, 0, 1)
// // po := n.End.Sub(n.Start)
// // c := time.Tick(1 * time.Second)
// tick := time.NewTicker(1 * time.Second)
// for now := range tick.C {
// t.Log(GetCurrentTime().Format(layout), now)
// }
//
// }