blob: a1eae45f0089fa93627b42aadafb97b7993e9096 [file] [log] [blame]
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package assert
// OnInteger is the result of calling ThatInt on an Assertion.
// It provides numeric assertion tests.
type OnInteger struct {
Assertion
value int
}
// Equals asserts that the supplied integer is equal to the expected integer.
func (o OnInteger) Equals(expect int) bool {
return o.Assertion.test(o.value == expect, expected, o.value, expect)
}
// NotEquals asserts that the supplied integer is not equal to the test integer.
func (o OnInteger) NotEquals(test int) bool {
return o.Assertion.test(o.value != test, expected, o.value, "a non equal integer")
}
// IsAtLeast asserts that the integer is at least the supplied minimum.
func (o OnInteger) IsAtLeast(min int) bool {
return o.Assertion.test(o.value >= min, unmatched, o.value, "Was less than", min)
}
// IsAtMost asserts that the integer is at most the supplied maximum.
func (o OnInteger) IsAtMost(max int) bool {
return o.Assertion.test(o.value <= max, unmatched, o.value, "Was more than", max)
}
// IsBetween asserts that the integer lies within the given range (inclusive).
func (o OnInteger) IsBetween(min, max int) bool {
return o.Assertion.test(o.value >= min && o.value <= max,
"Got: %v\nWas not between %v and %v\n", o.value, min, max)
}