Are multi dimensional arrays properly initialized with 0? arithmetic
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 15 Jan 2013 11:39:15 +0100
brancharithmetic
changeset 4546506c5925775
parent 447 aa48132c8a80
child 456 f2f769bafeef
child 581 95753ad65192
Are multi dimensional arrays properly initialized with 0?
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java
     1.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java	Mon Jan 14 14:23:27 2013 +0100
     1.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java	Tue Jan 15 11:39:15 2013 +0100
     1.3 @@ -91,6 +91,25 @@
     1.4          return mod(1, 2);
     1.5      }
     1.6      
     1.7 +    @Compare public int sumTwoDimensions() {
     1.8 +        int[][] matrix = createMatrix(4, 3);
     1.9 +        int sum = 0;
    1.10 +        for (int i = 0; i < matrix.length; i++) {
    1.11 +            for (int j = 0; j < matrix[i].length; j++) {
    1.12 +                sum += matrix[i][j];
    1.13 +            }
    1.14 +        }
    1.15 +        return sum;
    1.16 +    }
    1.17 +    
    1.18 +    static int[][] createMatrix(int x, int y) {
    1.19 +        int[][] m = new int[x][y];
    1.20 +        for (int i = 0; i < Math.min(x, y); i++) {
    1.21 +            m[i][i] = i;
    1.22 +        }
    1.23 +        return m;
    1.24 +    }
    1.25 +    
    1.26      @Factory
    1.27      public static Object[] create() {
    1.28          return VMTest.create(IntegerArithmeticTest.class);