Sha256: aa5a1f5684af9abb97e7c5b34ae30448abc34d0b21b7b49fbc40b8b4156ed6c9
Contents?: true
Size: 1.28 KB
Versions: 31
Compression:
Stored size: 1.28 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) { 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
31 entries across 31 versions & 1 rubygems