Last active
May 13, 2020 10:24
-
-
Save quii/96c49d33715d3eb55006c3c8852ff11d to your computer and use it in GitHub Desktop.
Why does this test pass huh?
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
package learn_go_with_tests | |
import ( | |
"fmt" | |
"testing" | |
) | |
func Add(x, y int) int { | |
return 3 | |
} | |
// Why does this test pass given the implementation of Add? | |
func TestAdd(t *testing.T) { | |
cases := []struct{ | |
X, Y int | |
Want int | |
} { | |
{X: 1, Y: 1, Want: 2}, | |
{X: 1, Y: 2, Want: 3}, | |
} | |
for _, test := range cases { | |
t.Run(fmt.Sprintf("%d plus %d is %d", test.X, test.Y, test.Want), func(t *testing.T) { | |
t.Parallel() | |
got := Add(test.X, test.Y) | |
if got != test.Want{ | |
t.Errorf("got %d, wanted %d", got, test.Want) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment