Sha256: 15e7808e3ad70eecc38c689028001672e8b779e2ac6929cfe455cdaebad70204

Contents?: true

Size: 1.55 KB

Versions: 66

Compression:

Stored size: 1.55 KB

Contents

package grains

import (
	"testing"
)

const targetTestVersion = 1

var squareTests = []struct {
	input       int
	expectedVal uint64
	expectError bool
}{
	{1, 1, false},
	{2, 2, false},
	{3, 4, false},
	{4, 8, false},
	{16, 32768, false},
	{32, 2147483648, false},
	{64, 9223372036854775808, false},
	{65, 0, true},
	{0, 0, true},
	{-1, 0, true},
}

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

func TestSquare(t *testing.T) {
	for _, test := range squareTests {
		actualVal, actualErr := Square(test.input)

		// check actualVal only if no error expected
		if !test.expectError && actualVal != test.expectedVal {
			t.Errorf("Square(%d) expected %d, Actual %d", test.input, test.expectedVal, actualVal)
		}

		// if we expect an error and there isn't one
		if test.expectError && actualErr == nil {
			t.Errorf("Square(%d) expected an error, but error is nil", test.input)
		}
		// if we don't expect an error and there is one
		if !test.expectError && actualErr != nil {
			var _ error = actualErr
			t.Errorf("Square(%d) expected no error, but error is: %s", test.input, actualErr)
		}
	}
}

func TestTotal(t *testing.T) {
	var expected uint64 = 18446744073709551615
	if actual := Total(); actual != expected {
		t.Errorf("Total() expected %d, Actual %d", expected, actual)
	}
}

func BenchmarkSquare(b *testing.B) {
	b.StopTimer()

	for _, test := range squareTests {
		b.StartTimer()

		for i := 0; i < b.N; i++ {
			Square(test.input)
		}

		b.StopTimer()
	}
}

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
trackler-2.1.0.5 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.4 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.3 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.2 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.1 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.0 tracks/go/exercises/grains/grains_test.go
trackler-2.0.8.55 tracks/go/exercises/grains/grains_test.go
trackler-2.0.8.54 tracks/go/exercises/grains/grains_test.go
trackler-2.0.8.53 tracks/go/exercises/grains/grains_test.go
trackler-2.0.8.52 tracks/go/exercises/grains/grains_test.go
trackler-2.0.8.51 tracks/go/exercises/grains/grains_test.go
trackler-2.0.8.50 tracks/go/exercises/grains/grains_test.go
trackler-2.0.8.49 tracks/go/exercises/grains/grains_test.go
trackler-2.0.8.48 tracks/go/exercises/grains/grains_test.go
trackler-2.0.8.47 tracks/go/exercises/grains/grains_test.go
trackler-2.0.8.46 tracks/go/exercises/grains/grains_test.go
trackler-2.0.8.45 tracks/go/exercises/grains/grains_test.go
trackler-2.0.8.44 tracks/go/exercises/grains/grains_test.go
trackler-2.0.8.43 tracks/go/exercises/grains/grains_test.go
trackler-2.0.8.42 tracks/go/exercises/grains/grains_test.go