stryker-net icon indicating copy to clipboard operation
stryker-net copied to clipboard

LinqMutator support multiple mutations

Open C0DK opened this issue 3 years ago • 4 comments

More mutations for each linq expression.

I.e: First is not just mutated to FirstOrDefault, but also Last and Single.

Currently, you guys have a one-to-one mapping of possible mutations given a Linq expression. I realized that I had a few places where I used First but never tested what would happen if multiple values were returned. A mapping from first -> last would be nice. This, however, Is currently not possible with the way LinqMutator.cs is written. A nested loop would be a solution, but would naturally create more mutations (are we interested in that?) but it might catch more different cases...

C0DK avatar Jun 15 '22 08:06 C0DK

I'm open to extra Linq mutations, we do the same for Binary mutations. Could you think of more extra mutations that would add value? It would be nice to think of all mutations before anyone starts working on this

richardwerkman avatar Jun 15 '22 08:06 richardwerkman

I started adding the followings (but realized it would entail some refactorings, and wanted a greenlight from you guys):

  • First -> last
  • first -> single
  • last -> first
  • last -> single
  • single -> first
  • single -> last

(and all the same operations for the OrDefault variants.

I'm not sure if I have others, but if we/you Change the KindsToMutate to a Dictionary<LinqExpression, LinqExpression[]>, then I'll be easy to add additional ones, and I'll promise to open a PR if I realize some other case that would be fun.

C0DK avatar Jun 21 '22 04:06 C0DK

we need to evaluate the risk of un-killable mutations which are (often) linked to semantically equivalent code. In your examples, I am pretty sure that Single mutations will be un-killable: if Single returns a result, First and Last will. The only change will be when Single is used on an enumeration containing more than one item, it will throws, whereas First and Last will work. So Single seems not interesting to mutate, and if you do it, there is no benefit in trying both First and Last.

Mutating First and Last to Single is interesting, because if the mutant survives, the coder can either adjust its test to ensure there is more than one entry in its enumeration, or it can switch to Single if there is always a single entry. That being said, I suspect this mutant will often be killed simply because there is more than one entry in the enumeration.

dupdob avatar Jun 22 '22 15:06 dupdob

hmm true, that are good points.

C0DK avatar Jul 01 '22 03:07 C0DK