53 lines
2.2 KiB
Go
53 lines
2.2 KiB
Go
package search
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTranslit(t *testing.T) {
|
|
assert.Equal(t, "kino", Translit("Кино"))
|
|
assert.Equal(t, "shchedrin", Translit("Щедрин"))
|
|
assert.Equal(t, "кино", Translit("Kino"))
|
|
assert.Equal(t, "щедрин", Translit("shchedrin"))
|
|
assert.Equal(t, "", Translit("1984"))
|
|
}
|
|
|
|
func TestTranslitVariants(t *testing.T) {
|
|
assert.Equal(t, []string{"боулевард депо", "бульвар депо"}, TranslitVariants("BOULEVARD DEPO"))
|
|
assert.Equal(t, []string{"боулевард депо кс 161", "бульвар депо кс 161"}, TranslitVariants("Boulevard Depo X 161"))
|
|
assert.Equal(t, []string{"kino"}, TranslitVariants("Кино"))
|
|
assert.Empty(t, TranslitVariants("1984"))
|
|
assert.Equal(t, []string{"боулевардиер"}, TranslitVariants("Boulevardier"), "whole words only")
|
|
}
|
|
|
|
func TestPersonalizeKeepsExactArtistFirst(t *testing.T) {
|
|
exact, collaboration, reversed := uuid.NewString(), uuid.NewString(), uuid.NewString()
|
|
found := []string{collaboration, reversed, exact}
|
|
aff := map[uuid.UUID]float64{uuid.MustParse(collaboration): 10000, uuid.MustParse(exact): -100}
|
|
assert.Equal(t, []string{exact, collaboration}, personalizeArtists(found, []string{exact}, aff, 2))
|
|
assert.Equal(t, []string{exact}, personalizeArtists(found, []string{exact}, aff, 1))
|
|
assert.Equal(t, found[:2], personalizeArtists(found, nil, nil, 2))
|
|
}
|
|
|
|
func TestSwitchLayout(t *testing.T) {
|
|
assert.Equal(t, "привет", SwitchLayout("ghbdtn"))
|
|
assert.Equal(t, "hello", SwitchLayout("руддщ"))
|
|
assert.Equal(t, "кино", SwitchLayout("rbyj"))
|
|
assert.Equal(t, "", SwitchLayout("123"))
|
|
}
|
|
|
|
func TestPersonalizeLiftsFamiliarAndSinksDisliked(t *testing.T) {
|
|
liked, disliked := uuid.New(), uuid.New()
|
|
other := []string{uuid.NewString(), uuid.NewString(), uuid.NewString()}
|
|
found := []string{other[0], disliked.String(), other[1], other[2], liked.String()}
|
|
aff := map[uuid.UUID]float64{liked: 30, disliked: -10}
|
|
|
|
got := personalize(found, aff, 3)
|
|
assert.Equal(t, []string{liked.String(), other[0], other[1]}, got)
|
|
assert.Equal(t, found[:2], personalize(found, nil, 2), "без вкуса — порядок релевантности")
|
|
}
|