File size: 6,230 Bytes
9438a57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
public class GET_FACTORSTest {
    @org.junit.jupiter.api.Test @org.junit.jupiter.api.Timeout(value = 3000, unit = java.util.concurrent.TimeUnit.MILLISECONDS)
    public void test_0() throws java.lang.Exception {
        java.util.ArrayList result = GET_FACTORS.get_factors((int)1);
        String resultFormatted = QuixFixOracleHelper.format(result,true);
        org.junit.jupiter.api.Assertions.assertEquals("[]", resultFormatted);
    }

    @org.junit.jupiter.api.Test @org.junit.jupiter.api.Timeout(value = 3000, unit = java.util.concurrent.TimeUnit.MILLISECONDS)
    public void test_1() throws java.lang.Exception {
        java.util.ArrayList result = GET_FACTORS.get_factors((int)100);
        String resultFormatted = QuixFixOracleHelper.format(result,true);
        org.junit.jupiter.api.Assertions.assertEquals("[2,2,5,5]", resultFormatted);
    }

    @org.junit.jupiter.api.Test @org.junit.jupiter.api.Timeout(value = 3000, unit = java.util.concurrent.TimeUnit.MILLISECONDS)
    public void test_2() throws java.lang.Exception {
        java.util.ArrayList result = GET_FACTORS.get_factors((int)101);
        String resultFormatted = QuixFixOracleHelper.format(result,true);
        org.junit.jupiter.api.Assertions.assertEquals("[101]", resultFormatted);
    }

    @org.junit.jupiter.api.Test @org.junit.jupiter.api.Timeout(value = 3000, unit = java.util.concurrent.TimeUnit.MILLISECONDS)
    public void test_3() throws java.lang.Exception {
        java.util.ArrayList result = GET_FACTORS.get_factors((int)104);
        String resultFormatted = QuixFixOracleHelper.format(result,true);
        org.junit.jupiter.api.Assertions.assertEquals("[2,2,2,13]", resultFormatted);
    }

    @org.junit.jupiter.api.Test @org.junit.jupiter.api.Timeout(value = 3000, unit = java.util.concurrent.TimeUnit.MILLISECONDS)
    public void test_4() throws java.lang.Exception {
        java.util.ArrayList result = GET_FACTORS.get_factors((int)2);
        String resultFormatted = QuixFixOracleHelper.format(result,true);
        org.junit.jupiter.api.Assertions.assertEquals("[2]", resultFormatted);
    }

    @org.junit.jupiter.api.Test @org.junit.jupiter.api.Timeout(value = 3000, unit = java.util.concurrent.TimeUnit.MILLISECONDS)
    public void test_5() throws java.lang.Exception {
        java.util.ArrayList result = GET_FACTORS.get_factors((int)3);
        String resultFormatted = QuixFixOracleHelper.format(result,true);
        org.junit.jupiter.api.Assertions.assertEquals("[3]", resultFormatted);
    }

    @org.junit.jupiter.api.Test @org.junit.jupiter.api.Timeout(value = 3000, unit = java.util.concurrent.TimeUnit.MILLISECONDS)
    public void test_6() throws java.lang.Exception {
        java.util.ArrayList result = GET_FACTORS.get_factors((int)17);
        String resultFormatted = QuixFixOracleHelper.format(result,true);
        org.junit.jupiter.api.Assertions.assertEquals("[17]", resultFormatted);
    }

    @org.junit.jupiter.api.Test @org.junit.jupiter.api.Timeout(value = 3000, unit = java.util.concurrent.TimeUnit.MILLISECONDS)
    public void test_7() throws java.lang.Exception {
        java.util.ArrayList result = GET_FACTORS.get_factors((int)63);
        String resultFormatted = QuixFixOracleHelper.format(result,true);
        org.junit.jupiter.api.Assertions.assertEquals("[3,3,7]", resultFormatted);
    }

    @org.junit.jupiter.api.Test @org.junit.jupiter.api.Timeout(value = 3000, unit = java.util.concurrent.TimeUnit.MILLISECONDS)
    public void test_8() throws java.lang.Exception {
        java.util.ArrayList result = GET_FACTORS.get_factors((int)74);
        String resultFormatted = QuixFixOracleHelper.format(result,true);
        org.junit.jupiter.api.Assertions.assertEquals("[2,37]", resultFormatted);
    }

    @org.junit.jupiter.api.Test @org.junit.jupiter.api.Timeout(value = 3000, unit = java.util.concurrent.TimeUnit.MILLISECONDS)
    public void test_9() throws java.lang.Exception {
        java.util.ArrayList result = GET_FACTORS.get_factors((int)73);
        String resultFormatted = QuixFixOracleHelper.format(result,true);
        org.junit.jupiter.api.Assertions.assertEquals("[73]", resultFormatted);
    }

    @org.junit.jupiter.api.Test @org.junit.jupiter.api.Timeout(value = 3000, unit = java.util.concurrent.TimeUnit.MILLISECONDS)
    public void test_10() throws java.lang.Exception {
        java.util.ArrayList result = GET_FACTORS.get_factors((int)9837);
        String resultFormatted = QuixFixOracleHelper.format(result,true);
        org.junit.jupiter.api.Assertions.assertEquals("[3,3,1093]", resultFormatted);
    }
}


/**
 * Methods to format the output from the subject programs.
 *
 * @author Matias Martinez
 *
 */

class QuixFixOracleHelper {

    public static String format(Object out, boolean cutDecimal) {
        Object jsonOutObtained = transformToString(out, cutDecimal);
        String obtained = removeSymbols(jsonOutObtained.toString());
        return obtained;
    }

    public static String removeSymbols(String r) {

        r = r.replaceAll("\\(", "[").replaceAll("\\)", "]").replace(" ", "").replaceAll("\"", "");
        return r;
    }

    public static String transformToString(Object out, boolean mustRemoveDecimal) {
        if (out instanceof Iterable) {
            String r = "[";
            for (Object o : (Iterable) out) {
                r += transformToString(o, mustRemoveDecimal) + ",";
            }
            if (r.length() >= 2) {
                r = r.trim().substring(0, r.length() - 1);
            }

            return r + "]";
        } else {
            String s = "";
            if (out instanceof String && !isInteger(out.toString()))
                s += out.toString();
            else {
                s = (mustRemoveDecimal && out.toString().endsWith(".0")
                        ? out.toString().substring(0, out.toString().length() - 2) : out.toString());
            }
            return s;
        }

    }

    public static boolean isInteger(String s) {
        boolean isValidInteger = false;
        try {
            Integer.parseInt(s);
            isValidInteger = true;
        } catch (NumberFormatException ex) {
        }

        return isValidInteger;
    }
}