package primes_test
import (
"primes/erastothenes"
"testing"
)
const benchNum = 10_001
func TestUnoptimized(t *testing.T) {
t.Parallel()
for _, tc := range TestCases {
t.Run(tc.description, func(t *testing.T) {
if tc.p != erastothenes.Nth("unoptimized", tc.n) {
t.FailNow()
}
})
}
}
func TestSkipEven(t *testing.T) {
t.Parallel()
for _, tc := range TestCases {
t.Run(tc.description, func(t *testing.T) {
if tc.p != erastothenes.Nth("skipeven", tc.n) {
t.FailNow()
}
})
}
}
func TestStartPower(t *testing.T) {
t.Parallel()
for _, tc := range TestCases {
t.Run(tc.description, func(t *testing.T) {
if tc.p != erastothenes.Nth("power", tc.n) {
t.FailNow()
}
})
}
}
func TestOnlyTilRoot(t *testing.T) {
t.Parallel()
for _, tc := range TestCases {
t.Run(tc.description, func(t *testing.T) {
if tc.p != erastothenes.Nth("root", tc.n) {
t.FailNow()
}
})
}
}
func TestOptimized(t *testing.T) {
t.Parallel()
for _, tc := range TestCases {
t.Run(tc.description, func(t *testing.T) {
if tc.p != erastothenes.Nth("opt", tc.n) {
t.FailNow()
}
})
}
}
func TestWaitGroup(t *testing.T) {
t.Parallel()
for _, tc := range TestCases {
t.Run(tc.description, func(t *testing.T) {
if tc.p != erastothenes.Nth("waitgroup", tc.n) {
t.FailNow()
}
})
}
}
func BenchmarkUnoptimized(b *testing.B) {
for i := 0; i < b.N; i++ {
erastothenes.Nth("unoptimized", benchNum)
}
}
func BenchmarkSkipEven(b *testing.B) {
for i := 0; i < b.N; i++ {
erastothenes.Nth("skipeven", benchNum)
}
}
func BenchmarkStartPower(b *testing.B) {
for i := 0; i < b.N; i++ {
erastothenes.Nth("power", benchNum)
}
}
func BenchmarkOnlyTilRoot(b *testing.B) {
for i := 0; i < b.N; i++ {
erastothenes.Nth("root", benchNum)
}
}
func BenchmarkOptimized(b *testing.B) {
for i := 0; i < b.N; i++ {
erastothenes.Nth("opt", benchNum)
}
}
func BenchmarkWaitGroup(b *testing.B) {
for i := 0; i < b.N; i++ {
erastothenes.Nth("waitgroup", benchNum)
}
}