Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStocks committed Jan 11, 2020
2 parents da528eb + c46b141 commit 460ecfe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions sort/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func Int32(slice []int32) {
sort.Sort(Int32Slice(slice))
}

func Uint32(slice []uint32) {
sort.Sort(Uint32Slice(slice))
}

type Int64Slice []int64

func (p Int64Slice) Len() int {
Expand Down Expand Up @@ -56,3 +60,17 @@ func (p Int32Slice) Less(i, j int) bool {
func (p Int32Slice) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}

type Uint32Slice []uint32

func (p Uint32Slice) Len() int {
return len(p)
}

func (p Uint32Slice) Less(i, j int) bool {
return p[i] < p[j]
}

func (p Uint32Slice) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}
12 changes: 12 additions & 0 deletions sort/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ func TestSortInt64(t *testing.T) {
assert.Equal(t, int64(5), data[5])
assert.Equal(t, int64(9), data[6])
}

func TestSortUint32(t *testing.T) {
data := []uint32{3, 5, 1, 9, 0, 2, 2}
Uint32(data)
assert.Equal(t, uint32(0), data[0])
assert.Equal(t, uint32(1), data[1])
assert.Equal(t, uint32(2), data[2])
assert.Equal(t, uint32(2), data[3])
assert.Equal(t, uint32(3), data[4])
assert.Equal(t, uint32(5), data[5])
assert.Equal(t, uint32(9), data[6])
}

0 comments on commit 460ecfe

Please sign in to comment.