chore: 项目基线(基于 WeKnora 定制版,整理文件忽略规则)
This commit is contained in:
commit
9097ee699d
5769 files changed
+1446466
No files matched your search
@@ -0,0 +1,43 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type placed struct {
|
||||
index int
|
||||
vector []float32
|
||||
}
|
||||
|
||||
func place(want int, reply []placed) ([][]float32, error) {
|
||||
return PlaceEmbeddings(want, len(reply), func(i int) (int, []float32) {
|
||||
return reply[i].index, reply[i].vector
|
||||
})
|
||||
}
|
||||
|
||||
func TestPlaceEmbeddingsHonoursTheReportedIndex(t *testing.T) {
|
||||
got, err := place(2, []placed{{1, []float32{2}}, {0, []float32{1}}})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, [][]float32{{1}, {2}}, got)
|
||||
}
|
||||
|
||||
// Every way a reply can fail to cover the inputs exactly once is an error:
|
||||
// each of them would otherwise store a vector under the wrong chunk or an
|
||||
// empty one.
|
||||
func TestPlaceEmbeddingsRefusesAReplyThatDoesNotCoverEachInputOnce(t *testing.T) {
|
||||
cases := map[string][]placed{
|
||||
"short": {{0, []float32{1}}},
|
||||
"out of range": {{0, []float32{1}}, {2, []float32{2}}},
|
||||
"duplicate": {{0, []float32{1}}, {0, []float32{2}}, {1, []float32{3}}},
|
||||
"empty vector": {{0, []float32{1}}, {1, nil}},
|
||||
}
|
||||
for name, reply := range cases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
_, err := place(2, reply)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user