SevdanurGenc's picture
Upload 300 files
9438a57 verified
Raw History Blame Contribute Delete
3.77 kB
public class TO_BASETest {
@org.junit.Test(timeout = 3000)
public void test_0() throws java.lang.Exception {
java.lang.String result = TO_BASE.to_base((int)31,(int)16);
String resultFormatted = QuixFixOracleHelper.format(result,true);
org.junit.Assert.assertEquals("1F", resultFormatted);
}
@org.junit.Test(timeout = 3000)
public void test_1() throws java.lang.Exception {
java.lang.String result = TO_BASE.to_base((int)41,(int)2);
String resultFormatted = QuixFixOracleHelper.format(result,true);
org.junit.Assert.assertEquals("101001", resultFormatted);
}
@org.junit.Test(timeout = 3000)
public void test_2() throws java.lang.Exception {
java.lang.String result = TO_BASE.to_base((int)44,(int)5);
String resultFormatted = QuixFixOracleHelper.format(result,true);
org.junit.Assert.assertEquals("134", resultFormatted);
}
@org.junit.Test(timeout = 3000)
public void test_3() throws java.lang.Exception {
java.lang.String result = TO_BASE.to_base((int)27,(int)23);
String resultFormatted = QuixFixOracleHelper.format(result,true);
org.junit.Assert.assertEquals("14", resultFormatted);
}
@org.junit.Test(timeout = 3000)
public void test_4() throws java.lang.Exception {
java.lang.String result = TO_BASE.to_base((int)56,(int)23);
String resultFormatted = QuixFixOracleHelper.format(result,true);
org.junit.Assert.assertEquals("2A", resultFormatted);
}
@org.junit.Test(timeout = 3000)
public void test_5() throws java.lang.Exception {
java.lang.String result = TO_BASE.to_base((int)8237,(int)24);
String resultFormatted = QuixFixOracleHelper.format(result,true);
org.junit.Assert.assertEquals("E75", resultFormatted);
}
@org.junit.Test(timeout = 3000)
public void test_6() throws java.lang.Exception {
java.lang.String result = TO_BASE.to_base((int)8237,(int)34);
String resultFormatted = QuixFixOracleHelper.format(result,true);
org.junit.Assert.assertEquals("749", 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;
}
}