# Test: absolute tolerance for vectors

**URL:** https://discourse.julialang.org/t/test-absolute-tolerance-for-vectors/20776
**Category:** General Usage
**Tags:** testing
**Created:** [February 14, 2019, 5:36am UTC](https://discourse.julialang.org/t/test-absolute-tolerance-for-vectors/20776 "2019-02-14T05:36:04Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mopg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mopg/32/3368_2.png) [@mopg](https://discourse.julialang.org/u/mopg)
#### Post date: [February 14, 2019, 5:36am UTC](https://discourse.julialang.org/t/test-absolute-tolerance-for-vectors/20776/1 "2019-02-14T05:36:04Z")

</div>

Does anyone know how tolerances are computed for vectors in the Base.Test environment? I’m seeing some behavior that I can’t fully explain, see below.

```julia
using Test

a = rand(10) * 1e-4

@test a ≈ zeros(size(a)) atol=1e-4

```

Which returns:

```julia
Test Failed at REPL[16]:1
  Expression: ≈(a, zeros(size(a)), atol=0.0001)
   Evaluated: [7.34438e-5, 1.48842e-5, 1.86573e-5, 3.26998e-5, 6.13959e-5, 4.73754e-5, 3.91773e-5, 6.14291e-5, 7.24425e-6, 4.73723e-5] ≈ [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] (atol=0.0001)

```

To me it seems like that test should have passed? Any ideas?

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [February 14, 2019, 6:01am UTC](https://discourse.julialang.org/t/test-absolute-tolerance-for-vectors/20776/2 "2019-02-14T06:01:01Z")

</div>

> [@mopg](#):
>
> Does anyone know how tolerances are computed for vectors in the Base.Test environment?

See the documentation, eg `?isapprox` in the REPL. In particular,

> `x` and `y` may also be arrays of numbers, in which case `norm` defaults to the usual  
> `norm` function in LinearAlgebra, but may be changed by passing a `norm::Function` keyword argument. (For numbers, `norm` is the same thing as `abs`.) When `x` and `y` are arrays, if `norm(x-y)` is not finite (i.e. `±Inf` or `NaN`), the comparison falls back to checking whether all elements of `x` and `y` are approximately equal component-wise.
