-
Notifications
You must be signed in to change notification settings - Fork 1
/
array_property_test.go
76 lines (66 loc) · 2 KB
/
array_property_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
package main
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSaveAndLoadInt32SliceProperty(t *testing.T) {
// ****************************** ARRANGE *********************************
data := []int32{
666,
420,
69,
2020,
}
reader := FBXReader{}
buffer := new(bytes.Buffer)
prop := NewArrayPropertyInt32Slice(data)
// ******************************** ACT ***********************************
writeErr := prop.Write(buffer)
propType, typeErr := buffer.ReadByte()
propFromBuffer := reader.readArray(buffer, 4)
// ******************************* ASSERT *********************************
assert.NoError(t, writeErr)
assert.NoError(t, typeErr)
assert.NoError(t, reader.Error)
assert.Equal(t, byte('i'), propType)
if assert.NotNil(t, propFromBuffer) {
dataBack := propFromBuffer.AsInt32Slice()
if assert.Len(t, dataBack, len(data)) {
assert.Equal(t, data[0], dataBack[0])
assert.Equal(t, data[1], dataBack[1])
assert.Equal(t, data[2], dataBack[2])
assert.Equal(t, data[3], dataBack[3])
}
}
}
func TestSaveAndLoadFloat64SliceProperty(t *testing.T) {
// ****************************** ARRANGE *********************************
data := []float64{
666,
420,
69,
2020,
}
reader := FBXReader{}
buffer := new(bytes.Buffer)
prop := NewArrayPropertyFloat64Slice(data)
// ******************************** ACT ***********************************
writeErr := prop.Write(buffer)
propType, typeErr := buffer.ReadByte()
propFromBuffer := reader.readArray(buffer, 8)
// ******************************* ASSERT *********************************
assert.NoError(t, writeErr)
assert.NoError(t, typeErr)
assert.NoError(t, reader.Error)
assert.Equal(t, byte('d'), propType)
if assert.NotNil(t, propFromBuffer) {
dataBack := propFromBuffer.AsFloat64Slice()
if assert.Len(t, dataBack, len(data)) {
assert.Equal(t, data[0], dataBack[0])
assert.Equal(t, data[1], dataBack[1])
assert.Equal(t, data[2], dataBack[2])
assert.Equal(t, data[3], dataBack[3])
}
}
}