# Previously tested code is already covered

**URL:** https://discourse.julialang.org/t/previously-tested-code-is-already-covered/9514
**Category:** Internals & Design
**Tags:** proposal
**Created:** [March 5, 2018, 4:56pm UTC](https://discourse.julialang.org/t/previously-tested-code-is-already-covered/9514 "2018-03-05T16:56:01Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [March 5, 2018, 4:56pm UTC](https://discourse.julialang.org/t/previously-tested-code-is-already-covered/9514/1 "2018-03-05T16:56:02Z")

</div>

Say I wrote a function:

```julia
f(x::Float64) = sin(x) + 2

```

In terms of CI and test coverage, the code of this function has already been covered elsewhere (in `Base`). Shouldn’t it be possible for the CI process to “discover” that and mark it as (at least indirectly) tested? Or is this science fiction?

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [March 5, 2018, 4:59pm UTC](https://discourse.julialang.org/t/previously-tested-code-is-already-covered/9514/2 "2018-03-05T16:59:36Z")

</div>

> [@yakir12](#):
>
> the code of this function has already been covered elsewhere (in Base)

Everything boils down to a few assembler instructions in the end which are all “covered” just by building Julia. So we don’t have to test anything?

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [March 5, 2018, 5:02pm UTC](https://discourse.julialang.org/t/previously-tested-code-is-already-covered/9514/3 "2018-03-05T17:02:32Z")

</div>

I’m assuming there is a continuum from impossible to automate to my example above. In the first case, automated tests would be a bad idea, but in the second case the automation wouldn’t do a worse job than what I’d be able to accomplish.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [March 5, 2018, 5:06pm UTC](https://discourse.julialang.org/t/previously-tested-code-is-already-covered/9514/4 "2018-03-05T17:06:54Z")

</div>

The fact that `sin(x)` `+` and `2` work individually doesn’t mean the behavior you get by composing them is what you want and that you didn’t accidentally introduce a bug here.  
To make an analogy, even if you use perfect bricks, mortar, and wood, you can still make a bad house.

Presumably, you created `f` to have some “higher” purpose, that is what we want to test.

---

<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: [March 5, 2018, 5:24pm UTC](https://discourse.julialang.org/t/previously-tested-code-is-already-covered/9514/5 "2018-03-05T17:24:40Z")

</div>

> [@yakir12](#):
>
> automation wouldn’t do a worse job than what I’d be able to accomplish

How would it know what `f` is supposed to do? Eg it could be that the “correct” function is `f(x) = sin(x) - 2`.

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [March 5, 2018, 5:51pm UTC](https://discourse.julialang.org/t/previously-tested-code-is-already-covered/9514/6 "2018-03-05T17:51:49Z")

</div>

> [@Tamas\_Papp](#):
>
> How would it know what f is supposed to do

No idea. I thought it would be possible to see that `f` is equal to the sinus of `x` plus two. Decompose it to units of code that have already been tested. But it sounds like that it would either be impossible or unwise.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [March 5, 2018, 6:12pm UTC](https://discourse.julialang.org/t/previously-tested-code-is-already-covered/9514/7 "2018-03-05T18:12:46Z")

</div>

> [@yakir12](#):
>
> No idea. I thought it would be possible to see that f is equal to the sinus of x plus two.

Sure, but how would the computer know that is the right thing. You are the only one who knows what higher level behavior you want from the function.

---

<div class="post-metadata">

### Author: ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)
#### Post date: [March 5, 2018, 6:13pm UTC](https://discourse.julialang.org/t/previously-tested-code-is-already-covered/9514/8 "2018-03-05T18:13:05Z")

</div>

The point is that when writing tests for `f` it’s not only important that it runs, but also that it does what you want it to.

```julia
f(x::Int32) = "You're on a"*" 64bit system"
f(x::Int64) = "You're on a"*" 32bit system"

```

We know that string concatenation works, so the two functions would be covered by base tests, but it’s probably giving you the wrong result.

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [March 5, 2018, 6:48pm UTC](https://discourse.julialang.org/t/previously-tested-code-is-already-covered/9514/9 "2018-03-05T18:48:13Z")

</div>

> [@pkofod](#):
>
> f(x::Int32) = “You’re on a”_" 64bit system"  
> f(x::Int64) = “You’re on a”_" 32bit system"

Now I get it. For some reason _this_ really explained it to me. Thanks!
