forked from spring1843/go-dsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
insertion_sort_test.go
35 lines (31 loc) · 987 Bytes
/
insertion_sort_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package array
import (
"reflect"
"testing"
)
/*
TestInsertionSort tests solution(s) with the following signature and problem description:
InsertionSort(input []int)
Given an array of unsorted integers, sort the array using the Insertion Sort algorithm.
The algorithm should be in-place, meaning it should not create a new array. The algorithm
works by dividing the input array into sorted and unsorted sections, and moving items from
the unsorted section into the sorted section, one item at a time.
*/
func TestInsertionSort(t *testing.T) {
tests := []struct {
input, sorted []int
}{
{[]int{}, []int{}},
{[]int{1}, []int{1}},
{[]int{1, 2}, []int{1, 2}},
{[]int{2, 1}, []int{1, 2}},
{[]int{2, 3, 1}, []int{1, 2, 3}},
{[]int{4, 2, 3, 1, 5}, []int{1, 2, 3, 4, 5}},
}
for i, test := range tests {
InsertionSort(test.input)
if !reflect.DeepEqual(test.input, test.sorted) {
t.Fatalf("Failed test case #%d. Want %v got %v", i, test.sorted, test.input)
}
}
}