1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 class Main { 18 final static int iterations = 10; 19 assertIntEquals(int expected, int result)20 public static void assertIntEquals(int expected, int result) { 21 if (expected != result) { 22 throw new Error("Expected: " + expected + ", found: " + result); 23 } 24 } 25 assertDoubleEquals(double expected, double result)26 public static void assertDoubleEquals(double expected, double result) { 27 if (expected != result) { 28 throw new Error("Expected: " + expected + ", found: " + result); 29 } 30 } 31 assertFloatEquals(float expected, float result)32 public static void assertFloatEquals(float expected, float result) { 33 if (expected != result) { 34 throw new Error("Expected: " + expected + ", found: " + result); 35 } 36 } 37 assertLongEquals(long expected, long result)38 public static void assertLongEquals(long expected, long result) { 39 if (expected != result) { 40 throw new Error("Expected: " + expected + ", found: " + result); 41 } 42 } 43 44 main(String[] args)45 public static void main(String[] args) { 46 Test test = new Test(); 47 long workJ = 2; 48 long workK = 3; 49 float workJ1 = 10.0f; 50 float workK1 = 15.0f; 51 int workJ2 = 10; 52 int workK2 = 15; 53 long workJ3 = 0xFAEFFFAB; 54 long workK3 = 0xF8E9DCBA; 55 56 for (long i = 0; i < iterations; i++) { 57 workJ = test.simplemethodMul(workJ, workK) + i; 58 } 59 assertLongEquals(workJ, 132855); 60 61 for (float i = 0.0f; i < iterations; i++) { 62 workJ1 = test.simplemethodRem(workJ1, workK1) + i; 63 } 64 assertFloatEquals(workJ1, 14.0f); 65 66 workJ2--; 67 68 try { 69 throw new Exception("Test"); 70 } catch (Exception e) { 71 workJ++; 72 } 73 74 for (int i = 0; i < iterations; i++) { 75 workJ2 = test.simplemethodInt(workJ2, workK2) + i; 76 } 77 assertIntEquals(workJ2, 152); 78 79 for (long i = 0; i < iterations; i++) { 80 workJ3 = test.simplemethodXor(workJ3, workK3) + i; 81 } 82 assertLongEquals(workJ3, 118891342); 83 } 84 } 85