Last active
May 29, 2017 18:21
-
-
Save dlespiau/4d4b8dc2d1e09985beac950caeed195e to your computer and use it in GitHub Desktop.
calc - unit-tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestAdd(t *testing.T) { | |
tests := []struct { | |
a, b, expected int | |
}{ | |
{0, 0, 0}, | |
{1, 1, 2}, | |
{-2, 1, -1}, | |
{-1, -10, -11}, | |
} | |
for i := range tests { | |
test := &tests[i] | |
got := add(test.a, test.b) | |
if test.expected != got { | |
t.Fatalf("expected %d but got %d", test.expected, got) | |
} | |
} | |
} | |
func TestMain(m *testing.M) { | |
cover.ParseAndStripTestFlags() | |
// Make sure we have the opportunity to flush the coverage report to disk when | |
// terminating the process. | |
exit.AtExit(cover.FlushProfiles) | |
// If the test binary name is "calc", we've are being asked to run the | |
// coverage-instrumented program. | |
if path.Base(os.Args[0]) == "calc" { | |
main() | |
exit.Exit(0) | |
} | |
os.Exit(m.Run()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment