1
0
mirror of https://github.com/sjwhitworth/golearn.git synced 2025-05-07 19:29:19 +08:00
golearn/metrics/pairwise/cosine_test.go

37 lines
712 B
Go
Raw Normal View History

2017-04-07 21:11:20 +08:00
package pairwise
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
2018-06-07 01:55:40 +08:00
"gonum.org/v1/gonum/mat"
2017-04-07 21:11:20 +08:00
)
func TestCosine(t *testing.T) {
var vectorX, vectorY *mat.Dense
2017-04-07 21:11:20 +08:00
cosine := NewCosine()
Convey("Given two vectors", t, func() {
vectorX = mat.NewDense(3, 1, []float64{1, 2, 3})
vectorY = mat.NewDense(3, 1, []float64{2, 4, 6})
2017-04-07 21:11:20 +08:00
Convey("When doing inner Dot", func() {
result := cosine.Dot(vectorX, vectorY)
Convey("The result should be 25", func() {
So(result, ShouldEqual, 28)
})
})
Convey("When calculating distance", func() {
result := cosine.Distance(vectorX, vectorY)
Convey("The result should be 0", func() {
So(result, ShouldEqual, 0)
})
})
})
}