forked from mpraski/clusters
-
Notifications
You must be signed in to change notification settings - Fork 1
/
csv_importer_test.go
80 lines (65 loc) · 1.23 KB
/
csv_importer_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
package clusters
import (
"math"
"testing"
)
const TOLERANCE = 0.000001
func TestImportedLoadDataOfCorrectLengh(t *testing.T) {
var (
f = "data/test.csv"
i = CsvImporter()
s = 3
)
d, e := i.Import(f, 0, 2)
if e != nil {
t.Errorf("Error importing data: %s\n", e.Error())
}
if s != len(d) {
t.Errorf("Imported data size mismatch: %d vs %d\n", s, len(d))
}
}
func TestImportedLoadCorrectData(t *testing.T) {
var (
f = "data/test.csv"
i = CsvImporter()
s = [][]float64{
{0.1, 0.2, 0.3},
{0.4, 0.5, 0.6},
{0.7, 0.8, 0.9},
}
)
d, e := i.Import(f, 0, 2)
if e != nil {
t.Errorf("Error importing data: %s\n", e.Error())
}
if !fsliceEqual(d, s) {
t.Errorf("Imported data mismatch: %v vs %v\n", d, s)
}
}
func fsliceEqual(a, b [][]float64) bool {
if len(a) != len(b) {
return false
}
for i := 0; i < len(a); i++ {
if len(a[i]) != len(b[i]) {
return false
}
for j := 0; j < len(a[i]); j++ {
if d := math.Abs(a[i][j] - b[i][j]); d > TOLERANCE {
return false
}
}
}
return true
}
func BenchmarkImport(b *testing.B) {
var (
f = "data/bus-stops.csv"
i = CsvImporter()
)
b.ResetTimer()
_, e := i.Import(f, 4, 5)
if e != nil {
b.Errorf("Error importing data: %s\n", e.Error())
}
}