2016-07-14 01:19:03 +02:00
|
|
|
package data
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2016-12-22 03:14:51 +01:00
|
|
|
func TestFrequencyName(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
assert.Equal("11a", WirelessAirtime{Frequency: 5000}.FrequencyName())
|
|
|
|
assert.Equal("11g", WirelessAirtime{Frequency: 4999}.FrequencyName())
|
|
|
|
assert.Equal("11g", WirelessAirtime{Frequency: 2412}.FrequencyName())
|
|
|
|
}
|
|
|
|
|
2016-07-14 01:19:03 +02:00
|
|
|
func TestUtilization(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
t1 := &WirelessAirtime{
|
2017-01-20 22:27:44 +01:00
|
|
|
ActiveTime: 20,
|
2017-04-08 13:57:33 +02:00
|
|
|
BusyTime: 5,
|
2017-01-20 22:27:44 +01:00
|
|
|
TxTime: 5,
|
|
|
|
RxTime: 0,
|
2016-07-14 01:19:03 +02:00
|
|
|
}
|
|
|
|
t2 := &WirelessAirtime{
|
2017-01-20 22:27:44 +01:00
|
|
|
ActiveTime: 120,
|
2017-04-08 13:57:33 +02:00
|
|
|
BusyTime: 50,
|
2017-01-20 22:27:44 +01:00
|
|
|
TxTime: 25,
|
|
|
|
RxTime: 15,
|
2016-07-14 01:19:03 +02:00
|
|
|
}
|
|
|
|
|
2017-04-08 13:57:33 +02:00
|
|
|
t1.setUtilization(t1)
|
|
|
|
assert.NotZero(t1.ChanUtil)
|
|
|
|
assert.EqualValues(0, t2.ChanUtil)
|
|
|
|
assert.EqualValues(0, t2.RxUtil)
|
|
|
|
assert.EqualValues(0, t2.TxUtil)
|
2016-07-14 01:19:03 +02:00
|
|
|
|
2017-04-08 13:57:33 +02:00
|
|
|
t2.setUtilization(t1)
|
2016-07-14 01:19:03 +02:00
|
|
|
assert.NotZero(t2.ChanUtil)
|
2016-07-14 12:31:11 +02:00
|
|
|
assert.EqualValues(45, t2.ChanUtil)
|
2017-04-08 13:57:33 +02:00
|
|
|
assert.EqualValues(15, t2.RxUtil)
|
|
|
|
assert.EqualValues(20, t2.TxUtil)
|
2016-07-14 01:19:03 +02:00
|
|
|
}
|
2016-11-20 19:11:56 +01:00
|
|
|
|
2016-12-22 03:14:51 +01:00
|
|
|
func TestWirelessStatistics(t *testing.T) {
|
2016-11-20 19:11:56 +01:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
2017-04-08 13:57:33 +02:00
|
|
|
// This is the current value
|
2016-12-22 03:14:51 +01:00
|
|
|
stats := WirelessStatistics([]*WirelessAirtime{{
|
2017-04-08 13:57:33 +02:00
|
|
|
Frequency: 2400,
|
|
|
|
ActiveTime: 10,
|
|
|
|
BusyTime: 4,
|
|
|
|
RxTime: 3,
|
2016-12-22 03:14:51 +01:00
|
|
|
}})
|
|
|
|
|
2017-04-08 13:57:33 +02:00
|
|
|
// previous value: Different Frequency, should not change anything
|
2016-12-22 03:14:51 +01:00
|
|
|
stats.SetUtilization([]*WirelessAirtime{{
|
2017-04-08 13:57:33 +02:00
|
|
|
Frequency: 5000,
|
|
|
|
ActiveTime: 5,
|
|
|
|
RxTime: 1,
|
2016-12-22 03:14:51 +01:00
|
|
|
}})
|
2017-04-08 13:57:33 +02:00
|
|
|
assert.Zero(0, stats[0].ChanUtil)
|
|
|
|
assert.Zero(0, stats[0].RxUtil)
|
|
|
|
assert.Zero(0, stats[0].TxUtil)
|
2016-11-20 19:11:56 +01:00
|
|
|
|
2017-04-08 13:57:33 +02:00
|
|
|
// previous value: Same Frequency, should set the utilization
|
2016-12-22 03:14:51 +01:00
|
|
|
stats.SetUtilization([]*WirelessAirtime{{
|
2017-04-08 13:57:33 +02:00
|
|
|
Frequency: 2400,
|
|
|
|
ActiveTime: 5,
|
|
|
|
RxTime: 2,
|
|
|
|
BusyTime: 1,
|
2016-12-22 03:14:51 +01:00
|
|
|
}})
|
2017-04-08 13:57:33 +02:00
|
|
|
assert.EqualValues(60, stats[0].ChanUtil)
|
|
|
|
assert.EqualValues(20, stats[0].RxUtil)
|
|
|
|
assert.EqualValues(0, stats[0].TxUtil)
|
2016-11-20 19:11:56 +01:00
|
|
|
}
|