How to use getHeuristicToLocalTimeWithoutSecondsParsing method of org.evomaster.client.java.instrumentation.coverage.methodreplacement.DateTimeParsingUtils class

Best EvoMaster code snippet using org.evomaster.client.java.instrumentation.coverage.methodreplacement.DateTimeParsingUtils.getHeuristicToLocalTimeWithoutSecondsParsing

Source:DateTimeParsingUtils.java Github

copy

Full Screen

...26 *27 * @param input28 * @return29 */30 private static double getHeuristicToLocalTimeWithoutSecondsParsing(CharSequence input) {31 Objects.requireNonNull(input);32 return getHeuristicToLocalTimeWithSecondsParsing(input + ":00");33 }34 /**35 * returns how close the input was to HH:MM:SS. If the input36 * fails to parse, then the heuristic only considers hours in the range37 * 00 to 19.38 *39 * @param input40 * @return41 */42 private static double getHeuristicToLocalTimeWithSecondsParsing(CharSequence input) {43 Objects.requireNonNull(input);44 try {45 /*46 due to the simplification later on (i.e. not all valid local dates47 are considered, only a subrange), still must make sure to get a 148 if no exception is thrown49 */50 LocalTime.parse(input);51 return H_PARSED_OK;52 } catch (DateTimeParseException ex) {53 return getHeuristicToLocalTimeWithSeconds(input);54 }55 }56 /**57 * Returns the approximate (i.e. simplified) heuristic value for a string58 * to the format HH:MM:SS.59 *60 * For simplification, only the range of hours between 00 and 1961 * are considered.62 *63 * @param input a non-null string that fails to parse in64 * the HH:MM:SS format65 * @return66 */67 private static double getHeuristicToLocalTimeWithSeconds(CharSequence input) {68 Objects.requireNonNull(input);69 final double base = H_NOT_NULL;70 long distance = 0;71 for (int i = 0; i < input.length(); i++) {72 char c = input.charAt(i);73 //format HH:MM:SS74 //let's simplify and only allow 00:00:00 to 19:59:5975 if (i == 0) {76 distance += distanceToRange(c, '0', '1');77 } else if (i == 1 || i == 4 || i == 7) {78 distance += distanceToRange(c, '0', '9');79 } else if (i == 2 || i == 5) {80 distance += distanceToChar(c, ':');81 } else if (i == 3 || i == 6) {82 distance += distanceToRange(c, '0', '5');83 } else {84 distance += MAX_CHAR_DISTANCE;85 }86 }87 if (input.length() < ISO_LOCAL_TIME_LENGTH) {88 //too short89 distance += (MAX_CHAR_DISTANCE * (ISO_LOCAL_TIME_LENGTH - input.length()));90 }91 //recall h in [0,1] where the highest the distance the closer to 092 final double h = base + ((1d - base) / (distance + 1));93 return h;94 }95 /**96 * returns a value that represents how close is the value to the format YYYY-MM-DD97 *98 * @param input99 * @return100 */101 public static double getHeuristicToISOLocalDateTimeParsing(CharSequence input) {102 if (input == null) {103 return H_REACHED_BUT_NULL;104 }105 try {106 LocalDateTime.parse(input);107 return H_PARSED_OK;108 } catch (DateTimeParseException ex) {109 return getHeuristicToISOLocalDateTime(input);110 }111 }112 /**113 * Returns the approximate (i.e. simplified) distance of a string114 * to the format YYYY-MM-DDTHH:MM (T is case insensitive)115 *116 * For simplification, only the range of days between 01 and 28,117 * and months between 01 and 09, and hours between 00 and 19.118 *119 * @param input a non-null string that fails to parse in120 * the YYYY-MM-DDTHH:MM format121 * @return122 */123 private static double getHeuristicToISOLocalDateTime(CharSequence input) {124 Objects.requireNonNull(input);125 final double base = H_NOT_NULL;126 long distance = 0;127 for (int i = 0; i < input.length(); i++) {128 char c = input.charAt(i);129 // TODO: The code below can be refactored with class DateFormatClassReplacement130 //format YYYY-MM-DDT131 if (i >= 0 && i <= 3) {132 //any Y value is ok133 distance += distanceToDigit(c);134 } else if (i == 4 || i == 7) {135 distance += distanceToChar(c, '-');136 } else if (i == 5) {137 //let's simplify and only allow 01 to 09 for MM138 distance += distanceToChar(c, '0');139 } else if (i == 6) {140 distance += distanceToRange(c, '1', '9');141 } else if (i == 8) {142 //let's simplify and only allow 01 to 28143 distance += distanceToRange(c, '0', '2');144 } else if (i == 9) {145 distance += distanceToRange(c, '1', '8');146 } else if (i == 10) {147 // The letter 'T'. Parsing is case insensitive.148 distance += Math.min(distanceToChar(c, 'T'), distanceToChar(c, 't'));149 } else if (i == 11) {150 distance += distanceToRange(c, '0', '1');151 } else if (i == 12 || i == 15 || i == 18) {152 distance += distanceToRange(c, '0', '9');153 } else if (i == 13 || i == 16) {154 distance += distanceToChar(c, ':');155 } else if (i == 14 || i == 17) {156 distance += distanceToRange(c, '0', '5');157 } else {158 distance += MAX_CHAR_DISTANCE;159 }160 }161 if (input.length() < ISO_LOCAL_DATE_TIME_LENGTH) {162 //too short163 distance += (MAX_CHAR_DISTANCE * (ISO_LOCAL_DATE_TIME_LENGTH - input.length()));164 }165 //recall h in [0,1] where the highest the distance the closer to 0166 final double h = base + ((1d - base) / (distance + 1));167 return h;168 }169 /**170 * returns how close the input was to HH:MM or HH:MM:SS.171 * If the input fails to parse in any of those formats, the172 * distance only considers hours in the 00 to 19 range.173 *174 * @param input175 * @return176 */177 public static double getHeuristicToISOLocalTimeParsing(CharSequence input) {178 if (input == null) {179 return H_REACHED_BUT_NULL;180 }181 /*182 * returns the highest value (i.e. closer) to actually183 * satisfy the parsing with or without seconds184 */185 return Math.max(186 getHeuristicToLocalTimeWithoutSecondsParsing(input),187 getHeuristicToLocalTimeWithSecondsParsing(input));188 }189 /**190 * returns the heuristic value in [0,1] that191 * represents how close is the value to the format YYYY-MM-DD192 *193 * @param input194 * @return195 */196 public static double getHeuristicToISOLocalDateParsing(CharSequence input) {197 if (input == null) {198 return H_REACHED_BUT_NULL;199 }200 try {...

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