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

Function TestSelectK

search/selectk_test.go:7–31  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

5)
6
7func TestSelectK(t *testing.T) {
8 tests := []struct {
9 data []int
10 k int
11 expected int
12 err error
13 name string
14 }{
15 {[]int{1, 2, 3, 4, 5}, 1, 5, nil, "sorted data"},
16 {[]int{5, 4, 3, 2, 1}, 2, 4, nil, "reversed data"},
17 {[]int{3, 1, 2, 5, 4}, 3, 3, nil, "random data"},
18 {[]int{3, 2, 1, 5, 4}, 10, -1, ErrNotFound, " absent data"},
19 }
20 for _, tc := range tests {
21 t.Run(tc.name, func(t *testing.T) {
22 elem, err := SelectK(tc.data, tc.k)
23 if err != tc.err {
24 t.Errorf("name:%v SelectK() = _, %v, want err: %v", tc.name, err, tc.err)
25 }
26 if elem != tc.expected {
27 t.Errorf("name:%v SelectK() = %v,_ , want: %v", tc.name, elem, tc.expected)
28 }
29 })
30 }
31}
32
33func BenchmarkSelectK(b *testing.B) {
34 testCase := generateBenchmarkTestCase()

Callers

nothing calls this directly

Calls 1

SelectKFunction · 0.85

Tested by

no test coverage detected