github.com/weaviate/weaviate@v1.24.6/usecases/modulecomponents/arguments/nearText/param_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 nearText 13 14 import ( 15 "testing" 16 ) 17 18 func Test_validateNearText(t *testing.T) { 19 tests := []struct { 20 name string 21 param NearTextParams 22 wantErr bool 23 }{ 24 { 25 "May be empty", 26 NearTextParams{}, 27 false, 28 }, 29 30 { 31 "With just values", 32 NearTextParams{ 33 Values: []string{"foobar"}, 34 }, 35 false, 36 }, 37 { 38 "With values, distance, limit", 39 NearTextParams{ 40 Values: []string{"foobar"}, 41 Limit: 100, 42 Distance: 0.9, 43 WithDistance: true, 44 }, 45 false, 46 }, 47 { 48 "With values, certainty, limit", 49 NearTextParams{ 50 Values: []string{"foobar"}, 51 Limit: 100, 52 Certainty: 0.9, 53 }, 54 false, 55 }, 56 { 57 "With certainty and distance", 58 NearTextParams{ 59 Values: []string{"foobar"}, 60 Certainty: 0.9, 61 Distance: 0.1, 62 WithDistance: true, 63 }, 64 true, 65 }, 66 { 67 "When moveTo with force must also provide either values or objects (with distance)", 68 NearTextParams{ 69 Values: []string{"foobar"}, 70 Limit: 100, 71 Distance: 0.9, 72 WithDistance: true, 73 MoveTo: ExploreMove{ 74 Force: 0.9, 75 }, 76 }, 77 true, 78 }, 79 { 80 "When moveTo with force must also provide either values or objects (with certainty)", 81 NearTextParams{ 82 Values: []string{"foobar"}, 83 Limit: 100, 84 Certainty: 0.9, 85 MoveTo: ExploreMove{ 86 Force: 0.9, 87 }, 88 }, 89 true, 90 }, 91 { 92 "When moveAway with force must also provide either values or objects (with distance)", 93 NearTextParams{ 94 Values: []string{"foobar"}, 95 Limit: 100, 96 Distance: 0.9, 97 WithDistance: true, 98 MoveAwayFrom: ExploreMove{ 99 Force: 0.9, 100 }, 101 }, 102 true, 103 }, 104 { 105 "When moveAway with force must also provide either values or objects (with certainty)", 106 NearTextParams{ 107 Values: []string{"foobar"}, 108 Limit: 100, 109 Certainty: 0.9, 110 MoveAwayFrom: ExploreMove{ 111 Force: 0.9, 112 }, 113 }, 114 true, 115 }, 116 { 117 "When moveTo and moveAway with force must also provide either values or objects (with distance)", 118 NearTextParams{ 119 Values: []string{"foobar"}, 120 Limit: 100, 121 Distance: 0.9, 122 WithDistance: true, 123 MoveTo: ExploreMove{ 124 Force: 0.9, 125 }, 126 MoveAwayFrom: ExploreMove{ 127 Force: 0.9, 128 }, 129 }, 130 true, 131 }, 132 { 133 "When moveTo and moveAway with force must also provide either values or objects (with certainty)", 134 NearTextParams{ 135 Values: []string{"foobar"}, 136 Limit: 100, 137 Certainty: 0.9, 138 MoveTo: ExploreMove{ 139 Force: 0.9, 140 }, 141 MoveAwayFrom: ExploreMove{ 142 Force: 0.9, 143 }, 144 }, 145 true, 146 }, 147 { 148 "When moveTo or moveAway is with force must also provide either values or objects (with distance)", 149 NearTextParams{ 150 Values: []string{"foobar"}, 151 Limit: 100, 152 Distance: 0.9, 153 WithDistance: true, 154 MoveTo: ExploreMove{ 155 Values: []string{"move to"}, 156 Force: 0.9, 157 }, 158 MoveAwayFrom: ExploreMove{ 159 Force: 0.9, 160 }, 161 }, 162 true, 163 }, 164 { 165 "When moveTo or moveAway is with force must also provide either values or objects (with certainty)", 166 NearTextParams{ 167 Values: []string{"foobar"}, 168 Limit: 100, 169 Certainty: 0.9, 170 MoveTo: ExploreMove{ 171 Values: []string{"move to"}, 172 Force: 0.9, 173 }, 174 MoveAwayFrom: ExploreMove{ 175 Force: 0.9, 176 }, 177 }, 178 true, 179 }, 180 { 181 "When moveTo or moveAway is with force must provide values or objects (with distance)", 182 NearTextParams{ 183 Values: []string{"foobar"}, 184 Limit: 100, 185 Distance: 0.9, 186 WithDistance: true, 187 MoveTo: ExploreMove{ 188 Values: []string{"move to"}, 189 Force: 0.9, 190 }, 191 MoveAwayFrom: ExploreMove{ 192 Objects: []ObjectMove{ 193 {ID: "some-uuid"}, 194 }, 195 Force: 0.9, 196 }, 197 }, 198 false, 199 }, 200 { 201 "When moveTo or moveAway is with force must provide values or objects (with certainty)", 202 NearTextParams{ 203 Values: []string{"foobar"}, 204 Limit: 100, 205 Certainty: 0.9, 206 MoveTo: ExploreMove{ 207 Values: []string{"move to"}, 208 Force: 0.9, 209 }, 210 MoveAwayFrom: ExploreMove{ 211 Objects: []ObjectMove{ 212 {ID: "some-uuid"}, 213 }, 214 Force: 0.9, 215 }, 216 }, 217 false, 218 }, 219 { 220 "When more than one target vector is passed", 221 NearTextParams{ 222 Values: []string{"foobar"}, 223 TargetVectors: []string{"targetVector1", "targetVector2"}, 224 }, 225 true, 226 }, 227 } 228 for _, tt := range tests { 229 t.Run(tt.name, func(t *testing.T) { 230 if err := tt.param.Validate(); (err != nil) != tt.wantErr { 231 t.Errorf("validateNearText() error = %v, wantErr %v", err, tt.wantErr) 232 } 233 }) 234 } 235 }