Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
69 lines
1.9 KiB
Go
69 lines
1.9 KiB
Go
package str
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestLevenshteinDistance(t *testing.T) {
|
|
tests := []struct {
|
|
a string
|
|
b string
|
|
want int
|
|
}{
|
|
{"", "hello", 5},
|
|
{"hello", "", 5},
|
|
{"hello", "hello", 0},
|
|
{"ab", "aa", 1},
|
|
{"ab", "ba", 2},
|
|
{"ab", "aaa", 2},
|
|
{"bbb", "a", 3},
|
|
{"kitten", "sitting", 3},
|
|
{"distance", "difference", 5},
|
|
{"levenshtein", "frankenstein", 6},
|
|
{"resume and cafe", "resumes and cafes", 2},
|
|
{"a very long string that is meant to exceed", "another very long string that is meant to exceed", 6},
|
|
// Testing acutes and umlauts
|
|
{"resumé and café", "resumés and cafés", 2},
|
|
{"resume and cafe", "resumé and café", 4},
|
|
{"Hafþór Júlíus Björnsson", "Hafþor Julius Bjornsson", 8},
|
|
// Only 2 characters are less in the 2nd string
|
|
{"།་གམ་འས་པ་་མ།", "།་གམའས་པ་་མ", 6},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.a, func(t *testing.T) {
|
|
if got := ToLevenshteinDistance(tt.a, tt.b); got != tt.want {
|
|
t.Errorf("LevenshteinDistance() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// goos: darwin
|
|
// goarch: arm64
|
|
// pkg: github.com/cortezaproject/corteza/server/pkg/str
|
|
// BenchmarkLeven_100_100-12 39949 25767 ns/op 93184 B/op 102 allocs/op
|
|
// BenchmarkLeven_1000_1000-12 390 3081967 ns/op 8298552 B/op 1011 allocs/op
|
|
// BenchmarkLeven_10000_10000-12 4 299103531 ns/op 829957216 B/op 10131 allocs/op
|
|
// PASS
|
|
|
|
func benchmarkLeven(b *testing.B, w1l, w2l int) {
|
|
w1 := randStringRunes(w1l)
|
|
w2 := randStringRunes(w2l)
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
ToLevenshteinDistance(w1, w2)
|
|
}
|
|
}
|
|
|
|
func BenchmarkLeven_100_100(b *testing.B) {
|
|
benchmarkLeven(b, 100, 100)
|
|
}
|
|
|
|
func BenchmarkLeven_1000_1000(b *testing.B) {
|
|
benchmarkLeven(b, 1000, 1000)
|
|
}
|
|
|
|
func BenchmarkLeven_10000_10000(b *testing.B) {
|
|
benchmarkLeven(b, 10000, 10000)
|
|
}
|