forked from google/gopacket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_test.go
73 lines (70 loc) · 1.21 KB
/
time_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2019 The GoPacket Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree.
package gopacket
import (
"testing"
"time"
)
func TestToDuration(t *testing.T) {
for i, test := range []struct {
r TimestampResolution
d time.Duration
}{
{
TimestampResolutionMillisecond,
time.Millisecond,
},
{
TimestampResolutionMicrosecond,
time.Microsecond,
},
{
TimestampResolutionNanosecond,
time.Nanosecond,
},
{
TimestampResolutionNTP,
0, // this is not representable since it's ~0.233 nanoseconds
},
{
TimestampResolution{2, -16},
15258,
},
{
TimestampResolution{2, 1},
2 * time.Second,
},
{
TimestampResolution{10, 1},
10 * time.Second,
},
{
TimestampResolution{10, 0},
time.Second,
},
{
TimestampResolution{2, 0},
time.Second,
},
{
TimestampResolution{0, 0},
0,
},
{
TimestampResolution{3, 2},
9 * time.Second,
},
{
TimestampResolution{3, -2},
111111111,
},
} {
d := test.r.ToDuration()
if d != test.d {
t.Errorf("%d: resolution: %s want: %d got: %d", i, test.r, test.d, d)
}
}
}