-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cranberra_test.go
51 lines (39 loc) · 1.26 KB
/
cranberra_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package pairwise
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
"gonum.org/v1/gonum/mat"
)
func TestCranberrra(t *testing.T) {
var vectorX, vectorY *mat.Dense
cranberra := NewCranberra()
Convey("Given two vectors that are same", t, func() {
vec := mat.NewDense(7, 1, []float64{0, 1, -2, 3.4, 5, -6.7, 89})
distance := cranberra.Distance(vec, vec)
Convey("The result should be 0", func() {
So(distance, ShouldEqual, 0)
})
})
Convey("Given two vectors", t, func() {
vectorX = mat.NewDense(5, 1, []float64{1, 2, 3, 4, 9})
vectorY = mat.NewDense(5, 1, []float64{-5, -6, 7, 4, 3})
Convey("When calculating distance with two vectors", func() {
result := cranberra.Distance(vectorX, vectorY)
Convey("The result should be 2.9", func() {
So(result, ShouldEqual, 2.9)
})
})
Convey("When calculating distance with row vectors", func() {
vectorX.Copy(vectorX.T())
vectorY.Copy(vectorY.T())
result := cranberra.Distance(vectorX, vectorY)
Convey("The result should be 2.9", func() {
So(result, ShouldEqual, 2.9)
})
})
Convey("When calculating distance with different dimension matrices", func() {
vectorX.CloneFrom(vectorX.T())
So(func() { cranberra.Distance(vectorX, vectorY) }, ShouldPanic)
})
})
}