-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweight_test.go
58 lines (47 loc) · 1.32 KB
/
weight_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
52
53
54
55
56
57
58
package nlp
import (
. "github.com/smartystreets/goconvey/convey"
"math"
"testing"
)
func TestWeightTF(t *testing.T) {
Convey("Given an array of words", t, func() {
words := []string{"a", "b", "c", "a", "b", "d", "a", "a", "d"}
Convey("when applying WeightTF", func() {
w := WeightTF(words)
Convey("it should have a correct lenght", func() {
So(len(w), ShouldEqual, 4)
})
Convey("it should have correct counts", func() {
So(w["a"], ShouldEqual, 4)
So(w["b"], ShouldEqual, 2)
So(w["c"], ShouldEqual, 1)
So(w["d"], ShouldEqual, 2)
})
})
Convey("when applying WeightBinary", func() {
w := WeightBinary(words)
Convey("it should have a correct lenght", func() {
So(len(w), ShouldEqual, 4)
})
Convey("it should have correct counts", func() {
So(w["a"], ShouldEqual, 1)
So(w["b"], ShouldEqual, 1)
So(w["c"], ShouldEqual, 1)
So(w["d"], ShouldEqual, 1)
})
})
Convey("when applying WeightLogTF", func() {
w := WeightLogTF(words)
Convey("it should have a correct lenght", func() {
So(len(w), ShouldEqual, 4)
})
Convey("it should have correct counts", func() {
So(w["a"], ShouldEqual, math.Log(1+4))
So(w["b"], ShouldEqual, math.Log(1+2))
So(w["c"], ShouldEqual, math.Log(1+1))
So(w["d"], ShouldEqual, math.Log(2+1))
})
})
})
}