Skip to content

Commit 4a8f286

Browse files
committed
Make some testcases use python unittest
1 parent 52da7b8 commit 4a8f286

File tree

6 files changed

+74
-47
lines changed

6 files changed

+74
-47
lines changed

java2python/tests/ArrayValues.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
2-
class ArrayValues {
1+
import junit.framework.*;
2+
3+
public class ArrayValues extends TestCase {
4+
35
int a[] = {1, 2, 3};
46

5-
public static void main(String[] args) {
6-
int b[] = {4, 5, 6};
7-
System.out.println(b[0]);
7+
public void testArrayValues() {
8+
int b[] = {4, 5, 6};
9+
Assert.assertEquals(a[0], 1);
10+
Assert.assertEquals(a[1], 2);
11+
Assert.assertEquals(a[2], 3);
12+
Assert.assertEquals(b[0], 4);
13+
Assert.assertEquals(b[1], 5);
14+
Assert.assertEquals(b[2], 6);
815
}
916
}

java2python/tests/ClassMember.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
class Simple {
44
public int a = 1;
55
public int [] b = new int[10];
6+
public static int c = 0;
7+
8+
public void add() {
9+
c++;
10+
a++;
11+
}
612
}
713

814
public class ClassMember extends TestCase {
@@ -13,4 +19,12 @@ public void testNonStaticMember() {
1319
x.b[0] = 1;
1420
Assert.assertEquals(y.b[0], 0);
1521
}
22+
23+
public void testStaticMember() {
24+
Simple x = new Simple();
25+
x.add();
26+
x.add();
27+
Assert.assertEquals(Simple.c, 2);
28+
Assert.assertEquals(x.c, 2);
29+
}
1630
}

java2python/tests/FloatFix.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
class FloatFix {
2-
public static void main(String[] args) {
3-
float b = 1.2f;
4-
System.out.println(b);
1+
import junit.framework.*;
2+
3+
public class FloatFix extends TestCase {
4+
public void runTest() {
5+
float b = 1.2f;
6+
Assert.assertEquals(b, 1.2f);
57
}
68
}

java2python/tests/Keywords.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
class Keywords {
2-
public static void main(String[] args) {
3-
String and = "this is and";
4-
System.out.println(and);
1+
import junit.framework.*;
52

6-
String del = "this is del";
7-
System.out.println(del);
3+
public class Keywords extends TestCase {
4+
public static void main(String[] args) {
5+
String and = "this is and";
6+
Assert.assertEquals(and, "this is and");
87

9-
String elif = "this is elif";
10-
System.out.println(elif);
8+
String del = "this is del";
9+
Assert.assertEquals(del, "this is del");
1110

12-
String in = "this is in";
13-
System.out.println(in);
11+
String elif = "this is elif";
12+
Assert.assertEquals(elif, "this is elif");
1413

15-
String is = "this is is";
16-
System.out.println(is);
14+
String in = "this is in";
15+
Assert.assertEquals(in, "this is in");
1716

18-
String not = "this is not";
19-
System.out.println(not);
17+
String is = "this is is";
18+
Assert.assertEquals(is, "this is is");
2019

21-
String or = "this is or";
22-
System.out.println(or);
20+
String not = "this is not";
21+
Assert.assertEquals(not, "this is not");
2322

24-
String print = "this is print";
25-
System.out.println(print);
23+
String or = "this is or";
24+
Assert.assertEquals(or, "this is or");
2625

27-
String str = "this is str";
28-
System.out.println(str);
26+
String print = "this is print";
27+
Assert.assertEquals(print, "this is print");
2928

29+
String str = "this is str";
30+
Assert.assertEquals(str, "this is str");
3031
}
3132
}

java2python/tests/Loops.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
class Loops {
2-
public static void main(String[] args) {
3-
for(int a = 1; a < 10;){
4-
a+= 3;
5-
System.out.println(a);
6-
}
1+
import junit.framework.*;
72

8-
for (int b = 0; b < 20; b+=2) {
9-
}
3+
public class Loops extends TestCase {
104

11-
doWhile();
5+
public void testFor() {
6+
for(int a = 1; a < 10;){
7+
a+= 3;
8+
}
9+
Assert.assertEquals(a, 10);
10+
11+
for (int b = 0; b < 20; b+=2) {
12+
}
13+
Assert.assertEquals(b, 20);
1214
}
1315

14-
public static int doWhile() {
15-
int x = 0;
16-
do {
17-
System.out.println(x);
18-
x += 1;
19-
} while (x <= 10);
20-
return x;
16+
public void testDoWhile() {
17+
int x = 0;
18+
do {
19+
x += 1;
20+
} while (x <= 10);
21+
Assert.assertEquals(x, 11);
2122
}
23+
2224
}
2325

java2python/tests/Makefile

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

4-
PYOBJS=AssignInExpr.py EmptyArray.py Switches.py
5-
JAVAOBJS=AssignInExpr EmptyArray Switches
4+
PYOBJS=Loops.py AssignInExpr.py EmptyArray.py Switches.py ClassMember.py \
5+
FloatFix.py Keywords.py
6+
JAVAOBJS=AssignInExpr EmptyArray Switches ClassMember
67

78
all: python-test
89

0 commit comments

Comments
 (0)