-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvectorspace_test.go
104 lines (77 loc) · 2.87 KB
/
vectorspace_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// SPDX-License-Identifier: MIT
package golangvectorspace
import (
"testing"
)
func TestConcordance(t *testing.T) {
var concordance = BuildConcordance("this is a test")
got := concordance["this"]
if got != 1 {
t.Errorf("Cocordance expect (test) to have 1 but got %v", got)
}
got = concordance["is"]
if got != 1 {
t.Errorf("Cocordance expect (test) to have 1 but got %v", got)
}
got = concordance["a"]
if got != 1 {
t.Errorf("Cocordance expect (test) to have 1 but got %v", got)
}
got = concordance["test"]
if got != 1 {
t.Errorf("Cocordance expect (test) to have 1 but got %v", got)
}
}
func TestConcordanceCase(t *testing.T) {
var concordance = BuildConcordance("this THIS thIS ThIs")
got := concordance["this"]
if got != 4 {
t.Errorf("Cocordance expect (test) to have 1 but got %v", got)
}
}
func TestMagnitude(t *testing.T) {
var concordance = BuildConcordance("this is a test")
var got = concordance.Magnitude()
if got != 2 {
t.Errorf("Magnitude expected 2 but got %v", got)
}
}
func TestRelationSameExpectOne(t *testing.T) {
var concordance1 = BuildConcordance("this is a test")
var concordance2 = BuildConcordance("this is a test")
got := Relation(concordance1, concordance2)
if got != 1 {
t.Errorf("Relation expected 1 but got %v", got)
}
}
func TestRelationSimilarExpectSimilar(t *testing.T) {
var concordance1 = BuildConcordance("this is a test")
var concordance2 = BuildConcordance("this test")
got := Relation(concordance1, concordance2)
if got != 0.7071067811865475 {
t.Errorf("Relation expected 0.7071067811865475 but got %v", got)
}
}
func TestRelationDifferentExpectZero(t *testing.T) {
var concordance1 = BuildConcordance("this is a test")
var concordance2 = BuildConcordance("not related at all")
got := Relation(concordance1, concordance2)
if got != 0 {
t.Errorf("Relation expected 0.5 but got %v", got)
}
}
func TestRelationSimilarStrings(t *testing.T) {
var concordance1 = BuildConcordance("Go has a lightweight test framework composed of the go test command and the testing package.")
var concordance2 = BuildConcordance("Package testing provides support for automated testing of Go packages. It is intended to be used in concert with the go test command, which automates execution of any function of the form.")
got := Relation(concordance1, concordance2)
if got != 0.5464006945532413 {
t.Errorf("Relation expected 0.5464006945532413 but got %v", got)
}
}
func BenchmarkRelation(b *testing.B) {
var concordance1 = BuildConcordance("Go has a lightweight test framework composed of the go test command and the testing package.")
var concordance2 = BuildConcordance("Package testing provides support for automated testing of Go packages. It is intended to be used in concert with the go test command, which automates execution of any function of the form.")
for i := 0; i < b.N; i++ {
Relation(concordance1, concordance2)
}
}