Created
April 20, 2019 09:19
-
-
Save famasoon/478e41557a16b78ae6588c8c1e42cde7 to your computer and use it in GitHub Desktop.
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 twosum | |
import ( | |
"reflect" | |
"testing" | |
) | |
type testCase struct { | |
array []int | |
target int | |
} | |
func TestTwoSum(t *testing.T) { | |
tests := []struct { | |
input testCase | |
output []int | |
}{ | |
{testCase{[]int{2, 7, 11, 15}, 9}, []int{0, 1}}, | |
{testCase{[]int{2, 3, 4, 11, 15}, 6}, []int{0, 2}}, | |
} | |
for i, tt := range tests { | |
sum := twoSum(tt.input.array, tt.input.target) | |
if !reflect.DeepEqual(sum, tt.output) { | |
t.Errorf("tests[%d] failed - input: %+v - answer: %+v output: %d¥n", i, tt.input.array, tt.output, sum) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment