Skip to content

Support order assertions on sort.Interface types #1122

Description

@sjiekak

Given the following type implementing the sort interface

type segment struct {
    left int
    right int
}

type segments []segment

func (l *segments) Len() int {
	return len([]segment(*l))
}

func (l *segments) Less(i, j int) bool {
	data := []segment(*l)
	return data[i].left < data[j].left  || (data[i].left == data[j].left && data[i].right < data[j].right)
}

func (l *segments) Swap(i, j int) {
	data := []segment(*l)
	data[i], data[j] = data[j], data[i]
}

I should be able to perform sort assertions

sample := segments([]segment{
{1, 2},
{3, 4},
})
assert.IsIncreasing(t, &sample)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions