Program: 61489
Project: 61489
Buggy source:
/** 
 * This test uses a new ingredient space specially created to manage expressions.
 * @throws Exception
 */
@Test public void testM70ExpressionAdaptation() throws Exception {
  CommandSummary command=MathTests.getMath70Command();
  command.command.put("String_Node_Str",ExtensionPoints.INGREDIENT_PROCESSOR.identifier + File.pathSeparator + ExpressionIngredientSpaceProcessor.class.getCanonicalName()+ File.pathSeparator+ ExtensionPoints.INGREDIENT_TRANSFORM_STRATEGY.identifier+ File.pathSeparator+ InScopeVarsTransformation.class.getCanonicalName());
  command.command.put("String_Node_Str","String_Node_Str");
  command.command.put("String_Node_Str",ExpressionReplaceOperator.class.getName());
  command.command.put("String_Node_Str",ExpressionIngredientSpace.class.getName());
  command.command.put("String_Node_Str","String_Node_Str");
  AstorMain main1=new AstorMain();
  main1.execute(command.flat());
  List<ProgramVariant> variantss=main1.getEngine().getVariants();
  assertTrue(variantss.size() > 0);
  JGenProg engine=(JGenProg)main1.getEngine();
  ModificationPoint modificationPoint=variantss.get(0).getModificationPoints().get(14);
  assertEquals("String_Node_Str",modificationPoint.getCodeElement().toString());
  ExpressionIngredientSpace ingredientSpace=(ExpressionIngredientSpace)engine.getIngredientStrategy().getIngredientSpace();
  assertNotNull(ingredientSpace);
  assertTrue(ExpressionIngredientSpace.class.isInstance(ingredientSpace));
  log.debug("String_Node_Str" + ingredientSpace.getAllIngredients());
  OperatorInstance opInstance=engine.createOperatorInstanceForPoint(modificationPoint);
  List<CtCodeElement> ingredients=ingredientSpace.getIngredients(opInstance.getOriginal(),ExpressionReplaceOperator.class.getName());
  log.debug("String_Node_Str" + ingredients);
  CtCodeElement ingredientTargeted=ingredients.get(4);
  assertEquals("String_Node_Str",ingredientTargeted.toString());
  IngredientTransformationStrategy transfStrategy=engine.getIngredientTransformationStrategy();
  assertNotNull(transfStrategy);
  assertTrue(InScopeVarsTransformation.class.isInstance(transfStrategy));
  InScopeVarsTransformation inScopeStrategy=(InScopeVarsTransformation)transfStrategy;
  VarMapping mapping=VariableResolver.mapVariablesFromContext(modificationPoint.getContextOfModificationPoint(),ingredientTargeted);
  List<CtVariable> variablesMapped=mapping.getMappedVariables().values().iterator().next();
  assertNotNull(variablesMapped);
  assertEquals(4,variablesMapped.size());
  List<Ingredient> transformedIngredients=inScopeStrategy.transform(modificationPoint,new Ingredient(ingredientTargeted));
  log.debug("String_Node_Str" + transformedIngredients);
  assertEquals(4,transformedIngredients.size());
  for (  CtVariable ctVariableInScope : variablesMapped) {
    boolean ingredientTransformedHasVarInScope=false;
    for (    Ingredient ingredient : transformedIngredients) {
      System.out.println(String.format("String_Node_Str",ingredient.getCode().toString(),(ctVariableInScope.getSimpleName())));
      if (ingredient.getCode().toString().contains(ctVariableInScope.getSimpleName())) {
        ingredientTransformedHasVarInScope=true;
        break;
      }
    }
    assertTrue(ingredientTransformedHasVarInScope);
  }
}

Fixed version (ground truth):
/** 
 * This test uses a new ingredient space specially created to manage expressions.
 * @throws Exception
 */
