-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimes_test.go
50 lines (42 loc) · 1007 Bytes
/
primes_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package primality
import (
"math/big"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPrimalityTest_AKS(t *testing.T) {
primes := make([]int, 0, 168)
for i := 1; i <= 1000; i++ {
if aks := AKS(i); aks {
primes = append(primes, i)
}
}
require.Len(t, primes, 168)
}
func TestPrimalityTest_MillerRabin(t *testing.T) {
primes := make([]int, 0, 168)
for i := 1; i <= 1000; i++ {
if mr := MillerRabin(big.NewInt(int64(i)), 25, true); mr {
primes = append(primes, i)
}
}
require.Len(t, primes, 168)
}
func TestPrimalityTests_Equal(t *testing.T) {
primes1 := make([]int, 0, 168)
for i := 1; i <= 1000; i++ {
if mr := MillerRabin(big.NewInt(int64(i)), 25, true); mr {
primes1 = append(primes1, i)
}
}
assert.Len(t, primes1, 168)
primes2 := make([]int, 0, 168)
for i := 1; i <= 1000; i++ {
if aks := AKS(i); aks {
primes2 = append(primes2, i)
}
}
assert.Len(t, primes2, 168)
require.Equal(t, primes1, primes2)
}