1
0
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:
dudaodong
2022-03-26 18:25:42 +08:00
parent ccc0188352
commit 142deb83b2
2 changed files with 3 additions and 3 deletions

View File

@@ -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

View File

@@ -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)