mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
fix: fix InsertionSort bug
This commit is contained in:
@@ -37,7 +37,7 @@ func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator) []
|
|||||||
preIndex--
|
preIndex--
|
||||||
}
|
}
|
||||||
|
|
||||||
slice[preIndex+1] = preItem
|
slice[preIndex+1] = currentItem
|
||||||
}
|
}
|
||||||
|
|
||||||
return slice
|
return slice
|
||||||
|
|||||||
@@ -89,10 +89,10 @@ func TestInsertionSort(t *testing.T) {
|
|||||||
asssert := internal.NewAssert(t, "TestInsertionSort")
|
asssert := internal.NewAssert(t, "TestInsertionSort")
|
||||||
|
|
||||||
comparator := &peopleAgeComparator{}
|
comparator := &peopleAgeComparator{}
|
||||||
sortedPeopleByAge := SelectionSort(peoples, comparator)
|
sortedPeopleByAge := InsertionSort(peoples, comparator)
|
||||||
t.Log(sortedPeopleByAge)
|
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)
|
actual := fmt.Sprintf("%v", sortedPeopleByAge)
|
||||||
|
|
||||||
asssert.Equal(expected, actual)
|
asssert.Equal(expected, actual)
|
||||||
|
|||||||
Reference in New Issue
Block a user