2021-06-22 13:00:29 +02:00
|
|
|
package bytecounter
|
2021-02-02 12:05:47 +01:00
|
|
|
|
2021-06-22 13:00:29 +02:00
|
|
|
import "testing"
|
2021-02-02 12:05:47 +01:00
|
|
|
|
2022-06-05 21:22:27 +02:00
|
|
|
func TestCounter(t *testing.T) {
|
2021-06-22 13:00:29 +02:00
|
|
|
counter := New()
|
2021-02-02 12:05:47 +01:00
|
|
|
counter.CountBytesReceived(16384)
|
|
|
|
counter.CountKibiBytesReceived(10)
|
|
|
|
counter.CountBytesSent(2048)
|
|
|
|
counter.CountKibiBytesSent(10)
|
|
|
|
if counter.BytesSent() != 12288 {
|
|
|
|
t.Fatal("invalid bytes sent")
|
|
|
|
}
|
|
|
|
if counter.BytesReceived() != 26624 {
|
|
|
|
t.Fatal("invalid bytes received")
|
|
|
|
}
|
|
|
|
if v := counter.KibiBytesSent(); v < 11.9 || v > 12.1 {
|
|
|
|
t.Fatal("invalid kibibytes sent")
|
|
|
|
}
|
|
|
|
if v := counter.KibiBytesReceived(); v < 25.9 || v > 26.1 {
|
|
|
|
t.Fatal("invalid kibibytes received")
|
|
|
|
}
|
|
|
|
}
|