MCPcopy
hub / github.com/tinylib/msgp / TestWriteFloat32

Function TestWriteFloat32

msgp/write_test.go:264–286  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

262}
263
264func TestWriteFloat32(t *testing.T) {
265 var buf bytes.Buffer
266 wr := NewWriter(&buf)
267
268 for range 10000 {
269 buf.Reset()
270 flt := (rand.Float32() - 0.5) * math.MaxFloat32
271 err := wr.WriteFloat32(flt)
272 if err != nil {
273 t.Errorf("Error with %f: %s", flt, err)
274 }
275 err = wr.Flush()
276 if err != nil {
277 t.Fatal(err)
278 }
279
280 bts := buf.Bytes()
281
282 if bts[0] != mfloat32 {
283 t.Errorf("Leading byte was %x and not %x", bts[0], mfloat64)
284 }
285 }
286}
287
288func BenchmarkWriteFloat32(b *testing.B) {
289 f := rand.Float32()

Callers

nothing calls this directly

Calls 4

WriteFloat32Method · 0.95
FlushMethod · 0.95
NewWriterFunction · 0.85
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…