# Odd counts from code coverage on 0.7/1.0

**URL:** https://discourse.julialang.org/t/odd-counts-from-code-coverage-on-0-7-1-0/13398
**Category:** General Usage
**Created:** [August 13, 2018, 6:14pm UTC](https://discourse.julialang.org/t/odd-counts-from-code-coverage-on-0-7-1-0/13398 "2018-08-13T18:14:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![alee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alee/32/2954_2.png) [@alee](https://discourse.julialang.org/u/alee)
#### Post date: [August 13, 2018, 6:14pm UTC](https://discourse.julialang.org/t/odd-counts-from-code-coverage-on-0-7-1-0/13398/1 "2018-08-13T18:14:48Z")

</div>

Probably not very important, but code coverage is giving slightly odd results on 1.0 (and 0.7) in comparison to 0.6. Does anyone know why? Consider

```julia
function foo(array::Vector{Float64})
  v = 0.0
  for i in 1:length(array)
    if mod(i, 10) != 0
      v += array[i]
    else
      v -= array[i]
    end
  end
  return v
end

foo(fill(1.0, 10000))

```

The .cov file produced by `julia --code-coverage=user` on 0.6 gives

```julia
        - function foo(array::Vector{Float64})
        1 v = 0.0
        1 for i in 1:length(array)
    10000 if mod(i, 10) != 0
     9000 v += array[i]
        - else
     1000 v -= array[i]
        - end
        - end
        1 return v
        - end
        - 
        - foo(fill(1.0, 10000))
        - 

```

as expected. But on 0.7/1.0 it gives

```julia
        - function foo(array::Vector{Float64})
        1 v = 0.0
        1 for i in 1:length(array)
    10000 if mod(i, 10) != 0
     9000 v += array[i]
        - else
    20000 v -= array[i]
        - end
        - end
        1 return v
        - end
        - 
        - foo(fill(1.0, 10000))
        - 

```

If the != is changed to ==, then the count for the if statement is correct (1000) but the count for the else statement is still 20000.

---

<div class="post-metadata">

### Author: ![alee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alee/32/2954_2.png) [@alee](https://discourse.julialang.org/u/alee)
#### Post date: [August 13, 2018, 6:19pm UTC](https://discourse.julialang.org/t/odd-counts-from-code-coverage-on-0-7-1-0/13398/2 "2018-08-13T18:19:35Z")

</div>

Running with `--inline=no` gives the right counts. So I guess this has something to do with optimization.

---

<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 8, 2018, 7:33am UTC](https://discourse.julialang.org/t/odd-counts-from-code-coverage-on-0-7-1-0/13398/3 "2018-11-08T07:33:54Z")

</div>

Recently I am getting very low coverage for some packages on Travis, for some packages it dropped from 90% to 50%. I wonder if this is related, or some recent change.

---

<div class="post-metadata">

### Author: ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)
#### Post date: [November 8, 2018, 8:16am UTC](https://discourse.julialang.org/t/odd-counts-from-code-coverage-on-0-7-1-0/13398/4 "2018-11-08T08:16:14Z")

</div>

Have seen something similar:

- [Codecov](https://codecov.io/gh/JuliaGPU/CuArrays.jl)
- [Codecov](https://codecov.io/gh/JuliaGPU/GPUArrays.jl)
- [Codecov](https://codecov.io/gh/JuliaGPU/CUDAnative.jl)

10/25 seems to have been the date where things changed.  
[https://github.com/JuliaCI/Coverage.jl/issues/187](https://github.com/JuliaCI/Coverage.jl/issues/187)
