-
Notifications
You must be signed in to change notification settings - Fork 2
/
gob_test.go
63 lines (46 loc) · 1.25 KB
/
gob_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
package psqr_test
import (
"testing"
"github.com/narqo/psqr"
)
func TestQuantileMarshalling(t *testing.T) {
quant := psqr.NewQuantile(0.5)
for i := 0; i < 1000; i++ {
quant.Append(float64(i))
}
before := quant.Value()
marshalled, err := quant.GobEncode()
if err != nil {
t.Errorf("unexpected encoding error: %s", err)
}
if err := quant.GobDecode(marshalled); err != nil {
t.Errorf("unexpected decoding error: %s", err)
}
after := quant.Value()
if before != after {
t.Errorf("encoded/decoded values differ: expected %f != got %f", before, after)
}
}
func TestQuantile_EncodingDecodingAndChanging(t *testing.T) {
quant := psqr.NewQuantile(0.5)
for i := 0; i < 1000; i++ {
quant.Append(float64(i))
}
encoded, err := quant.GobEncode()
if err != nil {
t.Errorf("unexpected encoding error: %s", err)
}
decoded := &psqr.Quantile{}
if err := decoded.GobDecode(encoded); err != nil {
t.Errorf("unexpected decoding error: %s", err)
}
for i := 0; i < 1000; i++ {
quant.Append(float64(i))
decoded.Append(float64(i))
}
origAfter := quant.Value()
decodedAfter := decoded.Value()
if origAfter != decodedAfter {
t.Errorf("encoded/decoded value did not keep internal representation: expected %f != got %f", origAfter, decodedAfter)
}
}