package assertimport ()// isOrdered checks that collection contains orderable elements.func isOrdered( TestingT, interface{}, []compareResult, string, ...interface{}) bool { := reflect.TypeOf().Kind()if != reflect.Slice && != reflect.Array {returnfalse } := reflect.ValueOf() := .Len()if <= 1 {returntrue } := .Index(0) := .Interface() := .Kind()for := 1; < ; ++ { := := = .Index() = .Interface() , := compare(, , )if ! {returnFail(, fmt.Sprintf(`Can not compare type "%T" and "%T"`, , ), ...) }if !containsValue(, ) {returnFail(, fmt.Sprintf(, , ), ...) } }returntrue}// IsIncreasing asserts that the collection is increasing//// assert.IsIncreasing(t, []int{1, 2, 3})// assert.IsIncreasing(t, []float{1, 2})// assert.IsIncreasing(t, []string{"a", "b"})func ( TestingT, interface{}, ...interface{}) bool {returnisOrdered(, , []compareResult{compareLess}, "\"%v\" is not less than \"%v\"", ...)}// IsNonIncreasing asserts that the collection is not increasing//// assert.IsNonIncreasing(t, []int{2, 1, 1})// assert.IsNonIncreasing(t, []float{2, 1})// assert.IsNonIncreasing(t, []string{"b", "a"})func ( TestingT, interface{}, ...interface{}) bool {returnisOrdered(, , []compareResult{compareEqual, compareGreater}, "\"%v\" is not greater than or equal to \"%v\"", ...)}// IsDecreasing asserts that the collection is decreasing//// assert.IsDecreasing(t, []int{2, 1, 0})// assert.IsDecreasing(t, []float{2, 1})// assert.IsDecreasing(t, []string{"b", "a"})func ( TestingT, interface{}, ...interface{}) bool {returnisOrdered(, , []compareResult{compareGreater}, "\"%v\" is not greater than \"%v\"", ...)}// IsNonDecreasing asserts that the collection is not decreasing//// assert.IsNonDecreasing(t, []int{1, 1, 2})// assert.IsNonDecreasing(t, []float{1, 2})// assert.IsNonDecreasing(t, []string{"a", "b"})func ( TestingT, interface{}, ...interface{}) bool {returnisOrdered(, , []compareResult{compareLess, compareEqual}, "\"%v\" is not less than or equal to \"%v\"", ...)}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.