[test] added unit test for array-smallest-missing-number

master
Furkan Türkal 5 years ago
parent 2b9b3a8548
commit 663087d7d1
No known key found for this signature in database
GPG Key ID: 3015FE56155820F2

@ -0,0 +1,36 @@
// ====================================================
// Data-Structures-with-Go Copyright(C) 2017 Furkan Türkal
// This program comes with ABSOLUTELY NO WARRANTY; This is free software,
// and you are welcome to redistribute it under certain conditions; See
// file LICENSE, which is part of this source code package, for details.
// ====================================================
package main
import (
"reflect"
"testing"
)
func TestFindFirstMissing(t *testing.T) {
var testDatas = []struct {
ArrayIn []int
Start int
End int
Out int
}{
{[]int{0, 1, 2, 4, 5}, 0, 4, 3},
{[]int{0, 1, 2, 3, 4, 6, 8, 9, 10}, 0, 5, 5},
{[]int{0, 1, 2, 3, 4, 6, 8, 9, 10}, 0, 8, 5},
{[]int{0, 1, 2, 3, 4, 5, 6, 8, 9, 10}, 0, 8, 7},
{[]int{1, 2, 3, 4, 5}, 0, 5, 0},
}
for _, data := range testDatas {
expected := data.Out
actual := findFirstMissing(data.ArrayIn, data.Start, data.End)
if !reflect.DeepEqual(expected, actual) {
t.Errorf("FindFirstMissing: Expected: %d, Actual: %d", expected, actual)
}
}
}
Loading…
Cancel
Save