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

Function TestNextPermutation

math/permutation/next_permutation_test.go:8–40  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestNextPermutation(t *testing.T) {
9 var nextPermutationTestData = []struct {
10 description string
11 numbers []int
12 next []int
13 }{
14 {
15 description: "Basic case",
16 numbers: []int{1, 2, 3},
17 next: []int{1, 3, 2},
18 },
19 {
20 description: "Should reverse the whole slice",
21 numbers: []int{3, 2, 1},
22 next: []int{1, 2, 3},
23 },
24 {
25 description: "A more complex test",
26 numbers: []int{2, 4, 1, 7, 5, 0},
27 next: []int{2, 4, 5, 0, 1, 7},
28 },
29 }
30 for _, test := range nextPermutationTestData {
31 t.Run(test.description, func(t *testing.T) {
32 NextPermutation(test.numbers)
33
34 if !reflect.DeepEqual(test.numbers, test.next) {
35 t.Logf("FAIL: %s", test.description)
36 t.Fatalf("Expected result:%v\nFound: %v", test.next, test.numbers)
37 }
38 })
39 }
40}

Callers

nothing calls this directly

Calls 1

NextPermutationFunction · 0.85

Tested by

no test coverage detected