mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-21 06:11:18 +01:00
Add TestUnpackFloat().
This commit is contained in:
parent
7e31d487e0
commit
64fe90aabb
@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
"bytes"
|
||||
"reflect"
|
||||
"math"
|
||||
);
|
||||
|
||||
func equal(lhs reflect.Value, rhs reflect.Value) bool {
|
||||
@ -196,3 +197,22 @@ func TestUnpackInt(t *testing.T) {
|
||||
if retval.Interface() != v { t.Errorf("%u != %u", retval.Interface(), v) }
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnpackFloat(t *testing.T) {
|
||||
b := bytes.NewBuffer([]byte { 0xca, 0x3d, 0xcc, 0xcc, 0xcd, 0xca, 0x3e, 0x4c, 0xcc, 0xcd, 0xca, 0xbd, 0xcc, 0xcc, 0xcd, 0xca, 0xbe, 0x4c, 0xcc, 0xcd, 0xca, 0x7f, 0x80, 0x00, 0x00, 0xca, 0xff, 0x80, 0x00, 0x00, 0xca, 0xff, 0xc0, 0x00, 0x0, 0xcb, 0x3f, 0xb9, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a, 0xcb, 0x3f, 0xc9, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a, 0xcb, 0xbf, 0xb9, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a, 0xcb, 0xbf, 0xc9, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a, 0xcb, 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcb, 0xcb, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcb, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })
|
||||
for _, v := range [](interface{}) { float32(.1), float32(.2), float32(-.1), float32(-.2), float32(math.Inf(1)), float32(math.Inf(-1)), float32(math.NaN()), float64(.1), float64(.2), float64(-.1), float64(-.2) } {
|
||||
retval, _, e := Unpack(b)
|
||||
if e != nil { t.Error("err != nil") }
|
||||
isnan := false
|
||||
if _v, ok := v.(float64); ok {
|
||||
isnan = math.IsNaN(_v)
|
||||
} else if _v, ok := v.(float32); ok {
|
||||
isnan = math.IsNaN(float64(_v))
|
||||
}
|
||||
if isnan {
|
||||
if retval.Interface() == v { t.Errorf("[NaN] %u == %u", retval.Interface(), v) }
|
||||
} else {
|
||||
if retval.Interface() != v { t.Errorf("%u != %u", retval.Interface(), v) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user