github.com/matrixorigin/matrixone@v1.2.0/pkg/vectorize/moarray/gonums_utils_test.go (about) 1 // Copyright 2023 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package moarray 16 17 import ( 18 "gonum.org/v1/gonum/mat" 19 "reflect" 20 "testing" 21 ) 22 23 func Test_ToGonumVectors(t *testing.T) { 24 type args struct { 25 vectors [][]float64 26 } 27 tests := []struct { 28 name string 29 args args 30 want []*mat.VecDense 31 }{ 32 { 33 name: "Test1", 34 args: args{ 35 vectors: [][]float64{{1, 2, 3}, {4, 5, 6}}, 36 }, 37 want: []*mat.VecDense{ 38 mat.NewVecDense(3, []float64{1, 2, 3}), 39 mat.NewVecDense(3, []float64{4, 5, 6}), 40 }, 41 }, 42 } 43 for _, tt := range tests { 44 t.Run(tt.name, func(t *testing.T) { 45 if got, _ := ToGonumVectors[float64](tt.args.vectors...); !reflect.DeepEqual(got, tt.want) { 46 t.Errorf("ToGonumVectors() = %v, want %v", got, tt.want) 47 } 48 }) 49 } 50 } 51 52 func Test_ToMoArrays(t *testing.T) { 53 type args struct { 54 vectors []*mat.VecDense 55 } 56 tests := []struct { 57 name string 58 args args 59 want [][]float64 60 }{ 61 { 62 name: "Test1", 63 args: args{ 64 vectors: []*mat.VecDense{ 65 mat.NewVecDense(3, []float64{1, 2, 3}), 66 mat.NewVecDense(3, []float64{4, 5, 6}), 67 }, 68 }, 69 want: [][]float64{{1, 2, 3}, {4, 5, 6}}, 70 }, 71 } 72 for _, tt := range tests { 73 t.Run(tt.name, func(t *testing.T) { 74 if got, _ := ToMoArrays[float64](tt.args.vectors); !reflect.DeepEqual(got, tt.want) { 75 t.Errorf("ToMoArrays() = %v, want %v", got, tt.want) 76 } 77 }) 78 } 79 }