Sha256: eae3e96b7470c242ff46a6f7863c016b72f07f0671e2bd08c7175c440b876dbf

Contents?: true

Size: 1.24 KB

Versions: 81

Compression:

Stored size: 1.24 KB

Contents

package grains

import (
	"testing"
)

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.Fatalf("FAIL: %s\nSquare(%d) expected %d, Actual %d", test.description, test.input, test.expectedVal, actualVal)
		}

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

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) {

	for i := 0; i < b.N; i++ {

		for _, test := range squareTests {
			Square(test.input)
		}

	}
}

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

Version data entries

81 entries across 81 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.179 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.178 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.177 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.176 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.175 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.174 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.173 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.172 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.171 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.170 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.169 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.167 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.166 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.165 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.164 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.163 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.162 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.161 tracks/go/exercises/grains/grains_test.go
trackler-2.2.1.160 tracks/go/exercises/grains/grains_test.go