func durationEqual(x, y time.Duration) bool {
	diff := x - y
	if diff < 0 {
		diff = -diff
	}
	return diff <= time.Microsecond
}
A similar function to the above because SinePacer.Pace has discrete
inputs and outputs but uses floats internally, and sometimes the
floating point imprecision leaks out :-(
package vegeta
import (
	"math"
	"strconv"
	"testing"
	"testing/quick"
	"time"
)
func TestConstantPacer(t *testing.T) {
	t.Parallel()
	for ti, tt := range []struct {
		freq    int
		per     time.Duration
		elapsed time.Duration
		hits    uint64
		wait    time.Duration
		stop    bool
	}{
		{1, time.Second, time.Second, 0, 0, false},
		{1, time.Second, 2 * time.Second, 0, 0, false},
		{1, time.Second, time.Second, 1, time.Second, false},
		{1, time.Second, time.Second, 2, 2 * time.Second, false},
		{1, time.Second, time.Second, 10, 10 * time.Second, false},
		{1, time.Second, 11 * time.Second, 10, 0, false},
		{2, time.Second, (49 * time.Second) / 10, 9, 100 * time.Millisecond, false},
		{0, time.Second, time.Second, 0, 0, false},
		{1, 0, time.Second, 0, 0, false},
		{0, 0, time.Second, 0, 0, false},
		{-1, time.Second, time.Second, 0, 0, true},
		{1, -time.Second, time.Second, 0, 0, true},
		{-1, -time.Second, time.Second, 0, 0, true},
		{1, time.Duration(math.MaxInt64) / 10, time.Duration(math.MaxInt64), 11, 0, true},
		{1, time.Hour, time.Duration(math.MaxInt64), 2562048, 0, true},
	} {
		cp := &ConstantPacer{Freq: tt.freq, Per: tt.per}
		wait, stop := cp.Pace(tt.elapsed, tt.hits)
		if wait != tt.wait || stop != tt.stop {
			t.Errorf("%d: %+v.Pace(%s, %d) = (%s, %t); want (%s, %t)",
				ti, cp, tt.elapsed, tt.hits, wait, stop, tt.wait, tt.stop)
		}
	}
}
func TestConstantPacer_Rate(t *testing.T) {
	t.Parallel()
	for _, tc := range []struct {
		freq int
		per  time.Duration
		rate float64
	}{{
		freq: 60,
		per:  time.Minute,
		rate: 1.0,
	}, {
		freq: 120,
		per:  time.Minute,
		rate: 2.0,
	}, {
		freq: 30,
		per:  time.Minute,
		rate: 0.5,
	}, {
		freq: 500,
		per:  time.Second,
		rate: 500.0,
	},
	} {
		cp := ConstantPacer{Freq: tc.freq, Per: tc.per}
		if have, want := cp.Rate(0), tc.rate; !floatEqual(have, want) {
			t.Errorf("%s.Rate(_): have %f, want %f", cp, have, want)
		}
	}
}
func floatEqual(x, y float64) bool {
	relMarg := 1e-6 * math.Min(math.Abs(x), math.Abs(y))
	return math.Abs(x-y) <= math.Max(1e-6, relMarg)
}