-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinto_words_test.go
99 lines (87 loc) · 2.11 KB
/
into_words_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
package inflect
import "testing"
func TestZero(t *testing.T) {
got := IntoWords(0)
if got != zero {
t.Errorf("Expected '%s' got '%s'", zero, got)
}
}
func TestUnits(t *testing.T) {
for i, expected := range units {
if i == 0 {
continue
}
got := IntoWords(float64(i))
if got != expected {
t.Errorf("Expected '%s' got '%s'", expected, got)
}
}
}
func TestTeens(t *testing.T) {
for value, expected := range teens {
got := IntoWords(float64(value))
if got != expected {
t.Errorf("Expected '%s' got '%s'", expected, got)
}
}
}
func TestTens(t *testing.T) {
for value, expected := range tens {
got := IntoWords(float64(value))
if got != expected {
t.Errorf("Expected '%s' got '%s'", expected, got)
}
}
}
func TestHundreds(t *testing.T) {
hundreds := []string{zero,
"one hundred",
"two hundred",
"three hundred",
"four hundred",
"five hundred",
"six hundred",
"seven hundred",
"eight hundred",
"nine hundred"}
for value, expected := range hundreds {
got := IntoWords(float64(value * 100))
if got != expected {
t.Errorf("Expected '%s' got '%s'", expected, got)
}
}
}
func TestUpThousand(t *testing.T) {
upThousands := map[float64]string{
1000: "one thousand",
1984: "one thousand, nine hundred and eighty-four",
510072000: "five hundred and ten million, seventy-two thousand",
775398007: "seven hundred and seventy-five million, three hundred and ninety-eight thousand, seven",
}
for key, value := range upThousands {
got := IntoWords(key)
if got != value {
t.Errorf("Expected '%s' got '%s'", value, got)
}
}
}
func TestFraction(t *testing.T) {
upThousands := map[float64]string{
1.99: "one point ninety-nine",
12756.2: "twelve thousand, seven hundred and fifty-six point twenty",
0.42: "point forty-two",
}
for key, value := range upThousands {
got := IntoWords(key)
if got != value {
t.Errorf("Expected '%s' got '%s'", value, got)
}
}
}
func TestNegativeValue(t *testing.T) {
expected := "Minus one hundred and forty-seven"
got := IntoWords(-147)
if got != expected {
t.Errorf("Expected '%s' got '%s'", expected, got)
}
}