From fe62a4b8a2b1137faec4ae38a247ecbb2d499ebb Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 18 Mar 2018 20:57:09 +0100 Subject: ... --- internal/plural/plural.go | 36 ++++++++++++++++++++++++++++++++++++ internal/plural/plural_test.go | 34 ++++++++++++++++++++++++++++++++++ plural.go | 36 ------------------------------------ plural_test.go | 34 ---------------------------------- queue.go | 2 -- type_string.go | 16 ---------------- 6 files changed, 70 insertions(+), 88 deletions(-) create mode 100644 internal/plural/plural.go create mode 100644 internal/plural/plural_test.go delete mode 100644 plural.go delete mode 100644 plural_test.go delete mode 100644 type_string.go diff --git a/internal/plural/plural.go b/internal/plural/plural.go new file mode 100644 index 0000000..a0b6d2e --- /dev/null +++ b/internal/plural/plural.go @@ -0,0 +1,36 @@ +package plural + +import "strings" + +func Plural(s string) string { + l := len(s) + switch { + case strings.HasSuffix(s, "y"): + return s[:l-1] + "ies" + case strings.HasSuffix(s, "us"): + return s[:l-2] + "i" + case strings.HasSuffix(s, "ch"), + strings.HasSuffix(s, "x"), + strings.HasSuffix(s, "s"): + return s + "es" + case strings.HasSuffix(s, "f"): + return s[:l-1] + "ves" + case strings.HasSuffix(s, "man"), + strings.HasSuffix(s, "Man"): + return s[:l-2] + "en" + default: + return s + "s" + } +} + +func Indefinite(s string, n int) string { + if strings.IndexByte("AEIOUÜaeiouü", s[0]) > 0 { + s = "an " + s + } else { + s = "a " + s + } + if n > 1 { + s = Plural(s) + } + return s +} diff --git a/internal/plural/plural_test.go b/internal/plural/plural_test.go new file mode 100644 index 0000000..15939f7 --- /dev/null +++ b/internal/plural/plural_test.go @@ -0,0 +1,34 @@ +package plural + +import "testing" + +func TestPlural(t *testing.T) { + testCases := map[string]string{ + "funny": "funnies", + "musmus": "musmi", + "much": "muches", + "mux": "muxes", + "fif": "fives", + "heman": "hemen", + "Wo Man": "Wo Men", + "else": "elses", + "usas": "usases", + "nismus": "nismi", + } + for k, v := range testCases { + if r := Plural(k); r != v { + t.Errorf("got %v, want %v", r, v) + } + } +} + +func TestIndefinite(t *testing.T) { + testCases := map[string]string{ + "abachus": "an abachi", + } + for k, v := range testCases { + if r := Indefinite(k, 2); r != v { + t.Errorf("got %v, want %v", r, v) + } + } +} diff --git a/plural.go b/plural.go deleted file mode 100644 index ba8e802..0000000 --- a/plural.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import "strings" - -func Plural(s string) string { - l := len(s) - switch { - case strings.HasSuffix(s, "y"): - return s[:l-1] + "ies" - case strings.HasSuffix(s, "us"): - return s[:l-2] + "i" - case strings.HasSuffix(s, "ch"), - strings.HasSuffix(s, "x"), - strings.HasSuffix(s, "s"): - return s + "es" - case strings.HasSuffix(s, "f"): - return s[:l-1] + "ves" - case strings.HasSuffix(s, "man"), - strings.HasSuffix(s, "Man"): - return s[:l-2] + "en" - default: - return s + "s" - } -} - -func Indefinite(s string, n int) string { - if strings.IndexByte("AEIOUÜaeiouü", s[0]) > 0 { - s = "an " + s - } else { - s = "a " + s - } - if n > 1 { - s = Plural(s) - } - return s -} diff --git a/plural_test.go b/plural_test.go deleted file mode 100644 index 385732b..0000000 --- a/plural_test.go +++ /dev/null @@ -1,34 +0,0 @@ -package main - -import "testing" - -func TestPlural(t *testing.T) { - testCases := map[string]string{ - "funny": "funnies", - "musmus": "musmi", - "much": "muches", - "mux": "muxes", - "fif": "fives", - "heman": "hemen", - "Wo Man": "Wo Men", - "else": "elses", - "usas": "usases", - "nismus": "nismi", - } - for k, v := range testCases { - if r := Plural(k); r != v { - t.Errorf("got %v, want %v", r, v) - } - } -} - -func TestIndefinite(t *testing.T) { - testCases := map[string]string{ - "abachus": "an abachi", - } - for k, v := range testCases { - if r := Indefinite(k, 2); r != v { - t.Errorf("got %v, want %v", r, v) - } - } -} diff --git a/queue.go b/queue.go index f854de5..c30fcb6 100644 --- a/queue.go +++ b/queue.go @@ -1,7 +1,5 @@ package main -//go:generate stringer -type=Type - type Type int const ( diff --git a/type_string.go b/type_string.go deleted file mode 100644 index ed5418f..0000000 --- a/type_string.go +++ /dev/null @@ -1,16 +0,0 @@ -// generated by stringer -type=Type; DO NOT EDIT - -package main - -import "fmt" - -const _Type_name = "TaksPlot" - -var _Type_index = [...]uint8{0, 4, 8} - -func (i Type) String() string { - if i < 0 || i >= Type(len(_Type_index)-1) { - return fmt.Sprintf("Type(%d)", i) - } - return _Type_name[_Type_index[i]:_Type_index[i+1]] -} -- cgit v1.2.3