2021-09-21 19:18:56 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2025-02-25 22:24:38 +01:00
|
|
|
"slices"
|
2021-09-21 19:18:56 +02:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNormalizeWords(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
input []string
|
|
|
|
expected []string
|
|
|
|
}{
|
|
|
|
{"simple", []string{"one", "two", "three"}, []string{"one", "three", "two"}},
|
|
|
|
{"duplicates", []string{"one", "one", "two", "one", "three", "two"}, []string{"one", "three", "two"}},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
valid := normalizeWords(tc.input)
|
2025-02-25 22:24:38 +01:00
|
|
|
if slices.Compare(valid, tc.expected) != 0 {
|
|
|
|
t.Errorf("got %v, want %v", valid, tc.expected)
|
|
|
|
}
|
2021-09-21 19:18:56 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestScoreIndex(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
input []string
|
|
|
|
index []string
|
|
|
|
expected int
|
|
|
|
}{
|
|
|
|
{"simple", []string{"one", "two", "three"}, []string{"one", "three", "two"}, 3},
|
|
|
|
{"duplicates", []string{"one", "one"}, []string{"one", "three", "two"}, 2},
|
|
|
|
{"none", []string{"one", "two"}, []string{"three", "four", "five"}, 0},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
valid := scoreIndex(tc.input, tc.index)
|
2025-02-25 22:24:38 +01:00
|
|
|
if valid != tc.expected {
|
|
|
|
t.Errorf("got %v, want %v", valid, tc.expected)
|
|
|
|
}
|
2021-09-21 19:18:56 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|