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

Ella
  • 21
  • 1
  • 4
  • How about adding parenthesis? Addition and subtraction are evaluated from left to right. With parenthesis you could force an evaluation from right to left. – Valerij Dobler Aug 29 '23 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. – Valerij Dobler Aug 29 '23 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 :( – Ella Aug 30 '23 at 07:54
  • Can you show the line of code in context? Is it in a finally block? – henry Aug 30 '23 at 17:20
  • I've added the line context...yes, my line is in a finally block, is that the reason of my problem? – Ella Sep 02 '23 at 09:45

0 Answers0