github.com/goplusjs/gopherjs@v1.2.6-0.20211206034512-f187917453b8/tests/sort_test.go (about) 1 package tests 2 3 import ( 4 "sort" 5 "testing" 6 ) 7 8 func TestSortSlice(t *testing.T) { 9 a := [...]int{5, 4, 3, 2, 1} 10 11 // Check for a subslice. 12 s1 := a[1:4] 13 sort.Slice(s1, func(i, j int) bool { return s1[i] < s1[j] }) 14 if a != [...]int{5, 2, 3, 4, 1} { 15 t.Fatal("not equal") 16 } 17 18 // Check a slice of the whole array. 19 s2 := a[:] 20 sort.Slice(s2, func(i, j int) bool { return s2[i] < s2[j] }) 21 if a != [...]int{1, 2, 3, 4, 5} { 22 t.Fatal("not equal") 23 } 24 25 // Try using a slice with cap. 26 a2 := [...]int{6, 5, 4, 3, 2, 1} 27 s3 := a2[1:4:4] 28 sort.Slice(s3, func(i, j int) bool { return s3[i] < s3[j] }) 29 if a2 != [...]int{6, 3, 4, 5, 2, 1} { 30 t.Fatal("not equal") 31 } 32 }