MCPcopy
hub / github.com/stretchr/testify / isOrdered

Function isOrdered

assert/assertion_order.go:9–45  ·  assert/assertion_order.go::isOrdered

isOrdered checks that collection contains orderable elements.

(t TestingT, object interface{}, allowedComparesResults []compareResult, failMessage string, msgAndArgs ...interface{})

Source from the content-addressed store, hash-verified

7
8// isOrdered checks that collection contains orderable elements.
9func isOrdered(t TestingT, object interface{}, allowedComparesResults []compareResult, failMessage string, msgAndArgs ...interface{}) bool {
10 objKind := reflect.TypeOf(object).Kind()
11 if objKind != reflect.Slice && objKind != reflect.Array {
12 return false
13 }
14
15 objValue := reflect.ValueOf(object)
16 objLen := objValue.Len()
17
18 if objLen <= 1 {
19 return true
20 }
21
22 value := objValue.Index(0)
23 valueInterface := value.Interface()
24 firstValueKind := value.Kind()
25
26 for i := 1; i < objLen; i++ {
27 prevValue := value
28 prevValueInterface := valueInterface
29
30 value = objValue.Index(i)
31 valueInterface = value.Interface()
32
33 compareResult, isComparable := compare(prevValueInterface, valueInterface, firstValueKind)
34
35 if !isComparable {
36 return Fail(t, fmt.Sprintf(`Can not compare type "%T" and "%T"`, value, prevValue), msgAndArgs...)
37 }
38
39 if !containsValue(allowedComparesResults, compareResult) {
40 return Fail(t, fmt.Sprintf(failMessage, prevValue, value), msgAndArgs...)
41 }
42 }
43
44 return true
45}
46
47// IsIncreasing asserts that the collection is increasing
48//

Callers 4

IsIncreasingFunction · 0.85
IsNonIncreasingFunction · 0.85
IsDecreasingFunction · 0.85
IsNonDecreasingFunction · 0.85

Calls 4

compareFunction · 0.85
containsValueFunction · 0.85
FailFunction · 0.70
LenMethod · 0.45

Tested by

no test coverage detected