Skip to content

Commit 96cde0d

Browse files
committed
Make switches testcases use python unittest and add some new ones.
1 parent 565ccb8 commit 96cde0d

2 files changed

Lines changed: 51 additions & 14 deletions

File tree

java2python/tests/Makefile

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

4-
PYOBJS=AssignInExpr.py EmptyArray.py
5-
JAVAOBJS=AssignInExpr EmptyArray
4+
PYOBJS=AssignInExpr.py EmptyArray.py Switches.py
5+
JAVAOBJS=AssignInExpr EmptyArray Switches
66

77
all: python-test
88

java2python/tests/Switches.java

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,66 @@
1-
class Switches {
2-
public static void main(String[] args) {
3-
System.out.println( switches() );
4-
}
1+
import junit.framework.*;
2+
3+
public class Switches extends TestCase {
4+
5+
public void testSwitches() {
6+
Assert.assertEquals(switch1(1), 1);
7+
Assert.assertEquals(switch1(2), 2);
8+
Assert.assertEquals(switch1(3), 10);
9+
Assert.assertEquals(switch1(10), 4);
10+
11+
Assert.assertEquals(switch2(3), 2);
12+
Assert.assertEquals(switch2(3), 2);
513

6-
public static int switches() {
7-
int i;
8-
i = 3;
14+
Assert.assertEquals(switch3(3), 4);
915

16+
Assert.assertEquals(switch4(1), 1);
17+
Assert.assertEquals(switch4(3), 2);
18+
}
19+
20+
public int switch1(int i) {
1021
switch (i) {
1122
case 1:
1223
case 2:
1324
break;
1425
case 3:
15-
i = 2;
26+
i = 10;
27+
break;
1628
default:
17-
return -4;
29+
i = 4;
1830
}
31+
return i;
32+
}
1933

34+
public int switch2(int i) {
2035
switch (i) {
2136
case 3:
2237
default:
2338
i = 2;
24-
}
25-
return -1;
39+
}
40+
return i;
2641
}
2742

28-
}
43+
public int switch3(int i) {
44+
switch (i) {
45+
case 1:
46+
case 2:
47+
break;
48+
case 3:
49+
i = 10;
50+
default:
51+
i = 4;
52+
}
53+
return i;
54+
}
2955

56+
public int switch4(int i) {
57+
switch (i) {
58+
case 1:
59+
if (i == 1) break;
60+
default:
61+
i = 2;
62+
}
63+
return i;
64+
}
65+
66+
}

0 commit comments

Comments
 (0)