github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/entity/columns_vector_gen_test.go (about) 1 // Code generated by go generate; DO NOT EDIT 2 // This file is generated by go generated 3 4 package entity 5 6 import ( 7 "fmt" 8 "math/rand" 9 "testing" 10 "time" 11 12 schema "github.com/milvus-io/milvus-proto/go-api/v2/schemapb" 13 "github.com/stretchr/testify/assert" 14 ) 15 16 func TestColumnBinaryVector(t *testing.T) { 17 rand.Seed(time.Now().UnixNano()) 18 columnName := fmt.Sprintf("column_BinaryVector_%d", rand.Int()) 19 columnLen := 12 + rand.Intn(10) 20 dim := ([]int{64, 128, 256, 512})[rand.Intn(4)] 21 22 v := make([][]byte,0, columnLen) 23 dlen := dim 24 dlen /= 8 25 26 27 for i := 0; i < columnLen; i++ { 28 entry := make([]byte, dlen) 29 v = append(v, entry) 30 } 31 column := NewColumnBinaryVector(columnName, dim, v) 32 33 t.Run("test meta", func(t *testing.T) { 34 ft := FieldTypeBinaryVector 35 assert.Equal(t, "BinaryVector", ft.Name()) 36 assert.Equal(t, "[]byte", ft.String()) 37 pbName, pbType := ft.PbFieldType() 38 assert.Equal(t, "[]byte", pbName) 39 assert.Equal(t, "", pbType) 40 }) 41 42 t.Run("test column attribute", func(t *testing.T) { 43 assert.Equal(t, columnName, column.Name()) 44 assert.Equal(t, FieldTypeBinaryVector, column.Type()) 45 assert.Equal(t, columnLen, column.Len()) 46 assert.Equal(t, dim, column.Dim()) 47 assert.Equal(t ,v, column.Data()) 48 49 var ev []byte 50 err := column.AppendValue(ev) 51 assert.Equal(t, columnLen+1, column.Len()) 52 assert.Nil(t, err) 53 54 err = column.AppendValue(struct{}{}) 55 assert.Equal(t, columnLen+1, column.Len()) 56 assert.NotNil(t, err) 57 }) 58 59 t.Run("test column field data", func(t *testing.T) { 60 fd := column.FieldData() 61 assert.NotNil(t, fd) 62 assert.Equal(t, fd.GetFieldName(), columnName) 63 64 c, err := FieldDataVector(fd) 65 assert.NotNil(t, c) 66 assert.NoError(t, err) 67 }) 68 69 t.Run("test column field data error", func(t *testing.T) { 70 fd := &schema.FieldData{ 71 Type: schema.DataType_BinaryVector, 72 FieldName: columnName, 73 } 74 _, err := FieldDataVector(fd) 75 assert.Error(t, err) 76 }) 77 78 } 79 80 func TestColumnFloatVector(t *testing.T) { 81 rand.Seed(time.Now().UnixNano()) 82 columnName := fmt.Sprintf("column_FloatVector_%d", rand.Int()) 83 columnLen := 12 + rand.Intn(10) 84 dim := ([]int{64, 128, 256, 512})[rand.Intn(4)] 85 86 v := make([][]float32,0, columnLen) 87 dlen := dim 88 89 90 91 for i := 0; i < columnLen; i++ { 92 entry := make([]float32, dlen) 93 v = append(v, entry) 94 } 95 column := NewColumnFloatVector(columnName, dim, v) 96 97 t.Run("test meta", func(t *testing.T) { 98 ft := FieldTypeFloatVector 99 assert.Equal(t, "FloatVector", ft.Name()) 100 assert.Equal(t, "[]float32", ft.String()) 101 pbName, pbType := ft.PbFieldType() 102 assert.Equal(t, "[]float32", pbName) 103 assert.Equal(t, "", pbType) 104 }) 105 106 t.Run("test column attribute", func(t *testing.T) { 107 assert.Equal(t, columnName, column.Name()) 108 assert.Equal(t, FieldTypeFloatVector, column.Type()) 109 assert.Equal(t, columnLen, column.Len()) 110 assert.Equal(t, dim, column.Dim()) 111 assert.Equal(t ,v, column.Data()) 112 113 var ev []float32 114 err := column.AppendValue(ev) 115 assert.Equal(t, columnLen+1, column.Len()) 116 assert.Nil(t, err) 117 118 err = column.AppendValue(struct{}{}) 119 assert.Equal(t, columnLen+1, column.Len()) 120 assert.NotNil(t, err) 121 }) 122 123 t.Run("test column field data", func(t *testing.T) { 124 fd := column.FieldData() 125 assert.NotNil(t, fd) 126 assert.Equal(t, fd.GetFieldName(), columnName) 127 128 c, err := FieldDataVector(fd) 129 assert.NotNil(t, c) 130 assert.NoError(t, err) 131 }) 132 133 t.Run("test column field data error", func(t *testing.T) { 134 fd := &schema.FieldData{ 135 Type: schema.DataType_FloatVector, 136 FieldName: columnName, 137 } 138 _, err := FieldDataVector(fd) 139 assert.Error(t, err) 140 }) 141 142 } 143 144 func TestColumnFloat16Vector(t *testing.T) { 145 rand.Seed(time.Now().UnixNano()) 146 columnName := fmt.Sprintf("column_Float16Vector_%d", rand.Int()) 147 columnLen := 12 + rand.Intn(10) 148 dim := ([]int{64, 128, 256, 512})[rand.Intn(4)] 149 150 v := make([][]byte,0, columnLen) 151 dlen := dim 152 153 dlen *= 2 154 155 for i := 0; i < columnLen; i++ { 156 entry := make([]byte, dlen) 157 v = append(v, entry) 158 } 159 column := NewColumnFloat16Vector(columnName, dim, v) 160 161 t.Run("test meta", func(t *testing.T) { 162 ft := FieldTypeFloat16Vector 163 assert.Equal(t, "Float16Vector", ft.Name()) 164 assert.Equal(t, "[]byte", ft.String()) 165 pbName, pbType := ft.PbFieldType() 166 assert.Equal(t, "[]byte", pbName) 167 assert.Equal(t, "", pbType) 168 }) 169 170 t.Run("test column attribute", func(t *testing.T) { 171 assert.Equal(t, columnName, column.Name()) 172 assert.Equal(t, FieldTypeFloat16Vector, column.Type()) 173 assert.Equal(t, columnLen, column.Len()) 174 assert.Equal(t, dim, column.Dim()) 175 assert.Equal(t ,v, column.Data()) 176 177 var ev []byte 178 err := column.AppendValue(ev) 179 assert.Equal(t, columnLen+1, column.Len()) 180 assert.Nil(t, err) 181 182 err = column.AppendValue(struct{}{}) 183 assert.Equal(t, columnLen+1, column.Len()) 184 assert.NotNil(t, err) 185 }) 186 187 t.Run("test column field data", func(t *testing.T) { 188 fd := column.FieldData() 189 assert.NotNil(t, fd) 190 assert.Equal(t, fd.GetFieldName(), columnName) 191 192 c, err := FieldDataVector(fd) 193 assert.NotNil(t, c) 194 assert.NoError(t, err) 195 }) 196 197 t.Run("test column field data error", func(t *testing.T) { 198 fd := &schema.FieldData{ 199 Type: schema.DataType_Float16Vector, 200 FieldName: columnName, 201 } 202 _, err := FieldDataVector(fd) 203 assert.Error(t, err) 204 }) 205 206 } 207 208 func TestColumnBFloat16Vector(t *testing.T) { 209 rand.Seed(time.Now().UnixNano()) 210 columnName := fmt.Sprintf("column_BFloat16Vector_%d", rand.Int()) 211 columnLen := 12 + rand.Intn(10) 212 dim := ([]int{64, 128, 256, 512})[rand.Intn(4)] 213 214 v := make([][]byte,0, columnLen) 215 dlen := dim 216 217 dlen *= 2 218 219 for i := 0; i < columnLen; i++ { 220 entry := make([]byte, dlen) 221 v = append(v, entry) 222 } 223 column := NewColumnBFloat16Vector(columnName, dim, v) 224 225 t.Run("test meta", func(t *testing.T) { 226 ft := FieldTypeBFloat16Vector 227 assert.Equal(t, "BFloat16Vector", ft.Name()) 228 assert.Equal(t, "[]byte", ft.String()) 229 pbName, pbType := ft.PbFieldType() 230 assert.Equal(t, "[]byte", pbName) 231 assert.Equal(t, "", pbType) 232 }) 233 234 t.Run("test column attribute", func(t *testing.T) { 235 assert.Equal(t, columnName, column.Name()) 236 assert.Equal(t, FieldTypeBFloat16Vector, column.Type()) 237 assert.Equal(t, columnLen, column.Len()) 238 assert.Equal(t, dim, column.Dim()) 239 assert.Equal(t ,v, column.Data()) 240 241 var ev []byte 242 err := column.AppendValue(ev) 243 assert.Equal(t, columnLen+1, column.Len()) 244 assert.Nil(t, err) 245 246 err = column.AppendValue(struct{}{}) 247 assert.Equal(t, columnLen+1, column.Len()) 248 assert.NotNil(t, err) 249 }) 250 251 t.Run("test column field data", func(t *testing.T) { 252 fd := column.FieldData() 253 assert.NotNil(t, fd) 254 assert.Equal(t, fd.GetFieldName(), columnName) 255 256 c, err := FieldDataVector(fd) 257 assert.NotNil(t, c) 258 assert.NoError(t, err) 259 }) 260 261 t.Run("test column field data error", func(t *testing.T) { 262 fd := &schema.FieldData{ 263 Type: schema.DataType_BFloat16Vector, 264 FieldName: columnName, 265 } 266 _, err := FieldDataVector(fd) 267 assert.Error(t, err) 268 }) 269 270 } 271