Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equivalent mutation on modulo operation involving integer literal #272

Open
deniciocode opened this issue Nov 14, 2014 · 1 comment
Open

Comments

@deniciocode
Copy link

The mutant changes variables in modulo calculations. E.G.

final_sum.modulo(10).zero?

will be changed into

final_sum.modulo(-10).zero?

I think on modulo it make no sense to check the negative part. Or do I make a mistake on using the modulo for mutant?

@mbj
Copy link
Owner

mbj commented Nov 14, 2014

@DenniJensen You did no mistake, and mutant did no mistake. You just found a case where the mutated semantics of a negated literal are the same as the original because of combination with the Fixnum#zero? operator. Summary: You found an equivalent mutant.

I can do something about this, but the decision is not easy and needs a bit of a wider scope.

One option would be to special case the mutation emitter to NOT emit literal negations in case the method selector is modulo inside another method call to zero?.

Problem is here: With just processing at the AST I do not know if Fixnum#modulo was called as receiver of Fixnum#zero? with skipping this specific mutation emit I might case blind spots that are valid for other cases. (Ruby does not tell me which exact objects are in use at the AST level). And I do not want to write a ruby interpreter for obvious reasons ;)

Another option would be to question if the mutation of integer literals to its negated version is actually a good mutation. I never saw an alive valid mutant where this mutation showed me a weak spot in my code / test. We currently do a series of mutations to integer literals that might already include the semantics of the negated version: https://github.com/mbj/mutant/blob/master/meta/int.rb.

Also you should have the option to ignore this specific mutation instance from your coverage analysis.. Mutant contains the code path for such exclusions but its right now not connected to the CLI or the (missing) configuration file.

I'll keep this ticket open till skipping specific mutation instances is possible, and or something other relevant to this behavior happens. And feel free to discuss this issue here.

@mbj mbj added the mutation label Nov 14, 2014
@mbj mbj changed the title Mutate modulo Equivalent mutation on modulo operation involving integer literal Nov 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants