-
Notifications
You must be signed in to change notification settings - Fork 31
/
real_test.go
45 lines (41 loc) · 1.02 KB
/
real_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
package ber
import (
"math"
"testing"
)
var negativeZero = math.Copysign(0, -1)
func TestRealEncoding(t *testing.T) {
for _, value := range []float64{
0.15625,
-0.15625,
math.Inf(1),
math.Inf(-1),
math.NaN(),
negativeZero,
0.0,
} {
enc := encodeFloat(value)
dec, err := ParseReal(enc)
if err != nil {
t.Errorf("Failed to decode %f (%v): %s", value, enc, err)
}
if dec != value {
if !(math.IsNaN(dec) && math.IsNaN(value)) {
t.Errorf("decoded value != orig: %f <=> %f", value, dec)
}
}
}
}
func TestRealBinaryDecodingTC10(t *testing.T) {
// This is the content of tests/tc10.ber. The orignal test suite would emit a
// "Needlessly long format" warning which we don't care about.
dec, err := DecodePacketErr([]byte{0x09, 0x07, 0x83, 0x04, 0xff, 0xff, 0xff, 0xfb, 0x05})
var expected float64 = 0.156250
if err != nil {
t.Errorf("Failed to decode: %s", err)
}
result := dec.Value.(float64)
if result != expected {
t.Errorf("invalid value parsed in tc10: %f <=> %f", result, expected)
}
}