Skip to content

Commit d77956c

Browse files
committed
Sped up TestIsPrimeAgainstBaseline
1 parent e2d8638 commit d77956c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

benchmark_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ package primes_test
2424

2525
import (
2626
"math"
27+
"math/rand"
2728
"testing"
28-
"testing/quick"
2929

3030
"github.com/fxtlabs/primes"
3131
)
@@ -88,11 +88,16 @@ func TestIsPrimeAgainstBaseline(t *testing.T) {
8888
p := primes.IsPrime(n)
8989
q := baselineIsPrime(n)
9090
if p != q {
91-
t.Errorf("ISPrimeAgainstBaseline(%d) == %v, want %v", n, p, q)
91+
t.Errorf("IsPrimeAgainstBaseline(%d) == %v, want %v", n, p, q)
9292
}
9393
}
94-
if err := quick.CheckEqual(primes.IsPrime, baselineIsPrime, &quick.Config{MaxCount: 50}); err != nil {
95-
t.Error(err)
94+
for i := 0; i < 10000; i++ {
95+
n := rand.Intn(math.MaxInt32)
96+
p := primes.IsPrime(n)
97+
q := baselineIsPrime(n)
98+
if p != q {
99+
t.Errorf("IsPrimeAgainstBaseline(%d) == %v, want %v", n, p, q)
100+
}
96101
}
97102
}
98103

0 commit comments

Comments
 (0)