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
|
package lora
import "testing"
// TestGetSignalQuality tests the GetSignalQuality function with different RSSI and SNR values.
func TestGetSignalQuality(t *testing.T) {
tests := []struct {
rssi float64
snr float64
expected SignalQuality
}{
{-115, -7, SignalQualityGood},
{-120, -10, SignalQualityFair},
{-130, -20, SignalQualityBad},
}
for _, test := range tests {
actual := GetSignalQuality(test.rssi, test.snr)
if actual != test.expected {
t.Errorf("GetSignalQuality(%v, %v) = %v; want %v", test.rssi, test.snr, actual, test.expected)
}
}
}
// TestGetDiagnosticNotes tests the GetDiagnosticNotes function with different RSSI and SNR values.
func TestGetDiagnosticNotes(t *testing.T) {
tests := []struct {
rssi float64
snr float64
expected string
}{
{-115, -7, "RF level is optimal to get a good reception reliability."},
{-126, -15, "RF level is not optimal but must be sufficient. Try to improve your device position if possible. You will have to monitor the stability of the RF level."},
{-130, -20, "NOISY environment. Try to put device out of electromagnetic sources."},
}
for _, test := range tests {
actual := GetDiagnosticNotes(test.rssi, test.snr)
if actual != test.expected {
t.Errorf("GetDiagnosticNotes(%v, %v) = %v; want %v", test.rssi, test.snr, actual, test.expected)
}
}
}
|