codegen: some more tests
[mate.git] / tests / WhileArray1.java
1 package tests;
2
3 public class WhileArray1 {
4         public static void main(String args[]) {
5                 char a[] = new char[10];
6                 char b[] = new char[10];
7                 for (int i = 0; i < 10; i++) {
8                         a[i] = b[i] = (char) i;
9                 }
10                 System.out.printf("success? %d\n", equal(a, b, 5) ? 1 : 0);
11
12                 for (int i = 0; i < 10; i++) {
13                         b[i] = (char) i;
14                         a[i] = (char) (b[i] + 2);
15                 }
16                 System.out.printf("success? %d\n", equal(a, b, 5) ? 1 : 0);
17         }
18
19         public static boolean equal(char[] a, char[] b, int len) {
20                 /* stolen from the equals implementation of java.lang.String of
21                  * GNU Classpath */
22                 int x = 0, y = 0;
23                 while (--len >= 0) {
24                         System.out.printf("idx: x: %d, y: %d\n", x, y);
25                         if (a[x++] != b[y++]) {
26                                 return false;
27                         }
28                 }
29                 return true;
30         }
31 }