package com.yuanchu.mom; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class SystemRunApplicationTest { @Test void contextLoads() { int i = checkValues(">=2", "=0", "0"); System.out.println(i); } public int checkValues(String standardValueStr, String controlValueStr, String detectionValueStr) { boolean isStandardValueSatisfied = isValueSatisfied(standardValueStr, detectionValueStr); boolean isControlValueSatisfied = isValueSatisfied(controlValueStr, detectionValueStr); if (isStandardValueSatisfied && isControlValueSatisfied) { return 1; } else { return 0; } } private boolean isValueSatisfied(String valueStr, String detectionValueStr) { String substring = valueStr.substring(1,2); if (substring.equals("=")) { String operator = valueStr.substring(0, 2); Double standardValue = Double.parseDouble(valueStr.substring(2)); Double detectionValue = Double.parseDouble(detectionValueStr); switch (operator){ case ">=": return detectionValue >= standardValue; case "<=": return detectionValue <= standardValue; default: return false; } }else { String operator = valueStr.substring(0,1); Double standardValue = Double.parseDouble(valueStr.substring(1)); Double detectionValue = Double.parseDouble(detectionValueStr); switch (operator){ case ">": return detectionValue > standardValue; case "<": return detectionValue < standardValue; case "=": return detectionValue.equals(standardValue); default: return false; } } } }