-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_test.go
80 lines (69 loc) · 1.79 KB
/
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package time
import (
"testing"
"time"
)
func TestDate(t *testing.T) {
year, month, day, hour, min, sec := 2003, 6, 9, 14, 21, 42
actual := Date(year, month, day, hour, min, sec)
expected := time.Date(year, time.Month(month), day, hour, min, sec, 0, time.UTC).String()
if actual != expected {
t.Errorf("Expected %s, got %s", expected, actual)
}
}
func TestNow(t *testing.T) {
actual := Now()
expected := time.Now().String()
actual = actual[0:19]
expected = expected[0:19]
if actual != expected {
t.Errorf("Expected %s, got %s", expected, actual)
}
}
func TestConvertRoman(t *testing.T) {
actual := ConvertRoman("1999")
expected := "MCMXCIX"
if actual != expected {
t.Errorf("Expected %s, got %s", expected, actual)
}
actual = ConvertRoman("658")
expected = "DCLVIII"
if actual != expected {
t.Errorf("Expected %s, got %s", expected, actual)
}
actual = ConvertRoman("444")
expected = "CDXLIV"
if actual != expected {
t.Errorf("Expected %s, got %s", expected, actual)
}
actual = ConvertRoman("10")
expected = "X"
if actual != expected {
t.Errorf("Expected %s, got %s", expected, actual)
}
}
func TestSleep(t *testing.T) {
Sleep(2)
Sleep(0.5)
}
func TestStrftime(t *testing.T) {
date := Date(2003, 6, 9, 14, 21, 42)
format := "Current time : %d/%m/%Y %H:%M:%S"
actual := Strftime(format, date)
expected := "Current time : 09/06/2003 14:21:42"
if actual != expected {
t.Errorf("Expected %s, got %s", expected, actual)
}
format = "Current time : "
actual = Strftime(format, date)
expected = "Current time : "
if actual != expected {
t.Errorf("Expected %s, got %s", expected, actual)
}
format = "Current time : %y %%"
actual = Strftime(format, date)
expected = "Current time : 03 %"
if actual != expected {
t.Errorf("Expected %s, got %s", expected, actual)
}
}