-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_test.go
56 lines (44 loc) · 1009 Bytes
/
time_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
package durations
import (
"strconv"
"testing"
"time"
)
func Test_GetDate(t *testing.T) {
strArr := []string{"c", "y", "h"}
mulArr := []int{1, 1, 1}
sumStr := ""
var expected time.Duration = 0
for index, str := range strArr {
digit := strconv.Itoa(mulArr[index])
expected += time.Duration(unitMap[str] * uint64(mulArr[index]))
sumStr += str + digit + " "
if str == "c" {
expected += GetTotalLeapYear(mulArr[index] * 100)
}
if str == "y" {
expected += GetTotalLeapYear(mulArr[index])
}
}
time, err := GetDuration(sumStr)
if err != nil {
t.Error(err.Error())
}
if expected != time {
t.Error("not same with expected value.")
}
}
func Test_parsetime(t *testing.T) {
str := "w"
mul := 3
var expected time.Duration = 0
expected = expected + time.Duration(unitMap[str]*uint64(mul))
mulstr := strconv.Itoa(mul)
time, err := parseTime(mulstr, str)
if err != nil {
t.Error(err.Error())
}
if expected != time {
t.Error("not same with expected value.")
}
}