Sha256: 26f9b70cde902a561ec9a0a87a2cd6fda1d434fd049884bc30a920c6c043b985

Contents?: true

Size: 847 Bytes

Versions: 177

Compression:

Stored size: 847 Bytes

Contents

package prime

import "testing"

const targetTestVersion = 1

var tests = []struct {
	n  int
	p  int
	ok bool
}{
	{1, 2, true},
	{2, 3, true},
	{3, 5, true},
	{4, 7, true},
	{5, 11, true},
	{6, 13, true},
	{10001, 104743, true},
	{0, 0, false},
}

func TestTestVersion(t *testing.T) {
	if testVersion != targetTestVersion {
		t.Fatalf("Found testVersion = %v, want %v", testVersion, targetTestVersion)
	}
}

func TestNth(t *testing.T) {
	for _, test := range tests {
		switch p, ok := Nth(test.n); {
		case !ok:
			if test.ok {
				t.Fatalf("Nth(%d) returned !ok.  Expecting ok.", test.n)
			}
		case !test.ok:
			t.Fatalf("Nth(%d) = %d, ok = %t.  Expecting !ok.", test.n, p, ok)
		case p != test.p:
			t.Fatalf("Nth(%d) = %d, want %d.", test.n, p, test.p)
		}
	}
}

func BenchmarkNth(b *testing.B) {
	for i := 0; i < b.N; i++ {
		Nth(10001)
	}
}

Version data entries

177 entries across 177 versions & 1 rubygems

Version Path
trackler-2.2.1.56 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.55 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.54 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.53 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.52 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.51 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.50 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.49 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.48 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.47 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.46 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.45 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.44 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.43 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.42 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.41 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.40 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.39 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.38 tracks/go/exercises/nth-prime/nth_prime_test.go
trackler-2.2.1.37 tracks/go/exercises/nth-prime/nth_prime_test.go