|
| 1 | +package sort_colors |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +func Test_sortColors(t *testing.T) { |
| 9 | + tests := []struct { |
| 10 | + input []int |
| 11 | + want []int |
| 12 | + }{ |
| 13 | + {input: []int{2, 0, 2, 1, 1, 0}, want: []int{0, 0, 1, 1, 2, 2}}, |
| 14 | + {input: []int{2, 0, 2, 1, 1, 1}, want: []int{0, 1, 1, 1, 2, 2}}, |
| 15 | + {input: []int{2, 2, 2, 1, 1, 1}, want: []int{1, 1, 1, 2, 2, 2}}, |
| 16 | + {input: []int{1, 2, 2, 0, 1}, want: []int{0, 1, 1, 2, 2}}, |
| 17 | + {input: []int{0, 1, 2, 2}, want: []int{0, 1, 2, 2}}, |
| 18 | + {input: []int{1, 2, 0}, want: []int{0, 1, 2}}, |
| 19 | + {input: []int{2, 0, 1}, want: []int{0, 1, 2}}, |
| 20 | + {input: []int{2, 2, 2}, want: []int{2, 2, 2}}, |
| 21 | + {input: []int{1}, want: []int{1}}, |
| 22 | + {input: []int{0}, want: []int{0}}, |
| 23 | + {input: []int{}, want: []int{}}, |
| 24 | + } |
| 25 | + |
| 26 | + for i, tc := range tests { |
| 27 | + sortColors(tc.input) |
| 28 | + if !reflect.DeepEqual(tc.want, tc.input) { |
| 29 | + t.Fatalf("Case #%d: expected: %v, got: %v", i+1, tc.want, tc.input) |
| 30 | + } |
| 31 | + } |
| 32 | +} |
0 commit comments