author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Tue, 15 Jan 2013 12:38:49 +0100 | |
changeset 458 | b157a354003f |
parent 390 | 40fabaeca68d |
child 459 | a2871a3fd4c5 |
permissions | -rw-r--r-- |
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 CompareByteArrayTest { |
jaroslav@390 | 29 |
@Compare public int byteArraySum() { |
jaroslav@390 | 30 |
byte[] arr = createArray(); |
jaroslav@390 | 31 |
return sumByteArr(arr); |
jaroslav@390 | 32 |
} |
jaroslav@390 | 33 |
|
jaroslav@390 | 34 |
@Compare public int countZeros() { |
jaroslav@390 | 35 |
int zeros = 0; |
jaroslav@390 | 36 |
for (Byte b : createArray()) { |
jaroslav@390 | 37 |
if (b == 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 sumByteArr(byte[] 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@458 | 52 |
@Compare public String noOutOfBounds() { |
jaroslav@458 | 53 |
return atIndex(1); |
jaroslav@458 | 54 |
} |
jaroslav@458 | 55 |
|
jaroslav@458 | 56 |
@Compare public String outOfBounds() { |
jaroslav@458 | 57 |
return atIndex(5); |
jaroslav@458 | 58 |
} |
jaroslav@458 | 59 |
|
jaroslav@458 | 60 |
@Compare public String outOfBoundsMinus() { |
jaroslav@458 | 61 |
return atIndex(-1); |
jaroslav@458 | 62 |
} |
jaroslav@458 | 63 |
|
jaroslav@458 | 64 |
private static final int[] arr = { 0, 1, 2 }; |
jaroslav@458 | 65 |
public static String atIndex(int at) { |
jaroslav@458 | 66 |
return "at@" + arr[at]; |
jaroslav@458 | 67 |
} |
jaroslav@458 | 68 |
|
jaroslav@458 | 69 |
|
jaroslav@390 | 70 |
@Factory |
jaroslav@390 | 71 |
public static Object[] create() { |
jaroslav@390 | 72 |
return VMTest.create(CompareByteArrayTest.class); |
jaroslav@390 | 73 |
} |
jaroslav@390 | 74 |
|
jaroslav@390 | 75 |
private byte[] createArray() { |
jaroslav@390 | 76 |
byte[] arr = new byte[10]; |
jaroslav@390 | 77 |
arr[5] = 3; |
jaroslav@390 | 78 |
arr[7] = 8; |
jaroslav@390 | 79 |
return arr; |
jaroslav@390 | 80 |
} |
jaroslav@390 | 81 |
} |