Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunsk committed Feb 15, 2024
1 parent 6739a0d commit 634066a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 54 deletions.
2 changes: 1 addition & 1 deletion utils/moarray/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ func NormalizeGonumVectors(vectors []*mat.VecDense) {
// NormalizeMoVecf64 is used only in test functions.
func NormalizeMoVecf64(vector []float64) []float64 {
res := ToGonumVector[float64](vector)
//NormalizeGonumVector(res)
NormalizeGonumVector(res)
return ToMoArray[float64](res)
}
111 changes: 58 additions & 53 deletions utils/moarray/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,61 @@

package moarray

//func TestNormalizeMoArray(t *testing.T) {
// type args struct {
// vector []float64
// }
// tests := []struct {
// name string
// args args
// want []float64
// }{
// {
// name: "Test1",
// args: args{
// vector: []float64{1, 2, 3},
// },
// want: []float64{0.2672612419124244, 0.5345224838248488, 0.8017837257372732},
// },
// {
// name: "Test2",
// args: args{
// vector: []float64{-1, 2, 3},
// },
// want: []float64{-0.2672612419124244, 0.5345224838248488, 0.8017837257372732},
// },
// {
// name: "Test3",
// args: args{
// vector: []float64{0, 0, 0},
// },
// want: []float64{0, 0, 0},
// },
// {
// name: "Test4",
// args: args{
// vector: []float64{10, 3.333333333333333, 4, 5},
// },
// want: []float64{0.8108108108108107, 0.27027027027027023, 0.3243243243243243, 0.4054054054054054},
// },
// {
// name: "Test5",
// args: args{
// vector: []float64{1, 2, 3.6666666666666665, 4.666666666666666},
// },
// want: []float64{0.15767649936829103, 0.31535299873658207, 0.5781471643504005, 0.7358236637186913},
// },
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// if got := NormalizeMoVecf64(tt.args.vector); !assertx.InEpsilonF64Slice(tt.want, got) {
// t.Errorf("NormalizeMoVecf64() = %v, want %v", got, tt.want)
// }
// })
// }
//}
import (
"github.com/arjunsk/kmeans/utils/assertx"
"testing"
)

func TestNormalizeMoArray(t *testing.T) {
type args struct {
vector []float64
}
tests := []struct {
name string
args args
want []float64
}{
{
name: "Test1",
args: args{
vector: []float64{1, 2, 3},
},
want: []float64{0.2672612419124244, 0.5345224838248488, 0.8017837257372732},
},
{
name: "Test2",
args: args{
vector: []float64{-1, 2, 3},
},
want: []float64{-0.2672612419124244, 0.5345224838248488, 0.8017837257372732},
},
{
name: "Test3",
args: args{
vector: []float64{0, 0, 0},
},
want: []float64{0, 0, 0},
},
{
name: "Test4",
args: args{
vector: []float64{10, 3.333333333333333, 4, 5},
},
want: []float64{0.8108108108108107, 0.27027027027027023, 0.3243243243243243, 0.4054054054054054},
},
{
name: "Test5",
args: args{
vector: []float64{1, 2, 3.6666666666666665, 4.666666666666666},
},
want: []float64{0.15767649936829103, 0.31535299873658207, 0.5781471643504005, 0.7358236637186913},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NormalizeMoVecf64(tt.args.vector); !assertx.InEpsilonF64Slice(tt.want, got) {
t.Errorf("NormalizeMoVecf64() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 634066a

Please sign in to comment.