summaryrefslogtreecommitdiff
path: root/internal/levenshtein/levenshtein_test.go
diff options
context:
space:
mode:
authorJeroen Wijenbergh <jeroenwijenbergh@protonmail.com>2024-05-27 13:40:38 +0200
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2024-05-29 14:36:10 +0200
commit820e70aed9c77f05a9275a789966f13453f330fd (patch)
treeaacccd33ce8d184be7b34c86acb87b11fc0e0449 /internal/levenshtein/levenshtein_test.go
parentd8123e814d37669daca4cf69107109f9009d39fa (diff)
Format: Run gofumpt
Diffstat (limited to 'internal/levenshtein/levenshtein_test.go')
-rw-r--r--internal/levenshtein/levenshtein_test.go300
1 files changed, 150 insertions, 150 deletions
diff --git a/internal/levenshtein/levenshtein_test.go b/internal/levenshtein/levenshtein_test.go
index 41f7f4a..5a1a427 100644
--- a/internal/levenshtein/levenshtein_test.go
+++ b/internal/levenshtein/levenshtein_test.go
@@ -3,163 +3,163 @@ package levenshtein
import "testing"
func TestLevenshtein(t *testing.T) {
- cases := []struct{
- a string
- b string
- score int
- }{
- {
- a: "foo",
- b: "foo",
- score: 0,
- },
- {
- a: "foo",
- b: "foo",
- score: 0,
- },
- {
- a: "foo",
- b: "foosd",
- score: 2,
- },
- {
- a: "foo",
- b: "bla",
- score: 3,
- },
- {
- a: "foo",
- b: "",
- score: 3,
- },
- {
- a: "",
- b: "foo",
- score: 3,
- },
- }
- for i, c := range cases {
- g := levenshtein(c.a, c.b)
- if g != c.score {
- t.Fatalf("case %d not equal, got: %d, want: %d", i, g, c.score)
- }
+ cases := []struct {
+ a string
+ b string
+ score int
+ }{
+ {
+ a: "foo",
+ b: "foo",
+ score: 0,
+ },
+ {
+ a: "foo",
+ b: "foo",
+ score: 0,
+ },
+ {
+ a: "foo",
+ b: "foosd",
+ score: 2,
+ },
+ {
+ a: "foo",
+ b: "bla",
+ score: 3,
+ },
+ {
+ a: "foo",
+ b: "",
+ score: 3,
+ },
+ {
+ a: "",
+ b: "foo",
+ score: 3,
+ },
+ }
+ for i, c := range cases {
+ g := levenshtein(c.a, c.b)
+ if g != c.score {
+ t.Fatalf("case %d not equal, got: %d, want: %d", i, g, c.score)
}
+ }
}
func TestAdjusted(t *testing.T) {
- cases := []struct{
- a string
- b string
- score int
- }{
- {
- a: "foo",
- b: "foo",
- score: 0,
- },
- {
- a: "foo",
- b: "foo",
- score: 0,
- },
- {
- a: "foo",
- b: "foosd",
- score: 2,
- },
- {
- a: "foo",
- b: "bla",
- score: -1,
- },
- {
- a: "bla foo",
- b: "bla",
- score: -1,
- },
- {
- a: "foo",
- b: "",
- score: -1,
- },
- {
- a: "",
- b: "foo",
- score: 3,
- },
- }
- for i, c := range cases {
- g := adjusted(c.a, c.b)
- if g != c.score {
- t.Fatalf("case %d not equal, got: %d, want: %d", i, g, c.score)
- }
+ cases := []struct {
+ a string
+ b string
+ score int
+ }{
+ {
+ a: "foo",
+ b: "foo",
+ score: 0,
+ },
+ {
+ a: "foo",
+ b: "foo",
+ score: 0,
+ },
+ {
+ a: "foo",
+ b: "foosd",
+ score: 2,
+ },
+ {
+ a: "foo",
+ b: "bla",
+ score: -1,
+ },
+ {
+ a: "bla foo",
+ b: "bla",
+ score: -1,
+ },
+ {
+ a: "foo",
+ b: "",
+ score: -1,
+ },
+ {
+ a: "",
+ b: "foo",
+ score: 3,
+ },
+ }
+ for i, c := range cases {
+ g := adjusted(c.a, c.b)
+ if g != c.score {
+ t.Fatalf("case %d not equal, got: %d, want: %d", i, g, c.score)
}
+ }
}
func TestDiscoveryScore(t *testing.T) {
- cases := []struct{
- q string
- disp map[string]string
- keys map[string]string
- score int
- }{
- {
- q: "test",
- disp: map[string]string{
- "en": "test",
- "de": "test",
- },
- keys: map[string]string{
- "en": "testing",
- "de": "testing",
- },
- score: 4,
- },
- {
- q: "test",
- disp: map[string]string{
- "en": "testing",
- "de": "testing",
- },
- keys: map[string]string{
- "en": "test",
- "de": "test",
- },
- score: 8,
- },
- {
- q: "foo",
- disp: map[string]string{
- "en": "test",
- "de": "testing",
- },
- keys: map[string]string{
- "en": "foo",
- "de": "foo",
- },
- score: 6,
- },
- {
- q: "fox",
- disp: map[string]string{
- "en": "test",
- "de": "testing",
- },
- keys: map[string]string{
- "en": "foo",
- "de": "foo",
- },
- score: -2,
- },
- }
+ cases := []struct {
+ q string
+ disp map[string]string
+ keys map[string]string
+ score int
+ }{
+ {
+ q: "test",
+ disp: map[string]string{
+ "en": "test",
+ "de": "test",
+ },
+ keys: map[string]string{
+ "en": "testing",
+ "de": "testing",
+ },
+ score: 4,
+ },
+ {
+ q: "test",
+ disp: map[string]string{
+ "en": "testing",
+ "de": "testing",
+ },
+ keys: map[string]string{
+ "en": "test",
+ "de": "test",
+ },
+ score: 8,
+ },
+ {
+ q: "foo",
+ disp: map[string]string{
+ "en": "test",
+ "de": "testing",
+ },
+ keys: map[string]string{
+ "en": "foo",
+ "de": "foo",
+ },
+ score: 6,
+ },
+ {
+ q: "fox",
+ disp: map[string]string{
+ "en": "test",
+ "de": "testing",
+ },
+ keys: map[string]string{
+ "en": "foo",
+ "de": "foo",
+ },
+ score: -2,
+ },
+ }
- for i, c := range cases {
- g := DiscoveryScore(c.q, c.disp, c.keys)
- if g != c.score {
- t.Fatalf("case %d not equal, got: %d, want: %d", i, g, c.score)
- }
+ for i, c := range cases {
+ g := DiscoveryScore(c.q, c.disp, c.keys)
+ if g != c.score {
+ t.Fatalf("case %d not equal, got: %d, want: %d", i, g, c.score)
}
+ }
}
func TestRemoveDiacritics(t *testing.T) {
@@ -179,9 +179,9 @@ func TestRemoveDiacritics(t *testing.T) {
e: nil,
},
{
- input: "GÉANT",
- want: "GEANT",
- e: nil,
+ input: "GÉANT",
+ want: "GEANT",
+ e: nil,
},
}