李林
2023-08-08 b71d454f550a53dde29b1849acfebd06e34f7299
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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;
            }
        }
    }
 
}