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

Function TestReadWriterDuration

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

Source from the content-addressed store, hash-verified

218}
219
220func TestReadWriterDuration(t *testing.T) {
221 var buf bytes.Buffer
222 wr := NewWriter(&buf)
223
224 for range 10000 {
225 buf.Reset()
226 dur := time.Duration(rand.Int63())
227 err := wr.WriteDuration(dur)
228 if err != nil {
229 t.Errorf("Error with %v: %s", dur, err)
230 }
231 err = wr.Flush()
232 if err != nil {
233 t.Fatal(err)
234 }
235
236 bts := buf.Bytes()
237
238 if bts[0] != mint64 {
239 t.Errorf("Leading byte was %x and not %x", bts[0], mint64)
240 }
241
242 wr := NewReader(&buf)
243 d, err := wr.ReadDuration()
244 if err != nil {
245 t.Errorf("Error reading duration: %v", err)
246 }
247 if d != dur {
248 t.Errorf("Got duration %v, want %v", d, dur)
249 }
250 }
251}
252
253func BenchmarkWriteFloat64(b *testing.B) {
254 f := rand.Float64()

Callers

nothing calls this directly

Calls 6

ReadDurationMethod · 0.95
NewWriterFunction · 0.85
NewReaderFunction · 0.85
WriteDurationMethod · 0.80
FlushMethod · 0.80
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…