Last active
May 1, 2018 17:11
-
-
Save evie404/adad552be2e92eda67ab5b4e6003fbcc to your computer and use it in GitHub Desktop.
interview snipplet
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 main | |
import "fmt" | |
func plusone(a int) int { | |
return a + 1 | |
} | |
type testCase struct { | |
input int | |
expected int | |
} | |
func main() { | |
testCases := []testCase{ | |
{ | |
1, | |
2, | |
}, | |
{ | |
2, | |
3, | |
}, | |
{ | |
3, | |
4, | |
}, | |
{ | |
4, | |
5, | |
}, | |
} | |
for _, t := range testCases { | |
input := t.input | |
expected := t.expected | |
actual := plusone(input) | |
fmt.Printf("input: %v\n", input) | |
fmt.Printf("expected: %v\n", expected) | |
fmt.Printf("actual: %v\n", actual) | |
if expected != actual { | |
fmt.Println("Test case is incorrect.") | |
return | |
} | |
fmt.Println() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment