-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathJavaParameterTest.java
More file actions
80 lines (61 loc) · 2.93 KB
/
Copy pathJavaParameterTest.java
File metadata and controls
80 lines (61 loc) · 2.93 KB
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
package moj;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import moj.mocks.*;
import org.junit.*;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.topcoder.shared.language.JavaLanguage;
import com.topcoder.shared.problem.DataType;
import com.topcoder.shared.problem.InvalidTypeException;
@RunWith(Parameterized.class)
public class JavaParameterTest {
private String typename, value, expected;
public JavaParameterTest(String typename, String varval, String expected) {
this.typename = typename;
this.value = varval;
this.expected = expected;
}
JavaHarnessGenerator generator;
ArrayList<String> code;
@Before public void setUp() {
generator = new JavaHarnessGenerator(
new ProblemComponentModelMock(),
JavaLanguage.JAVA_LANGUAGE,
new PreferencesMock()
);
code = new ArrayList<String>();
}
static String compressSpaceBeforeEquals(String str) {
return str.replaceFirst("\\s*=", " =").trim();
}
@Parameters
public static List<Object[]> data() {
Object[][] data = new Object[][] {
{"int", "-2147483648", "int var = -2147483648;"},
{"String", "\"test string\"", "String var = \"test string\";"},
{"String", "\" multiple spaces \"", "String var = \" multiple spaces \";"},
{"String", "\" a = 3 \"", "String var = \" a = 3 \";"},
{"double", "1.345e08", "double var = 1.345e08;"},
{"long", "123", "long var = 123;"},
{"long", "-9999999999", "long var = -9999999999L;"},
{"long", "2147483648", "long var = 2147483648L;"},
{"int[]", "{-2147483648, 2147483647, 0, -1, 555}", "int[] var = {-2147483648, 2147483647, 0, -1, 555};"},
{"int[]", "{}", "int[] var = {};"},
{"String[]", "{\"a\",\n \"\",\n \"test test\"}", "String[] var = {\"a\",\n \"\",\n \"test test\"};"},
{"String[]", "{\"spaces space\", \"a a\"}", "String[] var = {\"spaces space\", \"a a\"};"},
{"double[]", "{ 1e9, -3.e-012, -4, 5 }", "double[] var = { 1e9, -3.e-012, -4, 5 };"},
{"long[]", "{ 0, -1, 1, 2147483648,\n-2147483649, 9223372036854775807, -9223372036854775808}", "long[] var = {0, -1, 1, 2147483648L, -2147483649L, 9223372036854775807L, -9223372036854775808L};"},
};
return Arrays.asList(data);
}
@Test public void test() throws InvalidTypeException {
DataType dt = DataTypeFactoryMock.getDataType(this.typename);
generator.generateParameter(code, dt, "var", this.value, false);
String result = compressSpaceBeforeEquals(code.get(0).toString());
assertEquals(this.expected, result);
}
}