Skip to content

Commit 8f6867e

Browse files
committed
[test] added unit test for quick-sort
1 parent 67909ef commit 8f6867e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

quick-sort/quick-sort_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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

Comments
 (0)