(t *testing.T)
| 279 | } |
| 280 | } |
| 281 | func TestAppendDurations(t *testing.T) { |
| 282 | array := make([]time.Duration, len(internal.DurTestcases)) |
| 283 | want := make([]byte, 0) |
| 284 | want = append(want, 0x83) // start 3 element array |
| 285 | for i, tt := range internal.DurTestcases { |
| 286 | array[i] = tt.Duration |
| 287 | want = append(want, []byte(tt.FloatOut)...) |
| 288 | } |
| 289 | |
| 290 | got := enc.AppendDurations([]byte{}, array, time.Microsecond, "", false, -1) |
| 291 | if !bytes.Equal(got, want) { |
| 292 | t.Errorf("AppendDurations(%v)\ngot: 0x%s\nwant: 0x%s", |
| 293 | array, hex.EncodeToString(got), |
| 294 | hex.EncodeToString(want)) |
| 295 | } |
| 296 | |
| 297 | // now empty array case |
| 298 | array = make([]time.Duration, 0) |
| 299 | want = make([]byte, 0) |
| 300 | want = append(want, 0x9f) // start and end array |
| 301 | want = append(want, 0xff) // for empty array |
| 302 | got = enc.AppendDurations([]byte{}, array, time.Microsecond, "", false, -1) |
| 303 | if !bytes.Equal(got, want) { |
| 304 | t.Errorf("AppendDurations(%v)\ngot: 0x%s\nwant: 0x%s", |
| 305 | array, hex.EncodeToString(got), |
| 306 | hex.EncodeToString(want)) |
| 307 | } |
| 308 | |
| 309 | // now large array case |
| 310 | testtime := internal.DurTestcases[0].Duration |
| 311 | outbytes := internal.DurTestcases[0].FloatOut |
| 312 | array = make([]time.Duration, 24) |
| 313 | want = make([]byte, 0) |
| 314 | want = append(want, 0x98) // start a large array |
| 315 | want = append(want, 0x18) // of length 24 |
| 316 | for i := 0; i < len(array); i++ { |
| 317 | array[i] = testtime |
| 318 | want = append(want, []byte(outbytes)...) |
| 319 | } |
| 320 | got = enc.AppendDurations([]byte{}, array, time.Microsecond, "", false, -1) |
| 321 | if !bytes.Equal(got, want) { |
| 322 | t.Errorf("AppendDurations(%v)\ngot: 0x%s\nwant: 0x%s", |
| 323 | array, |
| 324 | hex.EncodeToString(got), |
| 325 | hex.EncodeToString(want)) |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | func BenchmarkAppendTime(b *testing.B) { |
| 330 | tests := map[string]string{ |
nothing calls this directly
no test coverage detected