public void DoMutate_Returns_Correct_Replacements_For_Addition() { var assembly = CreateTestAssembly(OpCodes.Add); var addMethod = assembly.MainModule .Types.Single(t => t.Name == "TestClass") .Methods.Single(t => t.Name == "TestMethod"); string tempAssemblyFileName = GetTempAssemblyFileName(); assembly.Write(tempAssemblyFileName); var module = new Module(tempAssemblyFileName); var mutator = new ArithmeticOperatorTurtle(); IEnumerable<MutantMetaData> mutations = mutator .Mutate(addMethod, module, addMethod.Body.Instructions.Select(i => i.Offset).ToArray()); int sub = 0; int mul = 0; int div = 0; int rem = 0; int total = 0; foreach (var metaData in mutations) { total++; if (metaData.MethodDefinition.Body.Instructions.Any(i => i.OpCode == OpCodes.Sub)) sub++; if (metaData.MethodDefinition.Body.Instructions.Any(i => i.OpCode == OpCodes.Mul)) mul++; if (metaData.MethodDefinition.Body.Instructions.Any(i => i.OpCode == OpCodes.Div)) div++; if (metaData.MethodDefinition.Body.Instructions.Any(i => i.OpCode == OpCodes.Rem)) rem++; } Assert.AreEqual(4, total); Assert.AreEqual(1, sub); Assert.AreEqual(1, mul); Assert.AreEqual(1, div); Assert.AreEqual(1, rem); }
public void DoMutate_Returns_Correct_Replacements_For_Division_And_Describes_Appropriately() { var assembly = CreateTestAssembly(OpCodes.Div); var divideMethod = assembly.MainModule .Types.Single(t => t.Name == "TestClass") .Methods.Single(t => t.Name == "TestMethod"); string tempAssemblyFileName = GetTempAssemblyFileName(); assembly.Write(tempAssemblyFileName); var module = new Module(tempAssemblyFileName); var mutator = new ArithmeticOperatorTurtle(); IEnumerable<MutantMetaData> mutations = mutator .Mutate(divideMethod, module, divideMethod.Body.Instructions.Select(i => i.Offset).ToArray()); int add = 0; int sub = 0; int mul = 0; int rem = 0; int total = 0; foreach (var metaData in mutations) { total++; add += MatchReplacement(metaData, OpCodes.Div, OpCodes.Add); sub += MatchReplacement(metaData, OpCodes.Div, OpCodes.Sub); mul += MatchReplacement(metaData, OpCodes.Div, OpCodes.Mul); rem += MatchReplacement(metaData, OpCodes.Div, OpCodes.Rem); } Assert.AreEqual(4, total); Assert.AreEqual(1, add); Assert.AreEqual(1, sub); Assert.AreEqual(1, mul); Assert.AreEqual(1, rem); }