-
Notifications
You must be signed in to change notification settings - Fork 4
/
ponjika_test.go
executable file
·213 lines (204 loc) · 5.18 KB
/
ponjika_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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
package ponjika
import (
"testing"
"time"
)
func Test_isLeapYear(t *testing.T) {
testCases := []struct {
Tag string
Year int
IsLeapYear bool
}{
{
"Year 1900 is NOT leap year",
1900,
false,
},
{
"Year 2000 is leap year",
2000,
true,
},
{
"Year 2004 is leap year",
2004,
true,
},
}
for _, tc := range testCases {
if isLeapYear(tc.Year) != tc.IsLeapYear {
t.Error(tc.Tag)
}
}
}
func Test_EnToBnYear(t *testing.T) {
testCases := []struct {
Month, Date, Year, BYear int
}{
{
Month: 3, Date: 13, Year: 2015, BYear: 1421,
},
{
Month: 5, Date: 10, Year: 2016, BYear: 1423,
},
}
// TODO: Need more test cases and accurate data
for _, tc := range testCases {
if r := EnToBnYear(tc.Year, tc.Month, tc.Date); r != tc.BYear {
t.Error("expected: ", tc.BYear, "go: ", r)
}
}
}
func Test_New(t *testing.T) {
layout := "2006-01-02 15:04:05"
testCases := []struct {
Tag string
EnDate string
ExptdBnYear, ExptdBnDate int
ExptdBnMonth, ExptdBnDay string
}{
{
Tag: "Expeted result for 2018-03-28 15:30:00 is 1424 bengali year and 14 bengali date",
EnDate: "2018-03-28 15:30:00",
ExptdBnYear: 1424,
ExptdBnDate: 14,
ExptdBnMonth: "চৈত্র",
ExptdBnDay: "বুধবার",
},
{
Tag: "Expeted result for 2018-03-29 15:30:00 is 1424 bengali year and 15 bengali date",
EnDate: "2018-03-29 15:30:00",
ExptdBnYear: 1424,
ExptdBnDate: 15,
ExptdBnMonth: "চৈত্র",
ExptdBnDay: "বৃহস্পতিবার",
},
{
Tag: "Expeted result for 2018-04-14 14:18:00 is 1425 bengali year and 1 bengali date. Pohela boisakh",
EnDate: "2018-04-14 14:18:00",
ExptdBnYear: 1425,
ExptdBnDate: 1,
ExptdBnMonth: "বৈশাখ",
ExptdBnDay: "শনিবার",
},
{
Tag: "Expeted result for 2001-03-14 14:18:00 is expected as non leap year and falun should be 30 days long",
EnDate: "2001-03-14 14:18:00",
ExptdBnYear: 1407,
ExptdBnDate: 30,
ExptdBnMonth: "ফাল্গুন",
ExptdBnDay: "বুধবার",
},
{
Tag: "Expeted result for 2004-03-14 14:18:00 is expected as leap year and falun should be 31 days long",
EnDate: "2004-03-14 14:18:00",
ExptdBnYear: 1410,
ExptdBnDate: 31,
ExptdBnMonth: "ফাল্গুন",
ExptdBnDay: "রবিবার",
},
}
for _, tc := range testCases {
d, err := time.Parse(layout, tc.EnDate)
if err != nil {
t.Error("failed to parse english date time: ", err)
} else {
p := New(d)
if p.Year != tc.ExptdBnYear ||
p.Date != tc.ExptdBnDate ||
p.BengaliMonth.Bengali != tc.ExptdBnMonth ||
p.BengaliDay.Bengali != tc.ExptdBnDay {
t.Errorf("%s\nExpected: year %d date %d month %s day %s \nGot: year %d date %d month %s day %s\n",
tc.Tag, tc.ExptdBnYear, tc.ExptdBnDate, tc.ExptdBnMonth, tc.ExptdBnDay,
p.Year, p.Date, p.BengaliMonth.Bengali, p.BengaliDay.Bengali)
}
}
}
}
func TestPonjika_String(t *testing.T) {
layout := "2006-01-02 15:04:05"
testCases := []struct {
EnDate, ExpectedBnDate string
}{
{
EnDate: "2001-03-14 14:18:00",
ExpectedBnDate: "৩০ ফাল্গুন ১৪০৭ রোজ বুধবার",
},
{
EnDate: "2001-03-14 14:18:00",
ExpectedBnDate: "৩০ ফাল্গুন ১৪০৭ রোজ বুধবার",
},
{
EnDate: "2018-04-14 14:18:00",
ExpectedBnDate: "১ বৈশাখ ১৪২৫ রোজ শনিবার",
},
}
for _, tc := range testCases {
d, err := time.Parse(layout, tc.EnDate)
if err != nil {
t.Error("failed to parse english date time: ", err)
} else {
p := New(d)
if p.String() != tc.ExpectedBnDate {
t.Errorf("Expected %s \nGot: %s", p.String(), tc.ExpectedBnDate)
}
}
}
}
func TestPonjika_Phonetic(t *testing.T) {
layout := "2006-01-02 15:04:05"
testCases := []struct {
EnDate, ExpectedBnDate string
}{
{
EnDate: "2001-03-14 14:18:00",
ExpectedBnDate: "30 Falgun 1407 Roj Budhbar",
},
{
EnDate: "2001-03-14 14:18:00",
ExpectedBnDate: "30 Falgun 1407 Roj Budhbar",
},
{
EnDate: "2018-04-14 14:18:00",
ExpectedBnDate: "1 Boisakh 1425 Roj Shonibar",
},
}
for _, tc := range testCases {
d, err := time.Parse(layout, tc.EnDate)
if err != nil {
t.Error("failed to parse english date time: ", err)
} else {
p := New(d)
if p.Phonetic() != tc.ExpectedBnDate {
t.Errorf("Expected %s \nGot: %s", p.Phonetic(), tc.ExpectedBnDate)
}
}
}
}
func Test_BanglaMonthTotalDays(t *testing.T) {
layout := "2006-01-02 15:04:05"
testCases := []struct {
EnDate string
ExpectedIndex int
}{
{
EnDate: "2018-04-01 14:18:00",
ExpectedIndex: 30,
},
{
EnDate: "2018-04-15 14:18:00",
ExpectedIndex: 31,
},
}
for _, tc := range testCases {
d, err := time.Parse(layout, tc.EnDate)
if err != nil {
t.Error("failed to parse english date time: ", err)
} else {
p := New(d)
if p.TotalDays != tc.ExpectedIndex {
t.Errorf("Expected %d \nGot: %d", tc.ExpectedIndex, p.TotalDays)
}
}
}
}