1 package english
2
3 import (
4 "testing"
5 )
6
7 func TestPluralWord(t *testing.T) {
8 tests := []struct {
9 n int
10 singular, plural string
11 want string
12 }{
13 {0, "object", "", "objects"},
14 {1, "object", "", "object"},
15 {-1, "object", "", "objects"},
16 {42, "object", "", "objects"},
17 {2, "vax", "vaxen", "vaxen"},
18
19
20 {2, "index", "", "indices"},
21
22
23 {2, "bus", "", "buses"},
24 {2, "bush", "", "bushes"},
25 {2, "watch", "", "watches"},
26 {2, "box", "", "boxes"},
27
28
29 {2, "hero", "", "heroes"},
30
31
32 {2, "lady", "", "ladies"},
33 {2, "day", "", "days"},
34 }
35 for _, tt := range tests {
36 if got := PluralWord(tt.n, tt.singular, tt.plural); got != tt.want {
37 t.Errorf("PluralWord(%d, %q, %q)=%q; want: %q", tt.n, tt.singular, tt.plural, got, tt.want)
38 }
39 }
40 }
41
42 func TestPlural(t *testing.T) {
43 tests := []struct {
44 n int
45 singular, plural string
46 want string
47 }{
48 {1, "object", "", "1 object"},
49 {42, "object", "", "42 objects"},
50 {1234567, "object", "", "1,234,567 objects"},
51 }
52 for _, tt := range tests {
53 if got := Plural(tt.n, tt.singular, tt.plural); got != tt.want {
54 t.Errorf("Plural(%d, %q, %q)=%q; want: %q", tt.n, tt.singular, tt.plural, got, tt.want)
55 }
56 }
57 }
58
59 func TestWordSeries(t *testing.T) {
60 tests := []struct {
61 words []string
62 conjunction string
63 want string
64 }{
65 {[]string{}, "and", ""},
66 {[]string{"foo"}, "and", "foo"},
67 {[]string{"foo", "bar"}, "and", "foo and bar"},
68 {[]string{"foo", "bar", "baz"}, "and", "foo, bar and baz"},
69 {[]string{"foo", "bar", "baz"}, "or", "foo, bar or baz"},
70 }
71 for _, tt := range tests {
72 if got := WordSeries(tt.words, tt.conjunction); got != tt.want {
73 t.Errorf("WordSeries(%q, %q)=%q; want: %q", tt.words, tt.conjunction, got, tt.want)
74 }
75 }
76 }
77
78 func TestOxfordWordSeries(t *testing.T) {
79 tests := []struct {
80 words []string
81 conjunction string
82 want string
83 }{
84 {[]string{}, "and", ""},
85 {[]string{"foo"}, "and", "foo"},
86 {[]string{"foo", "bar"}, "and", "foo and bar"},
87 {[]string{"foo", "bar", "baz"}, "and", "foo, bar, and baz"},
88 {[]string{"foo", "bar", "baz"}, "or", "foo, bar, or baz"},
89 }
90 for _, tt := range tests {
91 if got := OxfordWordSeries(tt.words, tt.conjunction); got != tt.want {
92 t.Errorf("OxfordWordSeries(%q, %q)=%q; want: %q", tt.words, tt.conjunction, got, tt.want)
93 }
94 }
95 }
96
View as plain text