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

Function TestFindKthMax

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

Source from the content-addressed store, hash-verified

6)
7
8func TestFindKthMax(t *testing.T) {
9 sortTests := []struct {
10 input []int
11 k int
12 expected int
13 err error
14 name string
15 }{
16 {
17 input: []int{6, 7, 0, -1, 10, 70, 8, 22, 3, 9},
18 k: 3,
19 expected: 10,
20 name: "3th largest number",
21 },
22 {
23 input: []int{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
24 k: 3,
25 expected: -1,
26 name: "3th largest number",
27 },
28 {
29 input: []int{-1, -1, -1, -1, -1, -1},
30 k: 7,
31 expected: -1,
32 err: search.ErrNotFound,
33 name: "This should be an error",
34 },
35 {
36 input: []int{},
37 k: 1,
38 expected: -1,
39 err: search.ErrNotFound,
40 name: "This should be an error",
41 },
42 }
43 for _, test := range sortTests {
44 t.Run(test.name, func(t *testing.T) {
45 actual, err := FindKthMax(test.input, test.k)
46 if err != test.err {
47 t.Errorf("name:%v FindKthMax() = %v, want err: %v", test.name, err, test.err)
48 }
49 if actual != test.expected {
50 t.Errorf("test %s failed", test.name)
51 t.Errorf("actual %v expected %v", actual, test.expected)
52 }
53 })
54 }
55}
56
57func TestFindKthMin(t *testing.T) {
58 sortTests := []struct {

Callers

nothing calls this directly

Calls 1

FindKthMaxFunction · 0.85

Tested by

no test coverage detected