MCPcopy Create free account
hub / github.com/apache/fory / TestFloat16StructField

Function TestFloat16StructField

go/fory/struct_test.go:634–665  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

632}
633
634func TestFloat16StructField(t *testing.T) {
635 type StructWithFloat16 struct {
636 F16 float16.Float16
637 SliceF16 []float16.Float16
638 ArrayF16 [3]float16.Float16
639 }
640
641 f := New(WithXlang(true), WithCompatible(false))
642 require.NoError(t, f.RegisterStruct(StructWithFloat16{}, 3001))
643
644 val := &StructWithFloat16{
645 F16: float16.Float16FromFloat32(1.5),
646 SliceF16: []float16.Float16{float16.Float16FromFloat32(1.0), float16.Float16FromFloat32(2.5)},
647 ArrayF16: [3]float16.Float16{float16.Zero, float16.One, float16.NegZero},
648 }
649
650 data, err := f.Serialize(val)
651 require.NoError(t, err)
652
653 // Create new instance
654 res := &StructWithFloat16{}
655 err = testDeserialize(t, f, data, res)
656 require.NoError(t, err)
657
658 // Verify
659 require.Equal(t, val.F16, res.F16)
660 require.Equal(t, val.SliceF16, res.SliceF16)
661 require.Equal(t, val.ArrayF16, res.ArrayF16)
662
663 // Specific value check
664 require.Equal(t, float32(1.5), res.F16.Float32())
665}
666
667// TestVarintFastPathTightBuffer exercises the varint fast-path with a single uint32 field.
668// Serializing a value requiring 5 varint bytes exercises the 8-byte bulk write.

Callers

nothing calls this directly

Calls 9

WithXlangFunction · 0.85
WithCompatibleFunction · 0.85
testDeserializeFunction · 0.85
NewFunction · 0.70
float32Function · 0.50
RegisterStructMethod · 0.45
SerializeMethod · 0.45
EqualMethod · 0.45
Float32Method · 0.45

Tested by

no test coverage detected