2014-05-04 23:11:37 +02:00
|
|
|
package pairwise
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
2018-06-07 01:55:40 +08:00
|
|
|
"gonum.org/v1/gonum/mat"
|
2014-05-04 23:11:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestChebyshev(t *testing.T) {
|
2018-03-23 23:39:55 +00:00
|
|
|
var vectorX, vectorY *mat.Dense
|
2014-05-04 23:11:37 +02:00
|
|
|
chebyshev := NewChebyshev()
|
|
|
|
|
|
|
|
Convey("Given two vectors", t, func() {
|
2018-03-23 23:39:55 +00:00
|
|
|
vectorX = mat.NewDense(4, 1, []float64{1, 2, 3, 4})
|
|
|
|
vectorY = mat.NewDense(4, 1, []float64{-5, -6, 7, 8})
|
2014-05-04 23:11:37 +02:00
|
|
|
|
|
|
|
Convey("When calculating distance with two vectors", func() {
|
|
|
|
result := chebyshev.Distance(vectorX, vectorY)
|
|
|
|
|
|
|
|
Convey("The result should be 8", func() {
|
|
|
|
So(result, ShouldEqual, 8)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("When calculating distance with row vectors", func() {
|
2015-09-13 11:22:27 +01:00
|
|
|
vectorX.Copy(vectorX.T())
|
|
|
|
vectorY.Copy(vectorY.T())
|
2014-05-04 23:11:37 +02:00
|
|
|
result := chebyshev.Distance(vectorX, vectorY)
|
|
|
|
|
|
|
|
Convey("The result should be 8", func() {
|
|
|
|
So(result, ShouldEqual, 8)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2015-05-26 23:43:35 +01:00
|
|
|
Convey("When calculating distance with different dimension matrices", func() {
|
2019-06-18 10:36:02 +01:00
|
|
|
vectorX.CloneFrom(vectorX.T())
|
2015-05-26 23:43:35 +01:00
|
|
|
So(func() { chebyshev.Distance(vectorX, vectorY) }, ShouldPanic)
|
2014-05-04 23:11:37 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|