elma_developer_test/missing/missing_test.go

52 lines
1.0 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package missing_test
import (
"fmt"
"gotest/missing"
"testing"
)
// Структура тестовых данных, input - входной массив,
// output - ожидаеммый вывод
type testdata struct {
input []int
output int
}
// Входной, повторения, ожидания
var test = []testdata{
{[]int{1, 2, 4, 3, 6}, 5},
{[]int{1, 2, 3, 5}, 4},
{[]int{1, 2, 4, 3, -6}, -6},
}
func TestMissing(t *testing.T) {
t.Run(
"insert slices", func(t *testing.T) {
for _, data := range test {
// Передаём массив и повторения в функцию и записываем результат в переменную
v := missing.FindNumber(data.input)
// Сравниваем вывод с ожиданием
if v != data.output {
t.Error(
"For: ", data.input,
"Expected: ", data.output,
"Got: ", v,
)
} else {
fmt.Println(
"For: ", data.input,
"Expected: ", data.output,
"Got: ", v,
)
}
}
},
)
}