MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TestFindKthMin

Function TestFindKthMin

math/kthnumber_test.go:57–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

55}
56
57func TestFindKthMin(t *testing.T) {
58 sortTests := []struct {
59 input []int
60 k int
61 expected int
62 err error
63 name string
64 }{
65 {
66 input: []int{6, 7, 0, -1, 10, 70, 8, 22, 3, 9},
67 k: 3,
68 expected: 3,
69 name: "3th smallest number",
70 },
71 {
72 input: []int{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
73 k: 3,
74 expected: -1,
75 name: "3th smallest number",
76 },
77 {
78 input: []int{-1, -1, -1, -1, -1, -1},
79 k: 7,
80 expected: -1,
81 err: search.ErrNotFound,
82 name: "This should be an error",
83 },
84 {
85 input: []int{},
86 k: 1,
87 expected: -1,
88 err: search.ErrNotFound,
89 name: "This should be an error",
90 },
91 }
92 for _, test := range sortTests {
93 t.Run(test.name, func(t *testing.T) {
94 actual, err := FindKthMin(test.input, test.k)
95 if err != test.err {
96 t.Errorf("name:%v FindKthMin() = %v, want err: %v", test.name, err, test.err)
97 }
98 if actual != test.expected {
99 t.Errorf("test %s failed", test.name)
100 t.Errorf("actual %v expected %v", actual, test.expected)
101 }
102 })
103 }
104}

Callers

nothing calls this directly

Calls 1

FindKthMinFunction · 0.85

Tested by

no test coverage detected