Created
March 6, 2021 19:26
-
-
Save juusechec/e9aee02d87b617c0d6d7b1b53cd9dc30 to your computer and use it in GitHub Desktop.
Revisions
-
juusechec created this gist
Mar 6, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ // filename sort_test.go package main import ( "reflect" "sort" "testing" ) func SortAscending(items []int) []int { sort.Slice(items, func(i, j int) bool { return items[i] < items[j] }) return items } func TestLastIndex(t *testing.T) { tests := []struct { list []int want []int }{ {list: []int{1}, want: []int{1}}, {list: []int{1, 1}, want: []int{1, 1}}, {list: []int{2, 1}, want: []int{1, 2}}, {list: []int{1, 2, 1, 1}, want: []int{1, 1, 1, 2}}, {list: []int{1, 1, 1, 2, 2, 1}, want: []int{1, 1, 1, 1, 2, 2}}, {list: []int{3, 1, 2, 2, 1, 1}, want: []int{1, 1, 1, 2, 2, 3}}, {list: []int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, want: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}, {list: []int{9999, 999, 9}, want: []int{9, 999, 9999}}, } for _, tt := range tests { if got := SortAscending(tt.list); !reflect.DeepEqual(got, tt.want) { t.Errorf("LastIndex(%v) = %v, want %v", tt.list, got, tt.want) } } }