diff --git a/internal/rate/rate_test.go b/internal/rate/rate_test.go index 5c5523e0..36ce0e08 100644 --- a/internal/rate/rate_test.go +++ b/internal/rate/rate_test.go @@ -13,7 +13,7 @@ const ( defaultBufSize = 4096 ) -func getExpectCost(dataSize, bytesPerSecond int64) (expectCost time.Duration, max time.Duration, min time.Duration) { +func getExpectCost(dataSize, bytesPerSecond int64) (expectCost time.Duration, maxCost time.Duration, minCost time.Duration) { expectCost = time.Second * time.Duration(dataSize) / time.Duration(bytesPerSecond) if bytesPerSecond <= defaultBufSize && dataSize <= defaultBufSize { @@ -21,19 +21,19 @@ func getExpectCost(dataSize, bytesPerSecond int64) (expectCost time.Duration, ma } else if bytesPerSecond > defaultBufSize && dataSize <= defaultBufSize { expectCost = 0 } - max = expectCost * (100 + deviation) / 100 - min = expectCost * (100 - deviation) / 100 + maxCost = expectCost * (100 + deviation) / 100 + minCost = expectCost * (100 - deviation) / 100 // the minimum deviation time is 1 second - if expectCost-min < time.Second { - min = expectCost - time.Second + if expectCost-minCost < time.Second { + minCost = expectCost - time.Second } - if min < 0 { - min = 0 + if minCost < 0 { + minCost = 0 } - if max <= 0 { - max = time.Second * deviation / 100 + if maxCost <= 0 { + maxCost = time.Second * deviation / 100 } - return expectCost, max, min + return expectCost, maxCost, minCost } type writer struct { diff --git a/internal/rate/reader_at_test.go b/internal/rate/reader_at_test.go index aac48d52..086452a1 100644 --- a/internal/rate/reader_at_test.go +++ b/internal/rate/reader_at_test.go @@ -57,16 +57,16 @@ func TestReadAt(t *testing.T) { return } - expectCost, max, min := getExpectCost(tc.dataSize, tc.bytesPerSecond) + expectCost, maxCost, minCost := getExpectCost(tc.dataSize, tc.bytesPerSecond) actualCost := end.Sub(start) - if actualCost >= min && actualCost <= max { + if actualCost >= minCost && actualCost <= maxCost { rate := 0.0 if actualCost > 0 { rate = float64(tc.dataSize) / actualCost.Seconds() } t.Logf("[%s] dataSize=%d bytesPerSecond=%d cost=%s, rate=%.2f bytes/sec", tc.name, tc.dataSize, tc.bytesPerSecond, actualCost, rate) } else { - t.Errorf("[%s] dataSize=%d bytesPerSecond=%d expect cost=%s min=%s max=%s, but actual cost=%s", tc.name, tc.dataSize, tc.bytesPerSecond, expectCost, min, max, actualCost) + t.Errorf("[%s] dataSize=%d bytesPerSecond=%d expect cost=%s min=%s max=%s, but actual cost=%s", tc.name, tc.dataSize, tc.bytesPerSecond, expectCost, minCost, maxCost, actualCost) } }) } diff --git a/internal/rate/reader_test.go b/internal/rate/reader_test.go index 52ad3b98..8707f22a 100644 --- a/internal/rate/reader_test.go +++ b/internal/rate/reader_test.go @@ -43,16 +43,16 @@ func TestReader(t *testing.T) { return } - expectCost, max, min := getExpectCost(tc.dataSize, tc.bytesPerSecond) + expectCost, maxCost, minCost := getExpectCost(tc.dataSize, tc.bytesPerSecond) actualCost := end.Sub(start) - if actualCost >= min && actualCost <= max { + if actualCost >= minCost && actualCost <= maxCost { rate := 0.0 if actualCost > 0 { rate = float64(tc.dataSize) / actualCost.Seconds() } t.Logf("[%s] dataSize=%d bytesPerSecond=%d cost=%s, rate=%.2f bytes/sec", tc.name, tc.dataSize, tc.bytesPerSecond, actualCost, rate) } else { - t.Errorf("[%s] dataSize=%d bytesPerSecond=%d expect cost=%s min=%s max=%s, but actual cost=%s", tc.name, tc.dataSize, tc.bytesPerSecond, expectCost, min, max, actualCost) + t.Errorf("[%s] dataSize=%d bytesPerSecond=%d expect cost=%s min=%s max=%s, but actual cost=%s", tc.name, tc.dataSize, tc.bytesPerSecond, expectCost, minCost, maxCost, actualCost) } }) }