Created
July 22, 2019 19:13
-
-
Save jsocol/3ac33fe56bf4bbbc2c0b12e50ba0d748 to your computer and use it in GitHub Desktop.
#golang test subcases
This file contains hidden or 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 ex | |
import ( | |
"fmt" | |
"testing" | |
) | |
func Multiplier(in int) int { | |
return in * 2 | |
} | |
func makeMultiplierTest(input, wanted int) func(*testing.T) { | |
return func(t *testing.T) { | |
if Multiplier(input) != wanted { | |
t.Errorf("Multiplier(%v) == (%v)", input, wanted) | |
} | |
} | |
} | |
func TestMultiplier(t *testing.T) { | |
testCases := []struct { | |
input int | |
wanted int | |
}{ | |
{ | |
input: 5, | |
wanted: 10, | |
}, | |
{ | |
input: 2, | |
wanted: 4, | |
}, | |
{ | |
input: 3, | |
wanted: 7, | |
}, | |
} | |
for _, tc := range testCases { | |
t.Run(fmt.Sprintf("Multiplier(%d)", tc.input), makeMultiplierTest(tc.input, tc.wanted)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment