Mutation Testing..Request for Mutation Method to change the order of array items
package com.teja.dsa.bbraces.test;
import com.teja.dsa.bbraces.BalancedBraces;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertEquals;
public final class TestBalancedBraces
{
@Test
final void testBalancedBraces()
{
final String[][] TEST_DATA_TRUE =
{
{"()", "single pair of parentheses"},
{"()()", "multiple pairs of parentheses"},
{"(())", "nested parentheses"},
{"{[()]}", "nested brackets and parentheses"},
{"{()[]}", "nested parentheses and square brackets"},
{null, "null value"},
{" == ", "== string"},
{" <(==\t\n \r)> ", "check the pair <>"},
{"", "empty string"},
{" \t\n \r ", "white space empty string"},
{" (\t\n \r) ", "white space with-in brackets"},
{" ()\t\n \r ", "braces first then white space suffix"},
{" (a+b)/2 ", "check chars"},
{" (1+3)*3 ", "check the numerals"},
{"[(){}]", "nested braces and brackets"},
{"([{}])", "nested parentheses, braces, and brackets"},
{"({[]})", "nested braces, brackets, and parentheses"},
{"'", "single quote"},
{"\"", "double quote"},
{"\"\"", "multiple pairs of double quotes"},
{"'\"'", "nested quotes"},
{"abc{123}def", "braces and ascii characters"},
{"{ab(cd)}", "braces and parentheses"},
{"abc123", "no braces or brackets"},
{"(a+b)*c/d-e", "has ANSI Chars and Arithmetic Operators"},
{"3*(2+4)/(1-5)", "has numbers and Arithmetic Operators"},
};
verify(TEST_DATA_TRUE, true);
}
@Test
final void testUnbalancedBraces()
{
final String[][] TEST_DATA_FALSE =
{
{"([)]", "mismatched parentheses and brackets, missing ]"},
{"3*(2+4)/(1-5]", "has numbers and Arithmetic Operators"},
{"{[}]", "mismatched brackets, missing ]"},
{"for (int i = 0; i < n; i++) {", "for loop, missing }"},
{"(", "unbalanced parentheses, missing )"},
{")", "unbalanced parentheses, missing ("},
{"((", "unbalanced parentheses, missing ))"},
{"}", "unbalanced curly braces"},
{"{", "unbalanced {"},
{"[]]", "mismatched square brackets missing ["},
{"[", "unbalanced, missing ]"},
{"]", "unbalanced, missing ["},
{"ac123", "no b matching to a"},
{"(a+b)*c/d-e]", "has ANSI Chars and Arithmetic Operators"},
};
verify(TEST_DATA_FALSE, false);
}
private final void verify(final String[][] aTestData, final boolean aExpected)
{
Arrays.stream(aTestData).forEach(bInput ->
{
assertEquals(aExpected,
new BalancedBraces().isBalanced(bInput[0]),
bInput[1]);
});
}
}
I want to all the true test data to be added to false testdata and make sure mutation is caught..and reverse too also, even in test or false test data, I want the order of data items to change, which should not impact the test validity etc..
Is there any mutation to suit my need, if not, can any guide me to write one myself, please..
BalancedBraces bb = new BalancedBraces()
private final void verify(final String[][] aTestData, final boolean aExpected)
{
Arrays.stream(aTestData).forEach(bInput ->
{
assertEquals(aExpected,
bb .isBalanced(bInput[0]),
bInput[1]);
});
}
when verify is changed to bb as one time instantiated object, I want to make sure any object data across multiple isBalanced() method call should not give the test cases different results.. hence asking for an order change of the TEST_DATA..
This is fundamentally not how mutation testing works. Changes are made to the production code, not the tests.
Thank You for the clarification hcoles.
May be a new Scope for mutation testing of test test cases resilience too.. please think if such feature can be brought out without impacting current thought process, as bugs could be there in testcases too that is shielding main code bugs..
It just happened to me today
my same testcases were behaving differently when I made new BalancedBraces() part of @BeforeEach, as test class object variable, as for loop variable varify method variable etc...
In any case, I leave it you to consider if some thing can be done to expose such bugs specially related to testcase variations in future may be another framework all together..
package com.tejasoft.dsa.bbraces.test;
import com.tejasoft.dsa.bbraces.BalancedBraces;
import com.tejasoft.test.aspects.AssertionsCounterAspect;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(AssertionsCounterAspect.class)
public final class TestBalancedBraces
{
private final static BalancedBraces csBalancedBraces = new BalancedBraces();
private static BalancedBraces baBalancedBraces;
private final BalancedBraces iBalancedBraces = new BalancedBraces();
private BalancedBraces beBalancedBraces;
@BeforeEach
void beforeEachInit()
{
beBalancedBraces = new BalancedBraces();
}
@Test
final void testBalancedBraces()
{
final String[][] TEST_DATA_TRUE =
{
{"()", "single pair of parentheses"},
{"()()", "multiple pairs of parentheses"},
{"(())", "nested parentheses"},
{"{[()]}", "nested brackets and parentheses"},
{"{()[]}", "nested parentheses and square brackets"},
{null, "null value"},
{" == ", "== string"},
{" <(==\t\n \r)> ", "check the pair <>"},
{"", "empty string"},
{" \t\n \r ", "white space empty string"},
{" (\t\n \r) ", "white space with-in brackets"},
{" ()\t\n \r ", "braces first then white space suffix"},
{" (a+b)/2 ", "check chars"},
{" (1+3)*3 ", "check the numerals"},
{"[(){}]", "nested braces and brackets"},
{"([{}])", "nested parentheses, braces, and brackets"},
{"({[]})", "nested braces, brackets, and parentheses"},
{"'", "single quote"},
{"(([{abc}]))", "chatGPT"},
{"\"", "double quote"},
{"\"\"", "multiple pairs of double quotes"},
{"'\"'", "nested quotes"},
{"abc{123}def", "braces and ascii characters"},
{"{ab(cd)}", "braces and parentheses"},
{"abc123", "no braces or brackets"},
{"(a+b)*c/d-e", "has ANSI Chars and Arithmetic Operators"},
{"3*(2+4)/(1-5)", "has numbers and Arithmetic Operators"},
};
verify(TEST_DATA_TRUE, true);
}
@Test
final void testUnbalancedBraces()
{
final String[][] TEST_DATA_FALSE =
{
{"([)]", "mismatched parentheses and brackets, missing ]"},
{"3*(2+4)/(1-5]", "has numbers and Arithmetic Operators"},
{"{[}]", "mismatched brackets, missing ]"},
{"for (int i = 0; i < n; i++) {", "for loop, missing }"},
{"(", "unbalanced parentheses, missing )"},
{")", "unbalanced parentheses, missing ("},
{"((", "unbalanced parentheses, missing ))"},
{"([{abc])}", "chatGPT"},
{"}", "unbalanced curly braces"},
{"{", "unbalanced {"},
{"))))", "unbalanced {"},
{"{[()]}(])", "unbalanced for closing braces given by chatGPT"},
{"[]]", "mismatched square brackets missing ["},
{"[", "unbalanced, missing ]"},
{"]", "unbalanced, missing ["},
{"ac123", "no b matching to a"},
{"(a+b)*c/d-e]", "has ANSI Chars and Arithmetic Operators"},
};
verify(TEST_DATA_FALSE, false);
}
@Test
final void testFalseThenTrueBalancedBraces()
{
final String[][] TEST_DATA_FALSE =
{
{"([)]", "mismatched parentheses and brackets, missing ]"},
{"3*(2+4)/(1-5]", "has numbers and Arithmetic Operators"},
};
verify(TEST_DATA_FALSE, false);
assertTrue(beBalancedBraces.isBalanced("3*(2+4)/(1-5)"));
verify(TEST_DATA_FALSE, false);
}
@Test
final void testTrueThenFalseBalancedBraces()
{
final String[][] TEST_DATA_TRUE =
{
{"()", "single pair of parentheses"},
{"()()", "multiple pairs of parentheses"},
{"(())", "nested parentheses"},
{"{[()]}", "nested brackets and parentheses"},
};
verify(TEST_DATA_TRUE, true);
assertFalse(beBalancedBraces.isBalanced("3*(2+4)/(1-5]"));
verify(TEST_DATA_TRUE, true);
}
private final void verify(final String[][] aTestData, final boolean aExpected)
{
final BalancedBraces lBalancedBraces = new BalancedBraces();
for (String[] bInput : aTestData)
{
final BalancedBraces[] kindsOfInstances =
{
csBalancedBraces,
baBalancedBraces,
iBalancedBraces,
beBalancedBraces,
lBalancedBraces,
new BalancedBraces()
};
for (BalancedBraces bVariousInstance : kindsOfInstances)
{
assertEquals(aExpected,
bVariousInstance.isBalanced(bInput[0]),
bInput[1]);
}
}
}
@BeforeAll
static void beforeAllInit()
{
baBalancedBraces = new BalancedBraces();
}
}
Modified code, that mutation testing could have variations in testcases.. documenting for reference.. in case mutation testing also considered for testcases any time future.
kindsOfInstances variations of BalancedBraces instances is the key mutation