-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraph_test.go
90 lines (74 loc) · 2.01 KB
/
graph_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
package graphblast
import (
"testing"
)
func TestRangeContains(t *testing.T) {
r := Range{Min: -1, Max: 1}
if !r.Contains(0) {
t.Error("contains failed for a number in range")
}
if !r.Contains(-1) {
t.Error("contains failed to be inclusive for min")
}
if !r.Contains(1) {
t.Error("contains failed to be inclusive for max")
}
if r.Contains(-1.1) {
t.Error("contains failed for a number less than min")
}
if r.Contains(1.1) {
t.Error("contains failed for a number greater than max")
}
}
func TestCountableParse(t *testing.T) {
c, err := Parse("0")
if c != 0 && err != nil {
t.Error("parse did not parse an integer")
}
c, err = Parse("-100e5")
if c != -100e5 && err != nil {
t.Error("parse did not parse an negative float")
}
c, err = Parse("3.1415926535")
if c != 3.1415926535 && err != nil {
t.Error("parse did not parse an negative float")
}
c, err = Parse("3.1415a")
if c != 0 || err == nil {
t.Error("parse did parsed an invalid number")
}
c, err = Parse("foo")
if c != 0 || err == nil {
t.Error("parse did parsed an invalid number")
}
c, err = Parse("")
if c != 0 || err == nil {
t.Error("parse did parsed an invalid number")
}
}
func TestCountableBucket(t *testing.T) {
if Countable(4).Bucket(1) != "4" {
t.Error("bucket failed on int for bucket of size 1")
}
if Countable(4.9).Bucket(1) != "4" {
t.Error("bucket failed on float for bucket of size 1")
}
if Countable(0.1).Bucket(1) != "0" {
t.Error("bucket failed on small float for bucket of size 1")
}
if Countable(-0.1).Bucket(1) != "-1" {
t.Error("bucket failed on negative float for bucket of size 1")
}
if Countable(4).Bucket(5) != "0" {
t.Error("bucket failed on int for bucket of size 5")
}
if Countable(4.9).Bucket(5) != "0" {
t.Error("bucket failed on float for bucket of size 5")
}
if Countable(0.1).Bucket(5) != "0" {
t.Error("bucket failed on small float for bucket of size 5")
}
if Countable(-0.1).Bucket(5) != "-5" {
t.Error("bucket failed on negative float for bucket of size 5")
}
}