Skip to content

Commit 59729f7

Browse files
committed
test file upgrade
1 parent 0e89021 commit 59729f7

File tree

9 files changed

+281
-101
lines changed

9 files changed

+281
-101
lines changed

sources/net.sf.j2s.java.core/src/test/Test_Array.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
class Test_Array extends Test_ {
66

77
static int[] i0 = new int[0];
8+
static Object ono = new Class<?>[0];
89

910
static Object c33def2b = new int[][] { { 0, 1, 2 }, { 3, 4, 5 }, { 3, 4, 5 }, { 3, 4, 5 } };
1011

sources/net.sf.j2s.java.core/src/test/Test_Byte.java

Lines changed: 101 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package test;
22

3+
import java.nio.ByteBuffer;
4+
import java.nio.ByteOrder;
5+
import java.util.Arrays;
6+
37
class Test_Byte extends Test_ {
48

59
private static byte v=127;
@@ -8,67 +12,74 @@ public static byte test1() {
812
return v++;
913
}
1014

11-
public static void main(String[] args) {
15+
public static void main(String[] args) {
16+
17+
byte[] ab = new byte[] { 0, 10, 0, 11, 0, 12, 1, 0, 2, 0, 3, 0 };
18+
19+
final ByteBuffer bb = ByteBuffer.wrap(ab);
20+
short[] ash = new short[10];
1221

13-
22+
bb.asShortBuffer().get(ash, 0, 5);
23+
String st = Arrays.toString(ash);
24+
assert(st.equals("[10, 11, 12, 256, 512, 0, 0, 0, 0, 0]"));
25+
System.out.println(st);
1426
byte s = v++;
1527
System.out.println(s + " " + v);
16-
assert((s + " " + v).equals("127 -128"));
17-
28+
assert ((s + " " + v).equals("127 -128"));
29+
1830
char co = '\220';
1931
assert (co == 144);
2032
v = 127;
2133
byte byte0 = 20;
2234
int i10 = 228;
23-
int l1 = ((i10 * 100) / 4805) * (100 / byte0);
24-
int i12 = 100 / byte0;
25-
byte b2 = test1();
26-
27-
assert((b2 + " " + v).equals("127 -128"));
28-
35+
int l1 = ((i10 * 100) / 4805) * (100 / byte0);
36+
int i12 = 100 / byte0;
37+
byte b2 = test1();
38+
39+
assert ((b2 + " " + v).equals("127 -128"));
40+
2941
// implied integer division can be done with int /=
3042
double d = 3;
3143
int di = 'c';
3244
d /= 'c';
3345
System.out.println(d);
34-
assert(d == 3.0/99);
35-
46+
assert (d == 3.0 / 99);
47+
3648
int i3 = 3;
37-
System.out.println(i3/5);
38-
49+
System.out.println(i3 / 5);
3950

4051
byte b1 = 30;
41-
52+
4253
int ib = i3 | b1;
43-
44-
assert(ib == 31);
45-
54+
55+
assert (ib == 31);
56+
4657
// integer division must be turned back into an integer in JavaScript
4758

4859
di /= 'c';
4960
System.out.println(1);
50-
assert(di == 1);
61+
assert (di == 1);
5162

5263
di = 100;
53-
System.out.println(d/7/3);
54-
assert(di / 7 / 3 == 4);
64+
System.out.println(d / 7 / 3);
65+
assert (di / 7 / 3 == 4);
5566

5667
// JavaScript byte arrays require no wrapping
57-
58-
byte[] ab = new byte[10];
68+
69+
ab = new byte[10];
5970
ab[1] += 120;
6071
ab[2] = 120;
6172
ab[3] = 120;
62-
ab[0] = (byte) ((ab[1] + ab[2] + ab[3])/3); // plus and div are not byte operators.
73+
ab[0] = (byte) ((ab[1] + ab[2] + ab[3]) / 3); // plus and div are not byte operators.
6374
System.out.println(ab[0]);
64-
assert(ab[0] == 120);
65-
66-
67-
// all sorts of conversions. Note that short or byte operations other than bit shifts
68-
// are really handled as int operations
75+
assert (ab[0] == 120);
76+
77+
// all sorts of conversions. Note that short or byte operations other than bit
78+
// shifts
79+
// are really handled as int operations
6980
int i255 = 0xFF;
7081
byte b = (byte) i255;
71-
82+
7283
b = 127;
7384
b += 127;
7485
b++;
@@ -90,163 +101,156 @@ public static void main(String[] args) {
90101
assert (i == -1);
91102
b = (byte) c;
92103
b = (byte) 2;
93-
int i2 = ((byte)4000 / b / b) * 30;
104+
int i2 = ((byte) 4000 / b / b) * 30;
94105
System.out.println(i2);
95-
assert(i2 == -720);
96-
b/=2;
106+
assert (i2 == -720);
107+
b /= 2;
97108
b /= 0.01;
98109
System.out.println(b);
99110
assert (b == 100);
100-
111+
101112
// byte array pointer increment test - with character encoding
102-
byte[] bok = new byte[] {'a', 2, 3, 4, 5};
113+
byte[] bok = new byte[] { 'a', 2, 3, 4, 5 };
103114
b = -128;
104115
int pt = 0;
105116
bok[bok[++pt]] += 0;
106117
bok[bok[2]++] += 0;
107-
108-
pt = 0;
118+
119+
pt = 0;
109120
bok[pt++] |= '\2';
110121
bok[pt++] = --b;
111-
assert(pt == 2 && bok[0] == 'c' && bok[1] == 127);
112-
bok[pt++] += b++;
113-
assert(pt == 3 && bok[2] == -125 && b == -128);
122+
assert (pt == 2 && bok[0] == 'c' && bok[1] == 127);
114123
bok[pt++] += b++;
115-
assert(bok[3] == -124 && b == -127);
116-
117-
124+
assert (pt == 3 && bok[2] == -125 && b == -128);
125+
bok[pt++] += b++;
126+
assert (bok[3] == -124 && b == -127);
127+
118128
// byte increment test
119-
b = 127;
129+
b = 127;
120130
i = b++;
121-
assert(i == 127 && b==-128);
122-
b = -128;
131+
assert (i == 127 && b == -128);
132+
b = -128;
123133
i = --b;
124-
assert(i == 127 && b==127);
134+
assert (i == 127 && b == 127);
125135
b = -128;
126136
i = b--;
127-
assert(i == -128 && b==127);
128-
137+
assert (i == -128 && b == 127);
138+
129139
b = 127;
130140
b++;
131-
assert(b==-128);
141+
assert (b == -128);
132142
--b;
133-
assert(b==127);
143+
assert (b == 127);
134144
++b;
135-
assert(b==-128);
145+
assert (b == -128);
136146
b--;
137-
assert(b==127);
138-
139-
147+
assert (b == 127);
148+
140149
// byte shift tests
141-
150+
142151
b = 101;
143152
b <<= 2;
144-
assert(b == -108);
153+
assert (b == -108);
145154
b >>= 2;
146155
System.out.println("((byte)101 << 2) >>2 = " + b);
147-
assert(b == -27);
156+
assert (b == -27);
148157

149158
b = 101;
150159
b = (byte) (b >>> 2);
151-
assert(b == 25);
160+
assert (b == 25);
152161
b = -101;
153162
b = (byte) (b >>> 2);
154163
System.out.println("((byte)-101 >>>2 = " + b);
155-
assert(b == -26);
164+
assert (b == -26);
156165
b = -1;
157166
b = (byte) (b >>> 2);
158167
System.out.println("((byte)-1 >>>2 = " + b);
159-
assert(b == -1);
168+
assert (b == -1);
160169

161170
// int bit shifts
162171
i = -1;
163172
i = i >>> 2;
164173
System.out.println("(int)-1 >>> 2 = " + i);
165-
assert(i == 1073741823);
174+
assert (i == 1073741823);
166175

167176
i = -1;
168177
i >>= 2;
169178
System.out.println("(int)-1 >>= 2 = " + i);
170-
assert(i == -1);
179+
assert (i == -1);
171180

172181
i = -1;
173182
i >>>= 2;
174183
System.out.println("(int)-1 >>>= 2 = " + i);
175-
assert(i == 1073741823);
176-
177-
184+
assert (i == 1073741823);
185+
178186
// character increment test
179187
c = 'a';
180188
c++;
181189
c--;
182190
++c;
183191
--c;
184-
assert(c == 'a');
192+
assert (c == 'a');
185193

186194
i = c++;
187-
assert(i == 'a' && c == 'b');
195+
assert (i == 'a' && c == 'b');
188196
i = ++c;
189-
assert(i == 'c' && c == 'c');
190-
197+
assert (i == 'c' && c == 'c');
191198

192199
pt = 0;
193200
int p = 3;
194-
int[] a = new int[] {1,2,3, 4, 5};
195-
a[2] |= 6;
201+
int[] a = new int[] { 1, 2, 3, 4, 5 };
202+
a[2] |= 6;
196203
a[p++] |= 6;
197204
a[pt++] |= 2;
198-
a[pt++] |= 4;
199-
assert(pt == 2 && a[0] == 3 && a[1] == 6);
200-
205+
a[pt++] |= 4;
206+
assert (pt == 2 && a[0] == 3 && a[1] == 6);
207+
201208
// double array check
202-
byte[][] aa = new byte[][] { {0, 0, 0}, {1,2,3}};
209+
byte[][] aa = new byte[][] { { 0, 0, 0 }, { 1, 2, 3 } };
203210
pt = 0;
204211
aa[pt++][1] += 5;
205212
aa[pt++][1] += (int) (pt + 5.0);
206213
pt = 0;
207214
aa[1][pt++] += 5;
208215
aa[1][pt++] += 5;
209-
assert(aa[0][1] == 5);
210-
assert(aa[1][1] == 14);
211-
212-
213-
byte[][][] aaa = new byte[][][] {{{0, 0, 0}, {1,2,3}, {4, 5, 6}}};
216+
assert (aa[0][1] == 5);
217+
assert (aa[1][1] == 14);
218+
219+
byte[][][] aaa = new byte[][][] { { { 0, 0, 0 }, { 1, 2, 3 }, { 4, 5, 6 } } };
214220
pt = 0;
215221
p = 0;
216222
aaa[p++][pt++][1] += 5;
217223
aaa[0][pt++][1] += (int) (pt + 5.0);
218224
pt = 0;
219225
aaa[0][1][pt++] += 5;
220-
assert(aaa[0][0][1] == 5);
221-
assert(aaa[0][1][0] == 6);
222-
assert(aaa[0][1][1] == 9);
223-
224-
226+
assert (aaa[0][0][1] == 5);
227+
assert (aaa[0][1][0] == 6);
228+
assert (aaa[0][1][1] == 9);
229+
225230
// boolean[] test
226231
boolean[] aok = new boolean[200];
227-
228-
aok[100] |= true;
229-
232+
233+
aok[100] |= true;
234+
230235
pt = 0;
231236
aok[pt++] |= true;
232-
assert(pt == 1 && aok[0] == true);
237+
assert (pt == 1 && aok[0] == true);
233238

234239
// char[] test
235-
240+
236241
char[] cok = new char[3];
237-
pt = 0;
242+
pt = 0;
238243
cok[0] = '\2';
239-
cok[pt++] |= 'a';
244+
cok[pt++] |= 'a';
240245
// cok[$j$=pt++] = String.fromCharCode((cok[$j$]).$c()| 97);
241-
assert(pt == 1 && cok[0] == 'c');
246+
assert (pt == 1 && cok[0] == 'c');
242247

243248
// quick test for double using += directly
244249

245250
double line1[] = new double[20];
246251
i2 = 1;
247-
line1[i2+1] += Math.sin(3);
248-
249-
252+
line1[i2 + 1] += Math.sin(3);
253+
250254
System.out.println("Test_Byte OK");
251255

252256
}

sources/net.sf.j2s.java.core/src/test/Test_Class.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
@SuppressWarnings("rawtypes")
1313
class Test_Class extends Test_Class2 {
1414

15+
Test_Class(byte[]...d) {
16+
super(d);
17+
System.out.println("Test_Class len = " + d.length);
18+
}
19+
20+
21+
1522
int x = 2000000000 + 2000000000;
1623

1724
static int istatic = 5;
@@ -229,14 +236,38 @@ Class B() {
229236

230237
static class C extends Test_Class {
231238

239+
C() {
240+
super();
241+
}
242+
243+
C(byte[]...d) {
244+
super(d);
245+
System.out.println("C len = " + d.length);
246+
}
247+
232248
}
233249

234250
Class C() {
235251
return C.class;
236252
}
253+
254+
255+
237256

238257
public static void main(String[] args) {
239258

259+
260+
new C(new byte[0], new byte[100], new byte[1000]);
261+
262+
new C(new byte[3][5]);
263+
264+
try {
265+
new C((byte[][])null);
266+
} catch (Throwable t) {
267+
System.out.println("Right!");
268+
}
269+
270+
240271
Class<?> type = Object.class;
241272
assert(type instanceof Class<?>);
242273

0 commit comments

Comments
 (0)