summaryrefslogtreecommitdiff
path: root/go/say/say_test.go
blob: e4144a5fe9f0b9bc30e0c409e682d2a665a946de (plain)
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
package say

// The steps are interesting, but all that matters is the final exam.

import (
	"math"
	"testing"
)

var tests = []struct {
	uint64
	string
}{
	{1, "one"},
	{14, "fourteen"},
	{20, "twenty"},
	{22, "twenty-two"},
	{100, "one hundred"},
	{120, "one hundred twenty"},
	{123, "one hundred twenty-three"},
	{1000, "one thousand"},
	{1234, "one thousand two hundred thirty-four"},
	{1000000, "one million"},
	{1000002, "one million two"},
	{1002345, "one million two thousand three hundred forty-five"},
	{1e9, "one billion"},
	{987654321123, "nine hundred eighty-seven billion " +
		"six hundred fifty-four million " +
		"three hundred twenty-one thousand " +
		"one hundred twenty-three"},
	{0, "zero"},
	{math.MaxUint64, "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"},
}

func TestSay(t *testing.T) {
	for _, test := range tests {
		if s := Say(test.uint64); s != test.string {
			t.Errorf("Say(%d) = %q.  Want %q.", test.uint64, s, test.string)
		}
	}
}