github.com/weaviate/weaviate@v1.24.6/modules/text2vec-contextionary/additional/sempath/builder_params_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 sempath
    13  
    14  import "testing"
    15  
    16  func TestParams_validate(t *testing.T) {
    17  	type fields struct {
    18  		SearchVector []float32
    19  	}
    20  	type args struct {
    21  		inputSize int
    22  		dims      int
    23  	}
    24  	tests := []struct {
    25  		name    string
    26  		fields  fields
    27  		args    args
    28  		wantErr bool
    29  	}{
    30  		{
    31  			name: "Should validate",
    32  			fields: fields{
    33  				SearchVector: []float32{1.0},
    34  			},
    35  			args: args{
    36  				inputSize: 25,
    37  				dims:      0,
    38  			},
    39  			wantErr: false,
    40  		},
    41  		{
    42  			name: "Should error with empty SearchVector",
    43  			fields: fields{
    44  				SearchVector: []float32{},
    45  			},
    46  			args: args{
    47  				inputSize: 25,
    48  				dims:      0,
    49  			},
    50  			wantErr: true,
    51  		},
    52  		{
    53  			name:   "Should error with nil SearchVector",
    54  			fields: fields{},
    55  			args: args{
    56  				inputSize: 25,
    57  				dims:      0,
    58  			},
    59  			wantErr: true,
    60  		},
    61  		{
    62  			name: "Should error with with inputSize greater then 25",
    63  			fields: fields{
    64  				SearchVector: []float32{1.0},
    65  			},
    66  			args: args{
    67  				inputSize: 26,
    68  				dims:      0,
    69  			},
    70  			wantErr: true,
    71  		},
    72  		{
    73  			name: "Should error with with inputSize greater then 25 and nil SearchVector",
    74  			fields: fields{
    75  				SearchVector: nil,
    76  			},
    77  			args: args{
    78  				inputSize: 26,
    79  				dims:      0,
    80  			},
    81  			wantErr: true,
    82  		},
    83  		{
    84  			name: "Should error with with inputSize greater then 25 and empty SearchVector",
    85  			fields: fields{
    86  				SearchVector: []float32{},
    87  			},
    88  			args: args{
    89  				inputSize: 26,
    90  				dims:      0,
    91  			},
    92  			wantErr: true,
    93  		},
    94  	}
    95  	for _, tt := range tests {
    96  		t.Run(tt.name, func(t *testing.T) {
    97  			p := &Params{
    98  				SearchVector: tt.fields.SearchVector,
    99  			}
   100  			if err := p.validate(tt.args.inputSize, tt.args.dims); (err != nil) != tt.wantErr {
   101  				t.Errorf("Params.validate() error = %v, wantErr %v", err, tt.wantErr)
   102  			}
   103  		})
   104  	}
   105  }