sckott / mutant

mutation testing for R
https://sckott.github.io/mutant/
Other
16 stars 2 forks source link

Option 1: Fix loop that goes out of bounds #14

Closed devarops closed 4 years ago

devarops commented 4 years ago

The i in the while loop in mutate some times gets bigger than the length of x. That is a problem in this line:

x[[i]] <- mutate_one(x[[i]])

since it produces this error:

Error in x[[i]] : subscript out of bounds
codecov-commenter commented 4 years ago

Codecov Report

Merging #14 into master will decrease coverage by 0.12%. The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #14      +/-   ##
==========================================
- Coverage   16.15%   16.03%   -0.13%     
==========================================
  Files          12       12              
  Lines         130      131       +1     
==========================================
  Hits           21       21              
- Misses        109      110       +1     
Impacted Files Coverage Δ
R/mutate.R 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update aa011ef...76eadee. Read the comment docs.

sckott commented 4 years ago

thanks!

I wonder if instead we might want mutate() to fail if it doesn't create a mutation in any of the functions? That is, if i gets bigger than the length of x, then we've gone through all the elements of x, correct? Then I imagine we'd just want to stop() saying that we couldn't create a mutation?

devarops commented 4 years ago

if i gets bigger than the length of x, then we've gone through all the elements of x, correct?

Yes, but mutate_one() randomly tries [using astr::ast_modify(..., if_many = "random")] a different mutation for each element of x. In the second round, mutate_one will most likely choose a different mutation for the first (and each) element of x. In randgeo, the example that you are using, mutate() succeeds in the first or second round (after going through all the elements of x once). This is the current implementation of mutate().

In an alternative implementation of mutate(), we could use the first mutation for each element of x and then use the second mutation for each element of x, and so on. In that case, we would want mutate() to fail (stop()) if it doesn't create a mutant in any of the functions after systematically trying each mutation.

Which method do you prefer?

This PR solves an issue if you choose to randomly try a mutation for each function

We would have to change the implementation of mutate() if you chose to systematically try each mutation for each function

devarops commented 4 years ago

I have updated this PR adding a break.

sckott commented 4 years ago

Let's stick with random for now.

devarops commented 4 years ago

Great!