2014-05-02 23:30:12 +08:00
|
|
|
package pairwise
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2014-05-03 00:55:38 +08:00
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
2018-06-07 01:55:40 +08:00
|
|
|
"gonum.org/v1/gonum/mat"
|
2014-05-02 23:30:12 +08:00
|
|
|
)
|
|
|
|
|
2014-05-02 23:49:06 +08:00
|
|
|
func TestEuclidean(t *testing.T) {
|
2018-03-23 23:39:55 +00:00
|
|
|
var vectorX, vectorY *mat.Dense
|
2014-05-02 23:30:12 +08:00
|
|
|
euclidean := NewEuclidean()
|
|
|
|
|
|
|
|
Convey("Given two vectors", t, func() {
|
2018-03-23 23:39:55 +00:00
|
|
|
vectorX = mat.NewDense(3, 1, []float64{1, 2, 3})
|
|
|
|
vectorY = mat.NewDense(3, 1, []float64{2, 4, 5})
|
2014-05-02 23:30:12 +08:00
|
|
|
|
|
|
|
Convey("When doing inner product", func() {
|
|
|
|
result := euclidean.InnerProduct(vectorX, vectorY)
|
|
|
|
|
2014-05-02 23:49:06 +08:00
|
|
|
Convey("The result should be 25", func() {
|
|
|
|
So(result, ShouldEqual, 25)
|
|
|
|
})
|
2014-05-02 23:30:12 +08:00
|
|
|
})
|
|
|
|
|
2014-05-02 23:49:06 +08:00
|
|
|
Convey("When calculating distance", func() {
|
2014-05-03 01:03:29 +08:00
|
|
|
result := euclidean.Distance(vectorX, vectorY)
|
2014-05-02 23:30:12 +08:00
|
|
|
|
2014-05-02 23:49:06 +08:00
|
|
|
Convey("The result should be 3", func() {
|
|
|
|
So(result, ShouldEqual, 3)
|
2014-05-02 23:30:12 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|