MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / primalityTestTestingHelper

Function primalityTestTestingHelper

math/prime/prime_test.go:13–31  ·  view source on GitHub ↗
(t *testing.T, name string, f primalityTest)

Source from the content-addressed store, hash-verified

11type primalityTest func(int64) bool
12
13func primalityTestTestingHelper(t *testing.T, name string, f primalityTest) {
14 arrayIndex := 0
15 for i := 1; i <= testLimit; i++ {
16 isPrime := i == primeList[arrayIndex]
17
18 testName := fmt.Sprintf("%s(%d)", name, i)
19 t.Run(testName, func(t *testing.T) {
20 result := f(int64(i))
21
22 if isPrime {
23 arrayIndex++
24 }
25
26 if result != isPrime {
27 t.Errorf("%d: %s function returned %v\n", i, name, result)
28 }
29 })
30 }
31}
32
33func primalityTestBenchmarkHelper(b *testing.B, f primalityTest) {
34 for i := 0; i < b.N; i++ {

Callers 4

TestTrialDivisionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected