📖 11 min read (~ 2300 words).

Ordering

Asserting How Collections Are Ordered

Assertions

GoDoc

All links point to https://pkg.go.dev/github.com/go-openapi/testify/v2

This domain exposes 10 functionalities. Generic assertions are marked with a .

IsDecreasing

IsDecreasing asserts that the collection is strictly decreasing.

Examples
	assertions.IsDecreasing(t, []int{2, 1, 0})
	assertions.IsDecreasing(t, []float{2, 1})
	assertions.IsDecreasing(t, []string{"b", "a"})
	success: []int{3, 2, 1}
	failure: []int{1, 2, 3}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestIsDecreasing(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/assert"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestIsDecreasing(t *testing.T)
    	success := assert.IsDecreasing(t, []int{3, 2, 1})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestIsDecreasing(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/require"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestIsDecreasing(t *testing.T)
    	require.IsDecreasing(t, []int{3, 2, 1})
    	fmt.Println("passed")
    
    }

IsDecreasingT[OrderedSlice ~[]E, E Ordered]

IsDecreasingT asserts that a slice of Ordered is strictly decreasing.

Examples
	assertions.IsDecreasingT(t, []int{2, 1, 0})
	assertions.IsDecreasingT(t, []float{2, 1})
	assertions.IsDecreasingT(t, []string{"b", "a"})
	success: []int{3, 2, 1}
	failure: []int{1, 2, 3}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestIsDecreasingT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/assert"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestIsDecreasingT(t *testing.T)
    	success := assert.IsDecreasingT(t, []int{3, 2, 1})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestIsDecreasingT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/require"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestIsDecreasingT(t *testing.T)
    	require.IsDecreasingT(t, []int{3, 2, 1})
    	fmt.Println("passed")
    
    }

IsIncreasing

IsIncreasing asserts that the collection is strictly increasing.

Examples
	assertions.IsIncreasing(t, []int{1, 2, 3})
	assertions.IsIncreasing(t, []float{1, 2})
	assertions.IsIncreasing(t, []string{"a", "b"})
	success: []int{1, 2, 3}
	failure: []int{1, 1, 2}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestIsIncreasing(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/assert"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestIsIncreasing(t *testing.T)
    	success := assert.IsIncreasing(t, []int{1, 2, 3})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestIsIncreasing(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/require"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestIsIncreasing(t *testing.T)
    	require.IsIncreasing(t, []int{1, 2, 3})
    	fmt.Println("passed")
    
    }

IsIncreasingT[OrderedSlice ~[]E, E Ordered]

IsIncreasingT asserts that a slice of Ordered is strictly increasing.

Examples
	assertions.IsIncreasingT(t, []int{1, 2, 3})
	assertions.IsIncreasingT(t, []float{1, 2})
	assertions.IsIncreasingT(t, []string{"a", "b"})
	success: []int{1, 2, 3}
	failure: []int{1, 1, 2}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestIsIncreasingT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/assert"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestIsIncreasingT(t *testing.T)
    	success := assert.IsIncreasingT(t, []int{1, 2, 3})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestIsIncreasingT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/require"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestIsIncreasingT(t *testing.T)
    	require.IsIncreasingT(t, []int{1, 2, 3})
    	fmt.Println("passed")
    
    }

IsNonDecreasing

IsNonDecreasing asserts that the collection is not strictly decreasing.

