Sha256: fb846484271d9626d0bd566d06050540b6aa9fbdb1c3e59931635dd3ba7bb411

Contents?: true

Size: 1.63 KB

Versions: 113

Compression:

Stored size: 1.63 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()
	}
}

func BenchmarkTotal(b *testing.B) {
	for i := 0; i < b.N; i++ {
		Total()
	}
}

Version data entries

113 entries across 113 versions & 1 rubygems

Version Path
trackler-2.1.0.39 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.38 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.37 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.36 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.34 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.33 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.32 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.31 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.30 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.29 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.28 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.27 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.26 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.25 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.24 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.23 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.22 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.21 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.20 tracks/go/exercises/grains/grains_test.go
trackler-2.1.0.19 tracks/go/exercises/grains/grains_test.go