|
| 1 | +// ==================================================== |
| 2 | +// Data-Structures-with-Go Copyright(C) 2017 Furkan Türkal |
| 3 | +// This program comes with ABSOLUTELY NO WARRANTY; This is free software, |
| 4 | +// and you are welcome to redistribute it under certain conditions; See |
| 5 | +// file LICENSE, which is part of this source code package, for details. |
| 6 | +// ==================================================== |
| 7 | + |
| 8 | +package main |
| 9 | + |
| 10 | +import ( |
| 11 | + "reflect" |
| 12 | + "testing" |
| 13 | +) |
| 14 | + |
| 15 | +func TestQuickSort(t *testing.T) { |
| 16 | + var testDatas = []struct { |
| 17 | + ArrayIn []int |
| 18 | + ArrayOut []int |
| 19 | + }{ |
| 20 | + {[]int{1, 3, 2, 4}, []int{1, 2, 3, 4}}, |
| 21 | + {[]int{3, 2, 1, 4}, []int{1, 2, 3, 4}}, |
| 22 | + {[]int{9, 8, 6, 5, 7, 4, 3, 0, 2, 1}, []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}}, |
| 23 | + {[]int{-3, -2, -1, -4, 0}, []int{-4, -3, -2, -1, 0}}, |
| 24 | + } |
| 25 | + for _, data := range testDatas { |
| 26 | + expected := data.ArrayOut |
| 27 | + QuickSort(data.ArrayIn, 0, len(data.ArrayIn)-1) |
| 28 | + actual := data.ArrayIn |
| 29 | + |
| 30 | + if !reflect.DeepEqual(expected, actual) { |
| 31 | + t.Errorf("QuickSort: Expected: %d, Actual: %d", expected, actual) |
| 32 | + } |
| 33 | + } |
| 34 | +} |
0 commit comments