forked from quickfixgo/quickfix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_float_test.go
More file actions
48 lines (42 loc) · 900 Bytes
/
fix_float_test.go
File metadata and controls
48 lines (42 loc) · 900 Bytes
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
package quickfix
import (
"bytes"
"testing"
)
func TestFloatWrite(t *testing.T) {
var tests = []struct {
field FIXFloat
val []byte
}{
{FIXFloat(5.0), []byte("5")},
}
for _, test := range tests {
b := test.field.Write()
if !bytes.Equal(b, test.val) {
t.Errorf("got %v; want %v", b, test.val)
}
}
}
func TestFloatRead(t *testing.T) {
var tests = []struct {
bytes []byte
value float64
expectError bool
}{
{[]byte("15"), 15.0, false},
{[]byte("blah"), 0.0, true},
{[]byte("+200.00"), 0.0, true},
}
for _, test := range tests {
var field FIXFloat
if err := field.Read(test.bytes); err != nil {
if !test.expectError {
t.Errorf("UnExpected '%v'", err)
}
} else if test.expectError {
t.Errorf("Expected error for %v", test.bytes)
} else if float64(field) != test.value {
t.Errorf("got %v want %v", field, test.value)
}
}
}