forked from ryanbressler/CloudForest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
56 lines (43 loc) · 1.19 KB
/
utils_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
package CloudForest
import (
"encoding/csv"
"io"
"testing"
)
func TestSpareseCounter(t *testing.T) {
sc := new(SparseCounter)
sc.Add(1, 1, 1)
pipereader, pipewriter := io.Pipe()
go func() {
sc.WriteTsv(pipewriter)
pipewriter.Close()
}()
tsv := csv.NewReader(pipereader)
tsv.Comma = '\t'
records, err := tsv.Read()
if err != nil {
t.Errorf("Error reading tsv output by SpareCOunter %v", err)
}
if l := len(records); l != 3 {
t.Errorf("Sparse counter output tsv with %v records", l)
}
for i, r := range records {
if r != "1" {
t.Errorf("Spares counter out put wrong value %v or field %v", r, i)
}
}
}
func TestParseAsIntOrFractionOfTotal(t *testing.T) {
if p := ParseAsIntOrFractionOfTotal("70", 100); p != 70 {
t.Errorf("ParseAsIntOrFractionOfTotal parsed 70 as %v", p)
}
if p := ParseAsIntOrFractionOfTotal(".7", 100); p != 70 {
t.Errorf("ParseAsIntOrFractionOfTotal parsed .7 as %v / 100", p)
}
if p := ParseAsIntOrFractionOfTotal("blah.7", 100); p != 0 {
t.Errorf("ParseAsIntOrFractionOfTotal parsed blah.7 as %v / 100", p)
}
if p := ParseAsIntOrFractionOfTotal("blah", 100); p != 0 {
t.Errorf("ParseAsIntOrFractionOfTotal parsed blah as %v / 100", p)
}
}