(t *testing.T, sortingFunction func([]int) []int)
| 10 | ) |
| 11 | |
| 12 | func testFramework(t *testing.T, sortingFunction func([]int) []int) { |
| 13 | sortTests := []struct { |
| 14 | input []int |
| 15 | expected []int |
| 16 | name string |
| 17 | }{ |
| 18 | //Sorted slice |
| 19 | { |
| 20 | input: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, |
| 21 | expected: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, |
| 22 | name: "Sorted Unsigned", |
| 23 | }, |
| 24 | //Reversed slice |
| 25 | { |
| 26 | input: []int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, |
| 27 | expected: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, |
| 28 | name: "Reversed Unsigned", |
| 29 | }, |
| 30 | //Sorted slice |
| 31 | { |
| 32 | input: []int{-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, |
| 33 | expected: []int{-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, |
| 34 | name: "Sorted Signed", |
| 35 | }, |
| 36 | //Reversed slice |
| 37 | { |
| 38 | input: []int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10}, |
| 39 | expected: []int{-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, |
| 40 | name: "Reversed Signed", |
| 41 | }, |
| 42 | //Reversed slice, even length |
| 43 | { |
| 44 | input: []int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10}, |
| 45 | expected: []int{-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, |
| 46 | name: "Reversed Signed #2", |
| 47 | }, |
| 48 | //Random order with repetitions |
| 49 | { |
| 50 | input: []int{-5, 7, 4, -2, 6, 5, 8, 3, 2, -7, -1, 0, -3, 9, -6, -4, 10, 9, 1, -8, -9, -10}, |
| 51 | expected: []int{-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10}, |
| 52 | name: "Random order Signed", |
| 53 | }, |
| 54 | //Single-entry slice |
| 55 | { |
| 56 | input: []int{1}, |
| 57 | expected: []int{1}, |
| 58 | name: "Singleton", |
| 59 | }, |
| 60 | // Empty slice |
| 61 | { |
| 62 | input: []int{}, |
| 63 | expected: []int{}, |
| 64 | name: "Empty Slice", |
| 65 | }, |
| 66 | } |
| 67 | for _, test := range sortTests { |
| 68 | t.Run(test.name, func(t *testing.T) { |
| 69 | actual := sortingFunction(test.input) |
no outgoing calls
no test coverage detected