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

Method InDelta

number.go:192–239  ·  view source on GitHub ↗

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

(value, delta float64)

Source from the content-addressed store, hash-verified

190// number := NewNumber(t, 123.0)
191// number.InDelta(123.2, 0.3)
192func (n *Number) InDelta(value, delta float64) *Number {
193 opChain := n.chain.enter("InDelta()")
194 defer opChain.leave()
195
196 if opChain.failed() {
197 return n
198 }
199
200 if math.IsNaN(delta) {
201 opChain.fail(AssertionFailure{
202 Type: AssertUsage,
203 Errors: []error{
204 errors.New("unexpected NaN delta argument"),
205 },
206 })
207 return n
208 }
209
210 if math.IsNaN(n.value) || math.IsNaN(value) {
211 opChain.fail(AssertionFailure{
212 Type: AssertEqual,
213 Actual: &AssertionValue{n.value},
214 Expected: &AssertionValue{value},
215 Delta: &AssertionValue{delta},
216 Errors: []error{
217 errors.New("expected: numbers are comparable"),
218 },
219 })
220 return n
221 }
222
223 diff := n.value - value
224
225 if diff < -delta || diff > delta {
226 opChain.fail(AssertionFailure{
227 Type: AssertEqual,
228 Actual: &AssertionValue{n.value},
229 Expected: &AssertionValue{value},
230 Delta: &AssertionValue{delta},
231 Errors: []error{
232 errors.New("expected: numbers lie within delta"),
233 },
234 })
235 return n
236 }
237
238 return n
239}
240
241// NotInDelta succeeds if two numerals are not within delta of each other.
242//

Callers 4

EqualDeltaMethod · 0.95
TestNumber_FailedChainFunction · 0.80
TestNumber_InDeltaFunction · 0.80
TestE2EReport_ValuesFunction · 0.80

Calls 4

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

Tested by 3

TestNumber_FailedChainFunction · 0.64
TestNumber_InDeltaFunction · 0.64
TestE2EReport_ValuesFunction · 0.64