You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.4 KiB

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