MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestComputePingOffset

Function TestComputePingOffset

pkg/crypto/ping_slot_test.go:28–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestComputePingOffset(t *testing.T) {
29 for _, tc := range []struct {
30 BeaconTime uint32
31 DevAddr types.DevAddr
32 PingPeriod uint16
33
34 ExpectedPingOffset uint16
35 ErrorAssertion func(t *testing.T, err error) bool
36 }{
37 {
38 ErrorAssertion: func(t *testing.T, err error) bool {
39 return assertions.New(t).So(errors.IsInvalidArgument(err), should.BeTrue)
40 },
41 },
42 {
43 PingPeriod: 31,
44 ErrorAssertion: func(t *testing.T, err error) bool {
45 return assertions.New(t).So(errors.IsInvalidArgument(err), should.BeTrue)
46 },
47 },
48 {
49 PingPeriod: 4097,
50 ErrorAssertion: func(t *testing.T, err error) bool {
51 return assertions.New(t).So(errors.IsInvalidArgument(err), should.BeTrue)
52 },
53 },
54 {
55 PingPeriod: 32,
56 ExpectedPingOffset: 6,
57 ErrorAssertion: func(t *testing.T, err error) bool {
58 return assertions.New(t).So(err, should.BeNil)
59 },
60 },
61 {
62 BeaconTime: 0xff42,
63 DevAddr: types.DevAddr{0x00, 0x42, 0x00, 0xff},
64 PingPeriod: 4096,
65 ExpectedPingOffset: 3994,
66 ErrorAssertion: func(t *testing.T, err error) bool {
67 return assertions.New(t).So(err, should.BeNil)
68 },
69 },
70 } {
71 t.Run(fmt.Sprintf("beacon_time(%d)/dev_addr(%s)/ping_period(%d)", tc.BeaconTime, tc.DevAddr, tc.PingPeriod), func(t *testing.T) {
72 a := assertions.New(t)
73 p, err := ComputePingOffset(tc.BeaconTime, tc.DevAddr, tc.PingPeriod)
74 a.So(p, should.Equal, tc.ExpectedPingOffset)
75 a.So(tc.ErrorAssertion(t, err), should.BeTrue)
76 })
77 }
78}

Callers

nothing calls this directly

Calls 4

IsInvalidArgumentFunction · 0.92
ComputePingOffsetFunction · 0.85
NewMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected