MCPcopy Create free account
hub / github.com/gavv/httpexpect / NotInDelta

Method NotInDelta

number.go:247–294  ·  view source on GitHub ↗

NotInDelta succeeds if two numerals are not within delta of each other. Example: number := NewNumber(t, 123.0) number.NotInDelta(123.2, 0.1)

(value, delta float64)

Source from the content-addressed store, hash-verified

245// number := NewNumber(t, 123.0)
246// number.NotInDelta(123.2, 0.1)
247func (n *Number) NotInDelta(value, delta float64) *Number {
248 opChain := n.chain.enter("NotInDelta()")
249 defer opChain.leave()
250
251 if opChain.failed() {
252 return n
253 }
254
255 if math.IsNaN(delta) {
256 opChain.fail(AssertionFailure{
257 Type: AssertUsage,
258 Errors: []error{
259 errors.New("unexpected NaN delta argument"),
260 },
261 })
262 return n
263 }
264
265 if math.IsNaN(n.value) || math.IsNaN(value) {
266 opChain.fail(AssertionFailure{
267 Type: AssertNotEqual,
268 Actual: &AssertionValue{n.value},
269 Expected: &AssertionValue{value},
270 Delta: &AssertionValue{delta},
271 Errors: []error{
272 errors.New("expected: numbers are comparable"),
273 },
274 })
275 return n
276 }
277
278 diff := n.value - value
279
280 if !(diff < -delta || diff > delta) {
281 opChain.fail(AssertionFailure{
282 Type: AssertNotEqual,
283 Actual: &AssertionValue{n.value},
284 Expected: &AssertionValue{value},
285 Delta: &AssertionValue{delta},
286 Errors: []error{
287 errors.New("expected: numbers do not lie within delta"),
288 },
289 })
290 return n
291 }
292
293 return n
294}
295
296// Deprecated: use InDelta instead.
297func (n *Number) EqualDelta(value, delta float64) *Number {

Callers 3

NotEqualDeltaMethod · 0.95
TestNumber_FailedChainFunction · 0.80
TestNumber_InDeltaFunction · 0.80

Calls 4

enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80

Tested by 2

TestNumber_FailedChainFunction · 0.64
TestNumber_InDeltaFunction · 0.64