MCPcopy Index your code
hub / github.com/gavv/httpexpect / NotOrdered

Method NotOrdered

array.go:1653–1732  ·  view source on GitHub ↗

NotOrdered succeeds if at least one element is less than the previous element as defined on the given `less` comparator function. For default, it will use built-in comparator function for each data type. Built-in comparator requires all elements in the array to have same data type. Array with 0 or 1

(less ...func(x, y *Value) bool)

Source from the content-addressed store, hash-verified

1651// return x.Number().Raw() < y.Number().Raw()
1652// }) // succeeds
1653func (a *Array) NotOrdered(less ...func(x, y *Value) bool) *Array {
1654 opChain := a.chain.enter("NotOrdered()")
1655 defer opChain.leave()
1656
1657 if opChain.failed() {
1658 return a
1659 }
1660
1661 if len(less) > 1 {
1662 opChain.fail(AssertionFailure{
1663 Type: AssertUsage,
1664 Errors: []error{
1665 errors.New("unexpected multiple less arguments"),
1666 },
1667 })
1668 return a
1669 }
1670
1671 var lessFn func(x, y *Value) bool
1672 if len(less) == 1 {
1673 lessFn = less[0]
1674 if lessFn == nil {
1675 opChain.fail(AssertionFailure{
1676 Type: AssertUsage,
1677 Errors: []error{
1678 errors.New("unexpected nil less argument"),
1679 },
1680 })
1681 return a
1682 }
1683 } else {
1684 lessFn = builtinComparator(opChain, a.value)
1685 if lessFn == nil {
1686 return a
1687 }
1688 }
1689
1690 if len(a.value) <= 1 {
1691 return a
1692 }
1693
1694 ordered := true
1695
1696 for i := 0; i < len(a.value)-1; i++ {
1697 func() {
1698 xChain := opChain.replace("IsOrdered[%d]", i)
1699 defer xChain.leave()
1700
1701 yChain := opChain.replace("IsOrdered[%d]", i+1)
1702 defer yChain.leave()
1703
1704 x := newValue(xChain, a.value[i])
1705 y := newValue(yChain, a.value[i+1])
1706
1707 if lessFn(y, x) {
1708 ordered = false
1709 }
1710 }()

Callers 1

TestArray_IsOrderedFunction · 0.80

Calls 7

builtinComparatorFunction · 0.85
newValueFunction · 0.85
enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80
replaceMethod · 0.80

Tested by 1

TestArray_IsOrderedFunction · 0.64