Sha256: a0935a8ba2a095ab4d3467e76672ab45d651ebc14f514385048a188c7a31fe8f

Contents?: true

Size: 1.55 KB

Versions: 95

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 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 TestTestVersion(t *testing.T) {
	if testVersion != targetTestVersion {
		t.Errorf("Found testVersion = %v, want %v.", testVersion, targetTestVersion)
	}
}

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

95 entries across 95 versions & 1 rubygems

Version Path
trackler-2.0.6.39 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.38 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.37 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.36 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.35 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.34 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.33 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.32 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.31 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.30 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.29 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.28 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.27 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.26 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.25 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.24 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.23 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.22 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.21 tracks/go/exercises/grains/grains_test.go
trackler-2.0.6.20 tracks/go/exercises/grains/grains_test.go