blob: bd1a28149964de4487b9cfde56d944d8ce6df409 [file] [log] [blame]
Elliott Hughes5a8e3d52012-07-11 11:16:24 -07001/*
2 * Copyright (C) 2012 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/**
18 * Tests long division by zero for both / and %.
19 */
20public class ZeroTests {
21 public static void longDivTest() throws Exception {
22 longTest("longDivTest", true);
23 }
24
25 public static void longModTest() throws Exception {
26 longTest("longModTest", false);
27 }
28
29 private static void longTest(String name, boolean divide) throws Exception {
30 try {
31 if (divide) {
32 longDiv(1, 0);
33 } else {
34 longMod(1, 0);
35 }
36 throw new AssertionError(name + " failed to throw");
37 } catch (ArithmeticException expected) {
38 System.out.println(name + " passes");
39 }
40 }
41
42 private static long longDiv(long lhs, long rhs) {
43 return lhs / rhs;
44 }
45
46 private static long longMod(long lhs, long rhs) {
47 return lhs % rhs;
48 }
49}