forked from schweikert/fping-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
measurement_test.go
100 lines (91 loc) · 2.95 KB
/
measurement_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import "fmt"
import "strconv"
import "testing"
func TestParseMeasurements(t *testing.T) {
{
testInput := ""
_, err := ParseMeasurements(testInput)
if err == nil {
t.Errorf("ParseMeasurements(\"%s\") failed, didn't get an error.", testInput)
} else if _, ok := err.(*strconv.NumError); !ok {
t.Errorf("ParseMeasurements(\"%s\") failed, expected error: strconv.NumError, got %v", testInput, err)
}
}
{
testInput := "- 30.23 -"
testOutput := "30.230 - -"
m, err := ParseMeasurements(testInput)
if err != nil {
t.Errorf("ParseMeasurements(\"%s\") failed, got error: %v", testInput, err)
}
if m.String() != testOutput {
t.Errorf("ParseMeasurements(\"%s\") failed, expected %v, got %v", testInput, testOutput, m.String())
}
}
{
testInput := "40 30.23 35.0001"
testOutput := "30.230 35.000 40.000"
m, err := ParseMeasurements(testInput)
if err != nil {
t.Errorf("ParseMeasurements(\"%s\") failed, got error: %v", testInput, err)
}
if m.String() != testOutput {
t.Errorf("ParseMeasurements(\"%s\") failed, expected %v, got %v", testInput, testOutput, m.String())
}
}
}
func TestLen(t *testing.T) {
testInput := "50.2 30.1 - 40"
m, err := ParseMeasurements(testInput)
if err != nil {
t.Errorf("ParseMeasurements(\"%s\") failed, got error: %v", testInput, err)
}
if m.Len() != 4 {
t.Errorf("ParseMeasurements(\"%s\").Len() failed, expected: 4, got: %d", testInput, m.Len())
}
}
func TestGetSentCount(t *testing.T) {
testInput := "50.2 30.1 - 40"
testOutput := 4
m, err := ParseMeasurements(testInput)
if err != nil {
t.Errorf("ParseMeasurements(\"%s\") failed, got error: %v", testInput, err)
}
if m.GetSentCount() != testOutput {
t.Errorf("ParseMeasurements(\"%s\").GetSentCount() failed, expected: %d, got: %d", testInput, testOutput, m.Len())
}
}
func TestGetLostCount(t *testing.T) {
testInput := "50.2 30.1 - 40"
testOutput := 1
m, err := ParseMeasurements(testInput)
if err != nil {
t.Errorf("ParseMeasurements(\"%s\") failed, got error: %v", testInput, err)
}
if m.GetLostCount() != testOutput {
t.Errorf("ParseMeasurements(\"%s\").GetLostCount() failed, expected: %d, got: %d", testInput, testOutput, m.Len())
}
}
func TestGetRTTSum(t *testing.T) {
testInput := "50.2 30.1 - 40"
testOutput := "0.120"
m, err := ParseMeasurements(testInput)
if err != nil {
t.Errorf("ParseMeasurements(\"%s\") failed, got error: %v", testInput, err)
}
if fmt.Sprintf("%.3f", m.GetRTTSum()) != testOutput {
t.Errorf("ParseMeasurements(\"%s\").GetRTTSum() failed, expected: %s, got: %.3f", testInput, testOutput, m.GetRTTSum())
}
}
func TestGetRTTCount(t *testing.T) {
testInput := "50.2 30.1 - 40"
testOutput := 3
m, err := ParseMeasurements(testInput)
if err != nil {
t.Errorf("ParseMeasurements(\"%s\") failed, got error: %v", testInput, err)
}
if m.GetRTTCount() != testOutput {
t.Errorf("ParseMeasurements(\"%s\").GetRTTCount() failed, expected: %d, got: %d", testInput, testOutput, m.GetRTTCount())
}
}