rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/tck/CompareIntArrayTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 19 Nov 2014 19:32:00 +0100
changeset 1723 3a1f262311cf
parent 1034 rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/CompareIntArrayTest.java@28dc692f3b11
child 1787 ea12a3bb4b33
permissions -rw-r--r--
Separating compact profile tests into own project, so launcher.http can depend on compact profile JAR
jaroslav@390
     1
/**
jaroslav@390
     2
 * Back 2 Browser Bytecode Translator
jaroslav@390
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@390
     4
 *
jaroslav@390
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@390
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@390
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@390
     8
 *
jaroslav@390
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@390
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@390
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@390
    12
 * GNU General Public License for more details.
jaroslav@390
    13
 *
jaroslav@390
    14
 * You should have received a copy of the GNU General Public License
jaroslav@390
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@390
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@390
    17
 */
jaroslav@390
    18
package org.apidesign.bck2brwsr.tck;
jaroslav@390
    19
jaroslav@390
    20
import org.apidesign.bck2brwsr.vmtest.Compare;
jaroslav@390
    21
import org.apidesign.bck2brwsr.vmtest.VMTest;
jaroslav@390
    22
import org.testng.annotations.Factory;
jaroslav@390
    23
jaroslav@390
    24
/**
jaroslav@390
    25
 *
jaroslav@390
    26
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@390
    27
 */
jaroslav@390
    28
public class CompareIntArrayTest {
jaroslav@390
    29
    @Compare public int integerArraySum() {
jaroslav@390
    30
        int[] arr = createArray();
jaroslav@390
    31
        return sumIntArr(arr);
jaroslav@390
    32
    }
jaroslav@390
    33
    
jaroslav@390
    34
    @Compare public int countZeros() {
jaroslav@390
    35
        int zeros = 0;
jaroslav@390
    36
        for (Integer i : createArray()) {
jaroslav@390
    37
            if (i == 0) {
jaroslav@390
    38
                zeros++;
jaroslav@390
    39
            }
jaroslav@390
    40
        }
jaroslav@390
    41
        return zeros;
jaroslav@390
    42
    }
jaroslav@390
    43
    
jaroslav@390
    44
    private static int sumIntArr(int[] arr) {
jaroslav@390
    45
        int sum = 0;
jaroslav@390
    46
        for (int i = 0; i < arr.length; i++) {
jaroslav@390
    47
            sum += arr[i];
jaroslav@390
    48
        }
jaroslav@390
    49
        return sum;
jaroslav@390
    50
    }
jaroslav@390
    51
    
jaroslav@390
    52
    @Factory
jaroslav@390
    53
    public static Object[] create() {
jaroslav@390
    54
        return VMTest.create(CompareIntArrayTest.class);
jaroslav@390
    55
    }
jaroslav@390
    56
jaroslav@390
    57
    private int[] createArray() {
jaroslav@390
    58
        int[] arr = new int[10];
jaroslav@390
    59
        arr[5] = 3;
jaroslav@390
    60
        arr[7] = 8;
jaroslav@390
    61
        return arr;
jaroslav@390
    62
    }
jaroslav@390
    63
}