github.com/weaviate/weaviate@v1.24.6/usecases/modulecomponents/arguments/nearThermal/graphql_extract_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 nearThermal
    13  
    14  import (
    15  	"reflect"
    16  	"testing"
    17  )
    18  
    19  func Test_extractNearThermalFn(t *testing.T) {
    20  	type args struct {
    21  		source map[string]interface{}
    22  	}
    23  	tests := []struct {
    24  		name string
    25  		args args
    26  		want interface{}
    27  	}{
    28  		{
    29  			name: "should extract properly with distance and thermal params set",
    30  			args: args{
    31  				source: map[string]interface{}{
    32  					"thermal":  "base64;encoded",
    33  					"distance": float64(0.9),
    34  				},
    35  			},
    36  			want: &NearThermalParams{
    37  				Thermal:      "base64;encoded",
    38  				Distance:     0.9,
    39  				WithDistance: true,
    40  			},
    41  		},
    42  		{
    43  			name: "should extract properly with certainty and thermal params set",
    44  			args: args{
    45  				source: map[string]interface{}{
    46  					"thermal":   "base64;encoded",
    47  					"certainty": float64(0.9),
    48  				},
    49  			},
    50  			want: &NearThermalParams{
    51  				Thermal:   "base64;encoded",
    52  				Certainty: 0.9,
    53  			},
    54  		},
    55  		{
    56  			name: "should extract properly with only thermal set",
    57  			args: args{
    58  				source: map[string]interface{}{
    59  					"thermal": "base64;encoded",
    60  				},
    61  			},
    62  			want: &NearThermalParams{
    63  				Thermal: "base64;encoded",
    64  			},
    65  		},
    66  		{
    67  			name: "should extract properly with thermal and targetVectors set",
    68  			args: args{
    69  				source: map[string]interface{}{
    70  					"thermal":       "base64;encoded",
    71  					"targetVectors": []interface{}{"targetVector1", "targetVector2"},
    72  				},
    73  			},
    74  			want: &NearThermalParams{
    75  				Thermal:       "base64;encoded",
    76  				TargetVectors: []string{"targetVector1", "targetVector2"},
    77  			},
    78  		},
    79  	}
    80  	for _, tt := range tests {
    81  		t.Run(tt.name, func(t *testing.T) {
    82  			if got := extractNearThermalFn(tt.args.source); !reflect.DeepEqual(got, tt.want) {
    83  				t.Errorf("extractNearThermalFn() = %v, want %v", got, tt.want)
    84  			}
    85  		})
    86  	}
    87  }