-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjapanese_test.go
70 lines (62 loc) · 2.06 KB
/
japanese_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
package kansuji_test
import (
"testing"
"github.com/GreenYun/kansuji"
)
func TestJapaneseFloat(t *testing.T) {
intTestCases := []struct {
number float64
ones int
prec int
want string
}{
{0, 0, -1, "零"},
{-1.01, 0, -1, "負一点零一"},
{1234567, 1, 5, "百二十三万四千五百六十七点零零零零零"},
{-1001101.987654321, 2, 8, "負一百万一千一百一点九八七六五四三二"},
}
for _, tc := range intTestCases {
got := kansuji.JapaneseFloat(tc.number, tc.ones, tc.prec)
if got != tc.want {
t.Errorf("JapaneseFloat(%f, %d, %d) got \"%s\" but wanted \"%s\"", tc.number, tc.ones, tc.prec, got, tc.want)
}
}
}
func TestJapaneseInt(t *testing.T) {
intTestCases := []struct {
number int64
ones int
want string
}{
{0, 0, "零"},
{-1, 0, "負一"},
{0x7fffffffffffffff, 0, "九百二十二京三千三百七十二兆三百六十八億五千四百七十七万五千八百七"},
{101010001010101101, 0, "十京千十兆十億千十万千百一"},
{101010001010101101, 1, "十京一千十兆十億一千十万千百一"},
{-1001101, 2, "負一百万一千一百一"},
}
for _, tc := range intTestCases {
got := kansuji.JapaneseInt(tc.number, tc.ones)
if got != tc.want {
t.Errorf("JapaneseInt(%d, %d) got \"%s\" but wanted \"%s\"", tc.number, tc.ones, got, tc.want)
}
}
}
func TestJapaneseUint(t *testing.T) {
intTestCases := []struct {
number uint64
ones int
want string
}{
{0, 0, "零"},
{0xffffffffffffffff, 0, "千八百四十四京六千七百四十四兆七百三十七億九百五十五万千六百十五"},
{0xffffffffffffffff, 1, "一千八百四十四京六千七百四十四兆七百三十七億九百五十五万千六百十五"},
{0xffffffffffffffff, 2, "一千八百四十四京六千七百四十四兆七百三十七億九百五十五万一千六百一十五"},
}
for _, tc := range intTestCases {
got := kansuji.JapaneseUint(tc.number, tc.ones)
if got != tc.want {
t.Errorf("JapaneseUint(%d, %d) got \"%s\" but wanted \"%s\"", tc.number, tc.ones, got, tc.want)
}
}
}