
com.ecfeed.core.model.ValueCondition Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ecfeed.junit Show documentation
Show all versions of ecfeed.junit Show documentation
An open library used to connect to the ecFeed service. It can be also used as a standalone testing tool. It is integrated with Junit5 and generates a stream of test cases using a selected algorithm (e.g. Cartesian, N-Wise). There are no limitations associated with the off-line version but the user cannot access the on-line computation servers and the model database.
The newest version!
/*******************************************************************************
*
* Copyright (c) 2016 ecFeed AS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*******************************************************************************/
package com.ecfeed.core.model;
import java.util.ArrayList;
import java.util.List;
import com.ecfeed.core.utils.EMathRelation;
import com.ecfeed.core.utils.EvaluationResult;
import com.ecfeed.core.utils.JavaTypeHelper;
import com.ecfeed.core.utils.MessageStack;
import com.ecfeed.core.utils.RangeHelper;
import com.ecfeed.core.utils.RelationMatcher;
import com.ecfeed.core.utils.StringHelper;
public class ValueCondition implements IStatementCondition {
private String fRightValue;
private RelationStatement fParentRelationStatement;
public ValueCondition(String rightValue, RelationStatement parentRelationStatement) {
fRightValue = rightValue;
fParentRelationStatement = parentRelationStatement;
}
@Override
public EvaluationResult evaluate(List choices) {
String substituteType = ConditionHelper.getSubstituteType(fParentRelationStatement);
String leftChoiceStr = getChoiceString(choices, fParentRelationStatement.getLeftParameter());
if (leftChoiceStr == null) {
return EvaluationResult.INSUFFICIENT_DATA;
}
EMathRelation relation = fParentRelationStatement.getRelation();
boolean isRandomizedChoice =
StatementConditionHelper.getChoiceRandomized(
choices, fParentRelationStatement.getLeftParameter());
if(isRandomizedChoice) {
if(JavaTypeHelper.isStringTypeName(substituteType)) {
return EvaluationResult.TRUE;
}
else {
boolean result = RangeHelper.isRightRangeInLeftRange(leftChoiceStr, fRightValue, relation, substituteType);
return EvaluationResult.convertFromBoolean(result);
}
}
if (RelationMatcher.isMatchQuiet(relation, substituteType, leftChoiceStr, fRightValue)) {
return EvaluationResult.TRUE;
}
return EvaluationResult.FALSE;
}
@Override
public boolean isAmbiguous(List> domain, MessageStack messageStack) {
String substituteType = ConditionHelper.getSubstituteType(fParentRelationStatement);
int leftParameterIndex = fParentRelationStatement.getLeftParameter().getMyIndex();
List choicesForParameter = domain.get(leftParameterIndex);
EMathRelation relation = fParentRelationStatement.getRelation();
for (ChoiceNode choice : choicesForParameter) {
if (choice.isRandomizedValue()) {
if (ConditionHelper.isRandomizedChoiceAmbiguous(
choice, fRightValue, fParentRelationStatement,
relation, substituteType)) {
ConditionHelper.addValuesMessageToStack(
choice.toString(), relation, "value [" + fRightValue + "]", messageStack);
return true;
}
}
}
return false;
}
private static String getChoiceString(List choices, MethodParameterNode methodParameterNode) {
ChoiceNode choiceNode = StatementConditionHelper.getChoiceForMethodParameter(choices, methodParameterNode);
if (choiceNode == null) {
return null;
}
return choiceNode.getValueString();
}
@Override
public boolean adapt(List values) {
return false;
}
@Override
public ValueCondition getCopy() {
return new ValueCondition(new String(fRightValue), fParentRelationStatement);
}
@Override
public boolean updateReferences(MethodNode methodNode) {
return true;
}
@Override
public Object getCondition(){
return fRightValue;
}
@Override
public boolean compare(IStatementCondition otherCondition) {
if (!(otherCondition instanceof ValueCondition)) {
return false;
}
ValueCondition otherValueCondition = (ValueCondition)otherCondition;
if (fParentRelationStatement.getRelation() != otherValueCondition.fParentRelationStatement.getRelation()) {
return false;
}
if (!StringHelper.isEqual(fRightValue, otherValueCondition.fRightValue)) {
return false;
}
return true;
}
@Override
public Object accept(IStatementVisitor visitor) throws Exception {
return visitor.visit(this);
}
@Override
public String toString() {
return fRightValue;
}
@Override
public boolean mentions(MethodParameterNode methodParameterNode) {
return false;
}
public String getRightValue() {
return fRightValue;
}
@Override
public List getListOfChoices() {
return new ArrayList();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy