-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathvector_test.go
43 lines (36 loc) · 1.25 KB
/
vector_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
// Copyright 2013 Matthew Fonda. All rights reserved.
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package simhash
import (
"testing"
)
func TestEmpty(t *testing.T) {
var empty Vector
v := Vectorize([]Feature{})
if v != empty {
t.Errorf("Expected empty vector for no features")
}
}
func TestVectorize(t *testing.T) {
features := []Feature{
NewFeature([]byte("test string")),
NewFeature([]byte("test thing")),
}
v := Vectorize(features)
expected := Vector{0, -2, 0, 0, -2, -2, -2, 0, 0, 0, -2, 0, 0, 0, -2, 0, -2, 0, 0, 0, 0, 0, 2, 2, 2, -2, 0, -2, 0, -2, 2, 0, 0, 2, 0, 2, -2, 0, 2, 0, 2, -2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 2, -2, -2, 2, -2, 0, 2, 0, 2, -2}
if v != expected {
t.Errorf("Vectorize failed to return expected result")
}
}
func TestVectorizeBytes(t *testing.T) {
features := [][]byte{
[]byte("test string"),
[]byte("test thing"),
}
v := VectorizeBytes(features)
expected := Vector{0, -2, 0, 0, -2, -2, -2, 0, 0, 0, -2, 0, 0, 0, -2, 0, -2, 0, 0, 0, 0, 0, 2, 2, 2, -2, 0, -2, 0, -2, 2, 0, 0, 2, 0, 2, -2, 0, 2, 0, 2, -2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 2, -2, -2, 2, -2, 0, 2, 0, 2, -2}
if v != expected {
t.Errorf("Vectorize failed to return expected result")
}
}