Skip to content

Instantly share code, notes, and snippets.

@dlespiau
Last active May 29, 2017 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlespiau/4d4b8dc2d1e09985beac950caeed195e to your computer and use it in GitHub Desktop.
Save dlespiau/4d4b8dc2d1e09985beac950caeed195e to your computer and use it in GitHub Desktop.
calc - unit-tests
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