MCPcopy Create free account
hub / github.com/chronoxor/FastBinaryEncoding / VerifyDecimal

Function VerifyDecimal

projects/Go/tests/decimal_test.go:8–37  ·  view source on GitHub ↗
(t *testing.T, low uint32, mid uint32, high uint32, negative bool, scale uint32, value string)

Source from the content-addressed store, hash-verified

6import "../proto/fbe"
7
8func VerifyDecimal(t *testing.T, low uint32, mid uint32, high uint32, negative bool, scale uint32, value string) {
9 base, _ := decimal.NewFromString(value)
10
11 flags := uint32(scale << 16)
12 if negative {
13 flags |= 0x80000000
14 }
15
16 buffer := make([]byte, 16)
17 fbe.WriteUInt32(buffer, 0, low)
18 fbe.WriteUInt32(buffer, 4, mid)
19 fbe.WriteUInt32(buffer, 8, high)
20 fbe.WriteUInt32(buffer, 12, flags)
21
22 readBuffer := fbe.NewAttached(buffer)
23
24 model := fbe.NewFieldModelDecimal(readBuffer, 0)
25 value1, _ := model.Get()
26 _ = model.Set(value1)
27 value2, _ := model.Get()
28
29 assert.True(t, value1.Equal(base) && value2.Equal(base), "Invalid decimal serialization!")
30
31 finalModel := fbe.NewFinalModelDecimal(readBuffer, 0)
32 value3, _, _ := finalModel.Get()
33 _, _ = finalModel.Set(value3)
34 value4, _, _ := finalModel.Get()
35
36 assert.True(t, value3.Equal(base) && value4.Equal(base), "Invalid decimal final serialization!")
37}
38
39func TestDecimal(test *testing.T) {
40 // FBE decimal exponent ranging from 0 to 28

Callers 2

TestDecimalFunction · 0.70
DecimalTestsMethod · 0.50

Calls 4

GetMethod · 0.95
SetMethod · 0.95
GetMethod · 0.95
SetMethod · 0.95

Tested by

no test coverage detected