Examples
	assertions.IsNonDecreasing(t, []int{1, 1, 2})
	assertions.IsNonDecreasing(t, []float{1, 2})
	assertions.IsNonDecreasing(t, []string{"a", "b"})
	success: []int{1, 1, 2}
	failure: []int{2, 1, 0}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestIsNonDecreasing(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/assert"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestIsNonDecreasing(t *testing.T)
    	success := assert.IsNonDecreasing(t, []int{1, 1, 2})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestIsNonDecreasing(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/require"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestIsNonDecreasing(t *testing.T)
    	require.IsNonDecreasing(t, []int{1, 1, 2})
    	fmt.Println("passed")
    
    }

IsNonDecreasingT[OrderedSlice ~[]E, E Ordered]

IsNonDecreasingT asserts that a slice of Ordered is not decreasing.

Examples
	assertions.IsNonDecreasingT(t, []int{1, 1, 2})
	assertions.IsNonDecreasingT(t, []float{1, 2})
	assertions.IsNonDecreasingT(t, []string{"a", "b"})
	success: []int{1, 1, 2}
	failure: []int{2, 1, 0}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestIsNonDecreasingT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/assert"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestIsNonDecreasingT(t *testing.T)
    	success := assert.IsNonDecreasingT(t, []int{1, 1, 2})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestIsNonDecreasingT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/require"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestIsNonDecreasingT(t *testing.T)
    	require.IsNonDecreasingT(t, []int{1, 1, 2})
    	fmt.Println("passed")
    
    }

IsNonIncreasing

IsNonIncreasing asserts that the collection is not increasing.

Examples
	assertions.IsNonIncreasing(t, []int{2, 1, 1})
	assertions.IsNonIncreasing(t, []float{2, 1})
	assertions.IsNonIncreasing(t, []string{"b", "a"})
	success: []int{2, 1, 1}
	failure: []int{1, 2, 3}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestIsNonIncreasing(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/assert"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestIsNonIncreasing(t *testing.T)
    	success := assert.IsNonIncreasing(t, []int{2, 1, 1})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestIsNonIncreasing(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/require"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestIsNonIncreasing(t *testing.T)
    	require.IsNonIncreasing(t, []int{2, 1, 1})
    	fmt.Println("passed")
    
    }

IsNonIncreasingT[OrderedSlice ~[]E, E Ordered]

IsNonIncreasingT asserts that a slice of Ordered is NOT strictly increasing.

Examples
	assertions.IsNonIncreasing(t, []int{2, 1, 1})
	assertions.IsNonIncreasing(t, []float{2, 1})
	assertions.IsNonIncreasing(t, []string{"b", "a"})
	success: []int{2, 1, 1}
	failure: []int{1, 2, 3}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestIsNonIncreasingT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/assert"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestIsNonIncreasingT(t *testing.T)
    	success := assert.IsNonIncreasingT(t, []int{2, 1, 1})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestIsNonIncreasingT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/require"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestIsNonIncreasingT(t *testing.T)
    	require.IsNonIncreasingT(t, []int{2, 1, 1})
    	fmt.Println("passed")
    
    }

NotSortedT[OrderedSlice ~[]E, E Ordered]

NotSortedT asserts that the slice of Ordered is NOT sorted (i.e. non-strictly increasing).

Unlike IsDecreasingT, it accepts slices that are neither increasing nor decreasing.

Examples
	assertions.NotSortedT(t, []int{3, 2, 3})
	assertions.NotSortedT(t, []float{2, 1})
	assertions.NotSortedT(t, []string{"b", "a"})
	success: []int{3, 1, 3}
	failure: []int{1, 4, 8}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestNotSortedT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/assert"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestNotSortedT(t *testing.T)
    	success := assert.NotSortedT(t, []int{3, 1, 3})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestNotSortedT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/require"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestNotSortedT(t *testing.T)
    	require.NotSortedT(t, []int{3, 1, 3})
    	fmt.Println("passed")
    
    }

SortedT[OrderedSlice ~[]E, E Ordered]

SortedT asserts that the slice of Ordered is sorted (i.e. non-strictly increasing).

Unlike IsIncreasingT, it accepts elements to be equal.

Examples
	assertions.SortedT(t, []int{1, 2, 3})
	assertions.SortedT(t, []float{1, 2})
	assertions.SortedT(t, []string{"a", "b"})
	success: []int{1, 1, 3}
	failure: []int{1, 4, 2}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestSortedT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/assert"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestSortedT(t *testing.T)
    	success := assert.SortedT(t, []int{1, 1, 3})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestSortedT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/require"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestSortedT(t *testing.T)
    	require.SortedT(t, []int{1, 1, 3})
    	fmt.Println("passed")
    
    }


Generated with github.com/go-openapi/testify/codegen/v2