package primes_test
import (
"primes"
"testing"
"github.com/matryer/is"
)
var primeCases = []struct {
input int
expected []int
}{
{0, []int{}},
{1, []int{}},
{2, []int{2}},
{10, []int{2, 3, 5, 7}},
{100, []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}},
}
var sieveCases = []struct {
input int
expected []bool
}{
// every non-prime is true, 0-th and 1-st is false, should be true
{0, []bool{false}},
{1, []bool{false, false}},
{2, []bool{false, false, false}},
{100, []bool{false, false, false, false, true, false, true, false, true, true, true, false, true, false, true, true, true, false, true, false, true, true, true, false, true, true, true, true, true, false, true, false, true, true, true, true, true, false, true, true, true, false, true, false, true, true, true, false, true, true, true, true, true, false, true, true, true, true, true, false, true, false, true, true, true, true, true, false, true, true, true, false, true, false, true, true, true, true, true, false, true, true, true, false, true, true, true, true, true, false, true, true, true, true, true, true, true, false, true, true, true}},
}
func TestPrimes(t *testing.T) {
is := is.New(t)
for _, tc := range primeCases {
is.Equal(tc.expected, primes.Primes(tc.input))
}
}
func TestSieve(t *testing.T) {
is := is.New(t)
for _, tc := range sieveCases {
is.Equal(tc.expected, primes.JustSieve(tc.input))
}
}
func BenchmarkPrimes(b *testing.B) {
for i := 0; i < b.N; i++ {
primes.Primes(1e6)
}
}
func BenchmarkSieve(b *testing.B) {
for i := 0; i < b.N; i++ {
primes.JustSieve(1e6)
}
}