diff --git a/algorithm/sorter.go b/algorithm/sorter.go index 075ed0f..9223337 100644 --- a/algorithm/sorter.go +++ b/algorithm/sorter.go @@ -37,7 +37,7 @@ func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator) [] preIndex-- } - slice[preIndex+1] = preItem + slice[preIndex+1] = currentItem } return slice diff --git a/algorithm/sorter_test.go b/algorithm/sorter_test.go index f6dd592..0a534dd 100644 --- a/algorithm/sorter_test.go +++ b/algorithm/sorter_test.go @@ -89,10 +89,10 @@ func TestInsertionSort(t *testing.T) { asssert := internal.NewAssert(t, "TestInsertionSort") comparator := &peopleAgeComparator{} - sortedPeopleByAge := SelectionSort(peoples, comparator) + sortedPeopleByAge := InsertionSort(peoples, comparator) t.Log(sortedPeopleByAge) - expected := "[{d 8} {b 10} {c 17} {a 20} {e 28}]" + expected := "[{e 28} {c 17} {a 20} {b 10} {d 8}]" actual := fmt.Sprintf("%v", sortedPeopleByAge) asssert.Equal(expected, actual)