@Test public void testM70ExpressionAdaptation() throws Exception {
  CommandSummary command=MathTests.getMath70Command();
  command.command.put("String_Node_Str",ExtensionPoints.INGREDIENT_PROCESSOR.identifier + File.pathSeparator + ExpressionIngredientSpaceProcessor.class.getCanonicalName()+ File.pathSeparator+ ExtensionPoints.INGREDIENT_TRANSFORM_STRATEGY.identifier+ File.pathSeparator+ InScopeVarsTransformation.class.getCanonicalName());
  command.command.put("String_Node_Str","String_Node_Str");
  command.command.put("String_Node_Str",ExpressionReplaceOperator.class.getName());
  command.command.put("String_Node_Str",ExpressionIngredientSpace.class.getName());
  command.command.put("String_Node_Str","String_Node_Str");
  AstorMain main1=new AstorMain();
  main1.execute(command.flat());
  List<ProgramVariant> variantss=main1.getEngine().getVariants();
  assertTrue(variantss.size() > 0);
  JGenProg engine=(JGenProg)main1.getEngine();
  ModificationPoint modificationPoint=variantss.get(0).getModificationPoints().get(14);
  assertEquals("String_Node_Str",modificationPoint.getCodeElement().toString());
  ExpressionIngredientSpace ingredientSpace=(ExpressionIngredientSpace)engine.getIngredientStrategy().getIngredientSpace();
  assertNotNull(ingredientSpace);
  assertTrue(ExpressionIngredientSpace.class.isInstance(ingredientSpace));
  log.debug("String_Node_Str" + ingredientSpace.getAllIngredients());
  OperatorInstance opInstance=engine.createOperatorInstanceForPoint(modificationPoint);
  List<CtCodeElement> ingredients=ingredientSpace.getIngredients(opInstance.getOriginal(),ExpressionReplaceOperator.class.getName());
  log.debug("String_Node_Str" + ingredients);
  CtCodeElement ingredientTargeted=ingredients.get(4);
  assertEquals("String_Node_Str",ingredientTargeted.toString());
  IngredientTransformationStrategy transfStrategy=engine.getIngredientTransformationStrategy();
  assertNotNull(transfStrategy);
  assertTrue(InScopeVarsTransformation.class.isInstance(transfStrategy));
  InScopeVarsTransformation inScopeStrategy=(InScopeVarsTransformation)transfStrategy;
  VarMapping mapping=VariableResolver.mapVariablesFromContext(modificationPoint.getContextOfModificationPoint(),ingredientTargeted);
  List<CtVariable> variablesMapped=mapping.getMappedVariables().values().iterator().next();
  assertNotNull(variablesMapped);
  assertEquals(4,variablesMapped.size());
  List<Ingredient> transformedIngredients=inScopeStrategy.transform(modificationPoint,new Ingredient(ingredientTargeted));
  log.debug("String_Node_Str" + transformedIngredients);
  assertEquals(4,transformedIngredients.size());
  for (  CtVariable ctVariableInScope : variablesMapped) {
    boolean ingredientTransformedHasVarInScope=false;
    for (    Ingredient ingredient : transformedIngredients) {
      System.out.println(String.format("String_Node_Str",ingredient.getCode().toString(),(ctVariableInScope.getSimpleName())));
      if (ingredient.getCode().toString().contains(ctVariableInScope.getSimpleName())) {
        ingredientTransformedHasVarInScope=true;
        break;
      }
    }
    assertTrue(ingredientTransformedHasVarInScope);
  }
  List<OperatorInstance> operatorsCreated=new ArrayList<>();
  for (int i=0; i < 10; i++) {
    log.debug("String_Node_Str" + i);
    OperatorInstance opi=engine.createOperatorInstanceForPoint(modificationPoint);
    operatorsCreated.add(opi);
  }
  log.debug("String_Node_Str" + operatorsCreated);
  for (  OperatorInstance operatorInstance : operatorsCreated) {
    log.debug("String_Node_Str" + operatorInstance);
  }
  List<String> ingredientsUsed=operatorsCreated.stream().map(OperatorInstance::getModified).map(CtElement::toString).distinct().collect(Collectors.toList());
  log.debug("String_Node_Str".format("String_Node_Str",ingredientsUsed.size(),ingredientsUsed));
  assertEquals(operatorsCreated.size(),ingredientsUsed.size());
}