(t *testing.T)
| 6 | ) |
| 7 | |
| 8 | func Test_maxSubArray(t *testing.T) { |
| 9 | type args struct { |
| 10 | nums []int |
| 11 | } |
| 12 | tests := []struct { |
| 13 | name string |
| 14 | args args |
| 15 | want int |
| 16 | }{ |
| 17 | { |
| 18 | name: "contiguous subarray which has the largest sum", |
| 19 | args: args{ |
| 20 | nums: []int{-2, 1, -3, 4, -1, 2, 1, -5, 4}, |
| 21 | }, |
| 22 | want: 6, |
| 23 | }, |
| 24 | { |
| 25 | name: "contiguous subarray which has the largest sum", |
| 26 | args: args{ |
| 27 | nums: []int{-1000, 1000, 1}, |
| 28 | }, |
| 29 | want: 1001, |
| 30 | }, |
| 31 | { |
| 32 | name: "contiguous subarray which has the largest sum", |
| 33 | args: args{ |
| 34 | nums: []int{-1, 2, -1, -3}, |
| 35 | }, |
| 36 | want: 2, |
| 37 | }, |
| 38 | } |
| 39 | for _, tt := range tests { |
| 40 | t.Run(tt.name, func(t *testing.T) { |
| 41 | assert.Equal(t, tt.want, maxSubArray(tt.args.nums)) |
| 42 | assert.Equal(t, tt.want, maxSubArray2(tt.args.nums)) |
| 43 | }) |
| 44 | } |
| 45 | } |
nothing calls this directly
no test coverage detected