Skip to content

Commit

Permalink
Avoid using the keywords min and max (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstmdev authored Dec 23, 2024
1 parent bd273c9 commit a6502b0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
20 changes: 10 additions & 10 deletions internal/rate/rate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ 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 {
expectCost = time.Second
} 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 {
Expand Down
6 changes: 3 additions & 3 deletions internal/rate/reader_at_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions internal/rate/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
Expand Down

0 comments on commit a6502b0

Please sign in to comment.