Skip to content

Commit adb1b8a

Browse files
committed
Add a testcase for ClassInit; Merge the original SuperCtorTests into one; Fix bugs in Loops testcase; Add tests for static member variable with keyword as name
1 parent 30c16af commit adb1b8a

11 files changed

Lines changed: 98 additions & 28 deletions

java2python/tests/ClassInit.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import junit.framework.*;
2+
3+
class SimpleClassInit {
4+
static int x = 1;
5+
6+
static {
7+
x = 2;
8+
}
9+
10+
}
11+
12+
public class ClassInit extends TestCase {
13+
14+
public void testClassInit() {
15+
Assert.assertEquals(SimpleClassInit.x, 2);
16+
}
17+
}

java2python/tests/FloatFix.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import junit.framework.*;
22

33
public class FloatFix extends TestCase {
4-
public void runTest() {
4+
5+
public void testFloatFix() {
56
float b = 1.2f;
67
Assert.assertEquals(b, 1.2f);
78
}
9+
810
}

java2python/tests/Keywords.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import junit.framework.*;
22

33
public class Keywords extends TestCase {
4-
public static void main(String[] args) {
4+
public static String None = "this is None";
5+
public static String and = "this is and";
6+
7+
public void testKeywords() {
58
String and = "this is and";
69
Assert.assertEquals(and, "this is and");
10+
Assert.assertEquals(Keywords.and, "this is and");
711

812
String del = "this is del";
913
Assert.assertEquals(del, "this is del");
@@ -12,7 +16,7 @@ public static void main(String[] args) {
1216
Assert.assertEquals(elif, "this is elif");
1317

1418
String from = "this is from";
15-
Assert.assertEquals(elif, "this is from");
19+
Assert.assertEquals(from, "this is from");
1620

1721
String in = "this is in";
1822
Assert.assertEquals(in, "this is in");
@@ -34,6 +38,6 @@ public static void main(String[] args) {
3438

3539
String None = "this is None";
3640
Assert.assertEquals(None, "this is None");
37-
41+
Assert.assertEquals(Keywords.None, "this is None");
3842
}
3943
}

java2python/tests/Loops.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
public class Loops extends TestCase {
44

55
public void testFor() {
6-
for(int a = 1; a < 10;){
6+
int a, b;
7+
8+
for(a = 1; a < 10;){
79
a+= 3;
810
}
911
Assert.assertEquals(a, 10);
1012

11-
for (int b = 0; b < 20; b+=2) {
13+
for (b = 0; b < 20; b+=2) {
1214
}
1315
Assert.assertEquals(b, 20);
1416
}

java2python/tests/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ PYTHONPATH=../../:.
22
CLASSPATH:=.:/usr/share/junit/lib/junit.jar
33

44
PYOBJS=Loops.py AssignInExpr.py EmptyArray.py Switches.py ClassMember.py \
5-
FloatFix.py Keywords.py
6-
JAVAOBJS=AssignInExpr EmptyArray Switches ClassMember
5+
FloatFix.py Keywords.py ClassInit.py SuperCtorTest.py
6+
JAVAOBJS=Loops AssignInExpr EmptyArray Switches ClassMember FloatFix Keywords \
7+
ClassInit SuperCtorTest
78

89
all: python-test
910

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import junit.framework.*;
2+
3+
class SuperClass {
4+
public int x = 0;
5+
public String y = null;
6+
7+
public SuperClass() {
8+
x = 1;
9+
}
10+
11+
public SuperClass(String arg) {
12+
y = arg;
13+
}
14+
15+
public SuperClass(int arg) {
16+
x = arg;
17+
}
18+
}
19+
20+
class SuperCtorTest1 extends SuperClass {
21+
public SuperCtorTest1() {
22+
}
23+
}
24+
25+
26+
class SuperCtorTest2 extends SuperClass {
27+
public SuperCtorTest2() {
28+
super();
29+
}
30+
}
31+
32+
33+
class SuperCtorTest3 extends SuperClass {
34+
public SuperCtorTest3() {
35+
super("arg");
36+
}
37+
}
38+
39+
class SuperCtorTest4 extends SuperClass {
40+
public SuperCtorTest4(int arg) {
41+
super(arg);
42+
}
43+
}
44+
45+
public class SuperCtorTest extends TestCase {
46+
47+
public void testSuperCtor() {
48+
SuperCtorTest1 t1 = new SuperCtorTest1();
49+
Assert.assertEquals(1, t1.x);
50+
51+
SuperCtorTest2 t2 = new SuperCtorTest2();
52+
Assert.assertEquals(1, t2.x);
53+
54+
SuperCtorTest3 t3 = new SuperCtorTest3();
55+
Assert.assertEquals("arg", t3.y);
56+
Assert.assertEquals(0, t3.x);
57+
58+
SuperCtorTest4 t4 = new SuperCtorTest4(10);
59+
Assert.assertEquals(10, t4.x);
60+
}
61+
62+
}

java2python/tests/SuperCtorTest1.java

Lines changed: 0 additions & 3 deletions
This file was deleted.

java2python/tests/SuperCtorTest2.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

java2python/tests/SuperCtorTest3.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

java2python/tests/SuperCtorTest4.java

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)