0

I'm newbie with mutation testing. I'm using Pit and in the following line of code there are 4 mutations of the same type: Replaced long addition with subtraction long newsize = position + START_OF_DATA + total; But I can't figured out why he gaves me 4 mutations and not 3:

1 mutation:long newsize = position - START_OF_DATA + total;
2 mutation:long newsize = position + START_OF_DATA - total;
3 mutation:long newsize = position - START_OF_DATA - total;
4 mutation: ???

This is the context of the line:

try {
    fc.position(position + START_OF_DATA);
    while (buffs[buffs.length - 1].remaining() > 0) {
        long rc = fc.write(buffs);
        if (rc <= 0) {
            throw new IOException("Short write");
        }
        total += rc;
    }
} finally {
    fc.force(true);
    long newsize = position + START_OF_DATA + total;
    if (newsize > size) {
        size = newsize;
    }
}

I've also tried to manually modify the source code with this three supposed mutation and my test suite failed. Which one could be the fourth mutation? Is there a way to see in clear the mutations and not just the list with the original code reported in the pit report?

Thanks to all

5
  • How about adding parenthesis? Addition and subtraction are evaluated from left to right. With parenthesis you could force an evaluation from right to left. Commented Aug 29, 2023 at 21:30
  • Because of the commutativity of addition, there shouldn't be any difference. But with subtraction, you might arrive at different results considering edge cases. Commented Aug 29, 2023 at 21:32
  • I've tried long newsize = position - (START_OF_DATA + total); but it seems like long newsize = position - START_OF_DATA - total; anyway my test suite falied :( Commented Aug 30, 2023 at 7:54
  • Can you show the line of code in context? Is it in a finally block? Commented Aug 30, 2023 at 17:20
  • I've added the line context...yes, my line is in a finally block, is that the reason of my problem? Commented Sep 2, 2023 at 9:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.