Skip to content

Commit

Permalink
Replace more custom min/max functions in favor of stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
joanlopez committed Aug 28, 2024
1 parent 9a1597c commit 44c779f
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 88 deletions.
15 changes: 3 additions & 12 deletions cmd/tests/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"slices"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -1434,16 +1435,6 @@ func sum(vals []float64) (sum float64) {
return sum
}

func maxFloat64(vals []float64) float64 {
result := vals[0]
for _, val := range vals {
if result < val {
result = val
}
}
return result
}

func TestActiveVUsCount(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1499,8 +1490,8 @@ func TestActiveVUsCount(t *testing.T) {
jsonResults, err := fsext.ReadFile(ts.FS, "results.json")
require.NoError(t, err)
// t.Log(string(jsonResults))
assert.Equal(t, float64(10), maxFloat64(getSampleValues(t, jsonResults, "vus_max", nil)))
assert.Equal(t, float64(10), maxFloat64(getSampleValues(t, jsonResults, "vus", nil)))
assert.Equal(t, float64(10), slices.Max(getSampleValues(t, jsonResults, "vus_max", nil)))
assert.Equal(t, float64(10), slices.Max(getSampleValues(t, jsonResults, "vus", nil)))
assert.Equal(t, float64(0), sum(getSampleValues(t, jsonResults, "iterations", nil)))

logEntries := ts.LoggerHook.Drain()
Expand Down
4 changes: 2 additions & 2 deletions cmd/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ func showProgress(ctx context.Context, gs *state.GlobalState, pbs []*pb.Progress
var leftLen int64
for _, pb := range pbs {
l := pb.Left()
leftLen = lib.Max(int64(len(l)), leftLen)
leftLen = max(int64(len(l)), leftLen)
}
// Limit to maximum left text length
maxLeft := int(lib.Min(leftLen, maxLeftLength))
maxLeft := int(min(leftLen, maxLeftLength))

var progressBarsLastRenderLock sync.Mutex
var progressBarsLastRender []byte
Expand Down
4 changes: 1 addition & 3 deletions js/modules/k6/experimental/fs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"io"
"path/filepath"
"sync/atomic"

"go.k6.io/k6/lib"
)

// file is an abstraction for interacting with files.
Expand Down Expand Up @@ -55,7 +53,7 @@ func (f *file) Read(into []byte) (n int, err error) {

// Calculate the effective new offset
targetOffset := currentOffset + int64(len(into))
newOffset := lib.Min(targetOffset, fileSize)
newOffset := min(targetOffset, fileSize)

// Read the data into the provided slice, and update
// the offset accordingly
Expand Down
19 changes: 0 additions & 19 deletions lib/util.go

This file was deleted.

52 changes: 0 additions & 52 deletions lib/util_test.go

This file was deleted.

0 comments on commit 44c779f

Please sign in to comment.