# I'm unable to use assertion

**URL:** <https://discourse.julialang.org/t/im-unable-to-use-assertion/31563>\
**Category:** General Usage\
**Created:** [November 27, 2019, 7:58am UTC](https://discourse.julialang.org/t/im-unable-to-use-assertion/31563 "2019-11-27T07:58:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Post date:** [November 27, 2019, 7:58am UTC](https://discourse.julialang.org/t/im-unable-to-use-assertion/31563/1 "2019-11-27T07:58:35Z")

</div>

An `AssertionError` raises in my code, when i want to assert `count(!iszero,[1 3;2 2])`to be equal to zero: `@assert count(!iszero,[1 3;2 2])==0` but, everytime i do that the error occurs.  
Perhaps i can do:

```julia
a= count(!iszero,[1 3;2 2])
a=0
a==0

```

it will return `True`, but i don’t know if it’s the proper way to do that!!!

---

<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:** [November 27, 2019, 8:00am UTC](https://discourse.julialang.org/t/im-unable-to-use-assertion/31563/2 "2019-11-27T08:00:06Z")

</div>

Not sure what you are expecting, since

```julia
julia> count(!iszero,[1 3;2 2])
4

```

So basically you are doing

```julia
@assert 4 == 0

```

which will of course raise an error.

---

<div class="post-metadata">

**Author:** ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Post date:** [November 27, 2019, 8:06am UTC](https://discourse.julialang.org/t/im-unable-to-use-assertion/31563/3 "2019-11-27T08:06:59Z")

</div>

i want that first output because it will be used in other lines of the code, and after that i want to make that `count(!iszero,[1 3;2 2])==0` it’s like an initialization

---

<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:** [November 27, 2019, 8:46am UTC](https://discourse.julialang.org/t/im-unable-to-use-assertion/31563/4 "2019-11-27T08:46:57Z")

</div>

I have to admit that I don’t understand what you are trying to do here.

Are you sure you want assertions? If you are using the result of `count`, just save it in a variable.

---

<div class="post-metadata">

**Author:** ![tamasgal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamasgal/32/27946_2.png) [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Post date:** [November 27, 2019, 8:55am UTC](https://discourse.julialang.org/t/im-unable-to-use-assertion/31563/5 "2019-11-27T08:55:02Z")

</div>

I have the feeling you don’t understand what `@assert` does: it basically raises an error if the expression is not `true`. So it is not “asserting” that it “will be magically true” afterwards.

…but correct me if I am wrong 😉

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [November 27, 2019, 8:55am UTC](https://discourse.julialang.org/t/im-unable-to-use-assertion/31563/6 "2019-11-27T08:55:21Z")

</div>

I think that marouane1994 wants the code

count(!iszero,[1 3;2 2])

to return the value of zero everytime and assign the value of zero to another variable

I think he wants

```julia
function myassert(expr,value)
    idontcare = expr
    return idontcare == value ? idontcare : value
end

a = myassert( count(!iszero,[1 3;2 2]), 0 )

```

I think a smart compiler can optimise this away to

```julia
myassert(expr,value) = value

```
