Initialized a proper go module for search, began adding tests and fixed a minor bug!
This commit is contained in:
parent
39e58554a1
commit
e504ad9fce
4 changed files with 67 additions and 0 deletions
43
search/search_test.go
Normal file
43
search/search_test.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
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)
|
||||
require.Equal(t, tc.expected, valid)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
require.Equal(t, tc.expected, valid)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue