Пример #1
0
func TestSortInputIsNil(t *testing.T) {
	var input []int

	got := counting.Sort(input)

	if got != nil {
		t.Errorf("Sort fail - got %v expected nil", got)
	}
}
Пример #2
0
func TestSort(t *testing.T) {
	// compareIntSlices checks if two integer slices contain elements in the
	// same order.
	compareIntSlices := func(a, b []int) bool {
		if len(a) != len(b) || a == nil || b == nil {
			return false
		}

		for i := 0; i < len(a); i++ {
			if a[i] != b[i] {
				return false
			}
		}
		return true
	}

	for _, test := range tests {
		got := counting.Sort(test.input)
		if !compareIntSlices(got, test.expected) {
			t.Errorf("Sort fail - got %v expected %v", got, test.expected)
		}
	}
}