Skip to content

Commit

Permalink
feat: add test covering the minimum number of tests, change frequency…
Browse files Browse the repository at this point in the history
… to every 4 hours
  • Loading branch information
phanyzewski committed Jul 23, 2023
1 parent 807fb0b commit 7804e05
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
33 changes: 31 additions & 2 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"time"

// xrand "golang.org/x/exp/rand"
"golang.org/x/exp/constraints"
log "golang.org/x/exp/slog"
"gonum.org/v1/gonum/stat/distuv"
)

// timePeriodMinutes is the desired interval between tests
// the default (fixed) configuration is one tests every six hours
const timePeriodMinutes = 6 * 60
// the default (fixed) configuration is one tests every four hours
const timePeriodMinutes = 4 * 60

// speedTestInterval takes advantage of a poisson distribution
// to generate pseudo random speed tests
Expand Down Expand Up @@ -39,3 +40,31 @@ func drain(c chan sendDataJob) {
}
}
}

func max[T constraints.Ordered](s []T) T {
if len(s) == 0 {
var zero T
return zero
}
m := s[0]
for _, v := range s {
if m < v {
m = v
}
}
return m
}

func min[T constraints.Ordered](s []T) T {
if len(s) == 0 {
var zero T
return zero
}
m := s[0]
for _, v := range s {
if m > v {
m = v
}
}
return m
}
17 changes: 2 additions & 15 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"testing"

"github.com/matryer/is"
"golang.org/x/exp/constraints"
)

func Test_SpeedTestFrequency(t *testing.T) {
is := is.New(t)
hours := 24
maxTests := 6
maxTests := 8

//
tf := func() int {
Expand All @@ -26,18 +25,6 @@ func Test_SpeedTestFrequency(t *testing.T) {

results := []int{tf(), tf(), tf(), tf(), tf(), tf(), tf(), tf(), tf()}
is.True(max(results) <= maxTests)
}
is.True(min(results) > maxTests/2)

func max[T constraints.Ordered](s []T) T {
if len(s) == 0 {
var zero T
return zero
}
m := s[0]
for _, v := range s {
if m < v {
m = v
}
}
return m
}

0 comments on commit 7804e05

Please sign in to comment.