How to use cannotHandle method of org.evomaster.client.java.controller.internal.db.HeuristicsCalculator class

Best EvoMaster code snippet using org.evomaster.client.java.controller.internal.db.HeuristicsCalculator.cannotHandle

Source:HeuristicsCalculator.java Github

copy

Full Screen

...104 }105 if(exp instanceof RegExpMatchOperator){106 //TODO107 }108 return cannotHandle(exp);109 }110 private double computeBetween(Between between, DataRow data) {111 Instant start = getAsInstant(getValue(between.getBetweenExpressionStart(), data));112 Instant end = getAsInstant(getValue(between.getBetweenExpressionEnd(), data));113 Instant x = getAsInstant(getValue(between.getLeftExpression(), data));114 double after = computeComparison(x, start, new GreaterThanEquals());115 double before = computeComparison(x, end, new MinorThanEquals());116 return addDistances(after, before);117 }118 private double computeInExpression(InExpression exp, DataRow data) {119 //TODO can left be a list???120 ItemsList itemsList = exp.getRightItemsList();121 if (itemsList instanceof ExpressionList) {122 ExpressionList list = (ExpressionList) itemsList;123 if (exp.isNot()) {124 double max = 0;125 for (Expression element : list.getExpressions()) {126 ComparisonOperator op = new NotEqualsTo();127 op.setLeftExpression(exp.getLeftExpression());128 op.setRightExpression(element);129 double dist = computeComparisonOperator(op, data);130 if (dist > max) {131 max = dist;132 break; // no need to look at others, as no gradient133 }134 }135 return max;136 } else {137 double min = Double.MAX_VALUE;138 for (Expression element : list.getExpressions()) {139 ComparisonOperator op = new EqualsTo();140 op.setLeftExpression(exp.getLeftExpression());141 op.setRightExpression(element);142 double dist = computeComparisonOperator(op, data);143 if (dist < min) {144 min = dist;145 }146 }147 return min;148 }149 } else {150 return cannotHandle(exp);151 }152 }153 private double computeIsNull(IsNullExpression exp, DataRow data) {154 Object x = getValue(exp.getLeftExpression(), data);155 if (x == null && !exp.isNot()) {156 return 0d;157 }158 if (x != null && exp.isNot()) {159 return 0d;160 }161 return 1;162 }163 private double cannotHandle(Expression exp) {164 SimpleLogger.uniqueWarn("WARNING, cannot handle SQL expression type '" + exp.getClass().getSimpleName() +165 "' with value: " + exp.toString());166 return Double.MAX_VALUE;167 }168 private double computeAnd(AndExpression exp, DataRow data) {169 double a = computeExpression(exp.getLeftExpression(), data);170 double b = computeExpression(exp.getRightExpression(), data);171 return addDistances(a, b);172 }173 private double addDistances(double a, double b) {174 double sum = a + b;175 if (sum < Math.max(a, b)) {176 //overflow177 return Double.MAX_VALUE;178 } else {179 return sum;180 }181 }182 private double computeOr(OrExpression exp, DataRow data) {183 double a = computeExpression(exp.getLeftExpression(), data);184 double b = computeExpression(exp.getRightExpression(), data);185 return Math.min(a, b);186 }187 private Instant getAsInstant(Object obj){188 if(obj == null){189 /*190 TODO this shouldn't really happen if we have full SQL support, like sub-selects191 */192 return null;193 }194 if(obj instanceof Timestamp){195 Timestamp timestamp = (Timestamp) obj;196 return timestamp.toInstant();197 }198 if(obj instanceof String){199 try {200 return ZonedDateTime.parse(obj.toString()).toInstant();201 } catch (DateTimeParseException e){202 /*203 maybe it is in some weird format like 28-Feb-17...204 this shouldn't really happen, but looks like Hibernate generate SQL from205 JPQL with Date handled like this :(206 */207 DateTimeFormatter df = new DateTimeFormatterBuilder()208 // case insensitive to parse JAN and FEB209 .parseCaseInsensitive()210 // add pattern211 .appendPattern("dd-MMM-yy")212 // create formatter (use English Locale to parse month names)213 .toFormatter(Locale.ENGLISH);214 return LocalDate.parse(obj.toString(), df)215 .atStartOfDay().toInstant(ZoneOffset.UTC);216 }217 }218 SimpleLogger.warn("Cannot handle time value for class: " + obj.getClass());219 return null;220 }221 private double computeComparisonOperator(ComparisonOperator exp, DataRow data) {222 Object left = getValue(exp.getLeftExpression(), data);223 Object right = getValue(exp.getRightExpression(), data);224 if(left instanceof Timestamp || right instanceof Timestamp){225 Instant a = getAsInstant(left);226 Instant b = getAsInstant(right);227 if(a==null || b==null){228 return cannotHandle(exp);229 }230 return computeComparison(a, b, exp);231 }232 if (left instanceof Number && right instanceof Number) {233 double x = ((Number) left).doubleValue();234 double y = ((Number) right).doubleValue();235 return computerComparison(x, y, exp);236 }237 if (left instanceof String && right instanceof String) {238 return computeComparison(left.toString(), right.toString(), exp);239 }240 if (left instanceof Boolean && right instanceof Boolean) {241 return computeBooleanComparison((Boolean) left, (Boolean) right, exp);242 }243 if (left == null || right == null) {244 return computeNullComparison(left, right, exp);245 }246 return cannotHandle(exp);247 }248 private double computeComparison(Instant a, Instant b, ComparisonOperator exp) {249 if(a==null || b==null){250 return Double.MAX_VALUE;251 }252 double dif = - Duration.between(a,b).toMillis();253 return computerComparison(dif, exp);254 }255 private double computeBooleanComparison(boolean x, boolean y, ComparisonOperator exp) {256 if (!checkEqualOrNotOperator(exp)) {257 return cannotHandle(exp);258 }259 if (exp instanceof EqualsTo && x == y) {260 return 0d;261 }262 if (exp instanceof NotEqualsTo && x != y) {263 return 0d;264 }265 return 1d;266 }267 private boolean checkEqualOrNotOperator(ComparisonOperator exp) {268 return (exp instanceof EqualsTo) || (exp instanceof NotEqualsTo);269 }270 private double computeNullComparison(Object x, Object y, ComparisonOperator exp) {271 assert x == null || y == null;272 if (!checkEqualOrNotOperator(exp)) {273 return cannotHandle(exp);274 }275 if (exp instanceof EqualsTo && x == y) {276 return 0d;277 }278 if (exp instanceof NotEqualsTo && x != y) {279 return 0d;280 }281 return Double.MAX_VALUE;282 }283 private double computerComparison(double dif, ComparisonOperator exp) {284 if (exp instanceof EqualsTo) {285 return Math.abs(dif);286 } else if (exp instanceof GreaterThanEquals) {287 return dif >= 0 ? 0d : -dif;288 } else if (exp instanceof GreaterThan) {289 return dif > 0 ? 0d : 1d - dif;290 } else if (exp instanceof MinorThanEquals) {291 return dif <=0 ? 0d : dif;292 } else if (exp instanceof MinorThan) {293 return dif < 0 ? 0d : 1d + dif;294 } else if (exp instanceof NotEqualsTo) {295 return dif != 0 ? 0d : 1d;296 } else {297 return cannotHandle(exp);298 }299 }300 private double computerComparison(double x, double y, ComparisonOperator exp) {301 double dif = x - y;302 return computerComparison(dif, exp);303 }304 private double computeComparison(String a, String b, ComparisonOperator exp) {305 if (exp instanceof EqualsTo) {306 return DistanceHelper.getLeftAlignmentDistance(a, b);307 } else if (exp instanceof NotEqualsTo) {308 if (a.equals(b)) {309 return Double.MAX_VALUE;310 } else {311 return 0d;312 }313 } else {314 return cannotHandle(exp);315 }316 }317 private Object getValue(Expression exp, DataRow data) {318 //TODO all cases319 if (exp instanceof Column) {320 Column column = (Column) exp;321 String name = column.getColumnName();322 String table = context.getTableName(column);323 return data.getValueByName(name, table);324 } else if (exp instanceof Parenthesis) {325 return getValue(((Parenthesis) exp).getExpression(), data);326 } else if (exp instanceof LongValue) {327 return ((LongValue) exp).getValue();328 } else if (exp instanceof StringValue) {329 return ((StringValue) exp).getNotExcapedValue();330 } else if (exp instanceof NullValue) {331 return null;332 } else if (exp instanceof SignedExpression) {333 SignedExpression signed = (SignedExpression) exp;334 Object base = getValue(signed.getExpression(), data);335 if (signed.getSign() != '-') {336 return base;337 } else {338 if (base instanceof Long) {339 return -(Long) base;340 } else if (base instanceof Double) {341 return -(Double) base;342 } else if (base instanceof Float) {343 return -(Float) base;344 } else if (base instanceof Integer) {345 return -(Integer) base;346 } else {347 cannotHandle(exp);348 return null;349 }350 }351 } else {352 cannotHandle(exp);353 return null;354 }355 }356}...

Full Screen

Full Screen

cannotHandle

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseCommandDto2import org.evomaster.client.java.controller.api.dto.database.operations.InsertionDto3import org.evomaster.client.java.controller.api.dto.database.operations.SqlScriptDto4import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType5import org.evomaster.client.java.controller.api.dto.database.schema.DbSchemaDto6import org.evomaster.client.java.controller.api.dto.database.schema.TableDto7import org.evomaster.client.java.controller.api.dto.database.schema.TableIndexDto8import org.evomaster.client.java.controller.api.dto.database.schema.TableIndexType9import org.evomaster.client.java.controller.internal.db.heuristics.HeuristicsCalculator10import org.evomaster.client.java.controller.internal.db.heuristics.TableRow11import org.evomaster.client.java.controller.internal.db.heuristics.TableRowId12import org.evomaster.client.java.controller.internal.db.schema.SqlScriptRunner13import org.evomaster.client.java.controller.internal.db.schema.SqlScriptRunnerImpl14import org.evomaster.client.java.controller.internal.db.schema.SqlScriptWriter15import org.evomaster.client.java.controller.internal.db.schema.SqlScriptWriterImpl16import org.evomaster.client.java.controller.internal.db.schema.TableSchema17import org.evomaster.client.java.controller.internal.db.schema.TableSchemaImpl18import org.junit.jupiter.api.Assertions19import org.junit.jupiter.api.Test20class HeuristicsCalculatorTest {21 fun testCannotHandle() {22 val heuristicsCalculator = HeuristicsCalculator()23 Assertions.assertTrue(heuristicsCalculator.cannotHandle())24 heuristicsCalculator.tableSchemas = listOf(TableSchemaImpl("table1", listOf("table1_col1")))25 Assertions.assertTrue(heuristicsCalculator.cannotHandle())26 heuristicsCalculator.tableRows = listOf(TableRow(TableRowId("table1", listOf("1")), listOf("1")))27 Assertions.assertFalse(heuristicsCalculator.cannotHandle())28 }29}30 fun testAddTableSchemas() {31 val heuristicsCalculator = HeuristicsCalculator()

Full Screen

Full Screen

cannotHandle

Using AI Code Generation

copy

Full Screen

1def heuristic = new org.evomaster.client.java.controller.internal.db.HeuristicsCalculator()2def heuristicValue = heuristic.calculateHeuristicValue("SELECT * FROM customers WHERE customer_id = 1")3def canHandle = heuristic.cannotHandle(heuristicValue, threshold)4if(canHandle){5} else {6}7if(canHandle){8} else {9}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful