github.com/weaviate/weaviate@v1.24.6/modules/text2vec-gpt4all/vectorizer/texts_test.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package vectorizer
    13  
    14  import (
    15  	"context"
    16  	"testing"
    17  
    18  	"github.com/stretchr/testify/assert"
    19  	"github.com/stretchr/testify/require"
    20  )
    21  
    22  // as used in the nearText searcher
    23  func TestVectorizingTexts(t *testing.T) {
    24  	type testCase struct {
    25  		name               string
    26  		input              []string
    27  		expectedClientCall string
    28  	}
    29  
    30  	tests := []testCase{
    31  		{
    32  			name:               "single word",
    33  			input:              []string{"hello"},
    34  			expectedClientCall: "hello",
    35  		},
    36  		{
    37  			name:               "multiple words",
    38  			input:              []string{"hello world, this is me!"},
    39  			expectedClientCall: "hello world, this is me!",
    40  		},
    41  
    42  		{
    43  			name:               "multiple sentences",
    44  			input:              []string{"this is sentence 1", "and here's number 2"},
    45  			expectedClientCall: "and here's number 2",
    46  		},
    47  	}
    48  
    49  	for _, test := range tests {
    50  		t.Run(test.name, func(t *testing.T) {
    51  			client := &fakeClient{}
    52  
    53  			v := New(client)
    54  
    55  			settings := &fakeClassConfig{}
    56  			vec, err := v.Texts(context.Background(), test.input, settings)
    57  
    58  			require.Nil(t, err)
    59  			assert.Equal(t, []float32{0, 1, 2, 3}, vec)
    60  			assert.Equal(t, test.expectedClientCall, client.lastInput)
    61  		})
    62  	}
    63  }