-
Notifications
You must be signed in to change notification settings - Fork 0
/
spell_test.go
158 lines (148 loc) · 3.3 KB
/
spell_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
package spell_test
import (
"github.com/daniellowtw/go-spell-number"
"math"
"testing"
)
func TestNegativeNumberReturnsEmptyString(t *testing.T) {
actual := spell.Number(-1)
if actual != "" {
t.Errorf("Expected the empty string for negative numbers but got %s", actual)
t.Fail()
}
}
func TestLargestUInt64Number(t *testing.T) {
expected := "eighteen quintillion four hundred forty six quadrillion seven hundred forty four trillion seventy three billion seven hundred nine million five hundred fifty one thousand six hundred fifteen"
var x uint64 = math.MaxUint64
actual := spell.LargeNumber(x)
if actual != expected {
t.Errorf("Expected %s but got %s", expected, actual)
t.Fail()
}
}
func TestLargestInt64Number(t *testing.T) {
expected := "nine quintillion two hundred twenty three quadrillion three hundred seventy two trillion thirty six billion eight hundred fifty four million seven hundred seventy five thousand eight hundred seven"
actual := spell.Number(math.MaxInt64)
if actual != expected {
t.Errorf("Expected %s but got %s", expected, actual)
t.Fail()
}
}
func TestLargeNumberSmokeTest(t *testing.T) {
expected := "nine trillion one hundred twenty three billion four hundred fifty six million seven hundred eighty nine thousand one hundred twenty three"
actual := spell.LargeNumber(9123456789123)
if actual != expected {
t.Errorf("Expected %s but got %s", expected, actual)
t.Fail()
}
}
func TestNumberProxySmokeTest(t *testing.T) {
expected := "twelve"
actual := spell.Number(12)
if actual != expected {
t.Errorf("Expected %s but got %s", expected, actual)
t.Fail()
}
}
func TestTrickyNumbers(t *testing.T) {
tests := []struct {
expected string
number uint64
}{
{
expected: "zero",
number: 0,
},
{
expected: "ten",
number: 10,
},
{
expected: "twelve",
number: 12,
},
{
expected: "twenty",
number: 20,
},
{
expected: "twenty two",
number: 22,
},
{
expected: "one hundred",
number: 100,
},
{
expected: "one hundred one",
number: 101,
},
{
expected: "one hundred eleven",
number: 111,
},
{
expected: "one thousand one",
number: 1001,
},
{
expected: "one thousand one hundred",
number: 1100,
},
{
expected: "one hundred eleven thousand one hundred eleven",
number: 111111,
},
}
for _, test := range tests {
t.Run(test.expected, func(t *testing.T) {
expected := test.expected
actual := spell.LargeNumber(test.number)
if actual != expected {
t.Errorf("Expected %s but got %s", expected, actual)
t.Fail()
}
})
}
}
func TestShortFormNumberEnding(t *testing.T) {
tests := []struct {
expected string
number uint64
}{
{
expected: "two thousand",
number: 2 * 1e3,
},
{
expected: "two million",
number: 2 * 1e6,
},
{
expected: "two billion",
number: 2 * 1e9,
},
{
expected: "two trillion",
number: 2 * 1e12,
},
{
expected: "two quadrillion",
number: 2 * 1e15,
},
{
expected: "two quintillion",
number: 2 * 1e18,
},
}
for _, test := range tests {
t.Run(test.expected, func(t *testing.T) {
expected := test.expected
actual := spell.LargeNumber(test.number)
if actual != expected {
t.Errorf("Expected %s but got %s", expected, actual)
t.Fail()
}
})
}
}