1 /*
2  * Copyright (C) 2015 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 public class Main {
19 
main(String[] args)20   public static void main(String[] args) {
21     assertEqual(4, add3(1));
22     assertEqual(4l, add3(1l));
23     assertEqual(4f, add3(1f));
24     assertEqual(4d, add3(1d));
25   }
26 
add3(int a)27   public static int add3(int a) {
28     return 1 + a + 2;
29   }
30 
add3(long a)31   public static long add3(long a) {
32     return 1l + a + 2l;
33   }
34 
add3(float a)35   public static float add3(float a) {
36     return 1f + a + 2f;
37   }
38 
add3(double a)39   public static double add3(double a) {
40     return 1d + a + 2d;
41   }
42 
assertEqual(int a, int b)43   public static void assertEqual(int a, int b) {
44     if (a != b) {
45       throw new RuntimeException("Expected: " + a + " Found: " + b);
46     }
47   }
48 
assertEqual(long a, long b)49   public static void assertEqual(long a, long b) {
50     if (a != b) {
51       throw new RuntimeException("Expected: " + a + " Found: " + b);
52     }
53   }
54 
assertEqual(float a, float b)55   public static void assertEqual(float a, float b) {
56     boolean aproxEquals = (a > b)
57       ? ((a - b) < 0.0001f)
58       : ((b - a) < 0.0001f);
59     if (!aproxEquals) {
60       throw new RuntimeException("Expected: " + a + " Found: " + b);
61     }
62   }
63 
assertEqual(double a, double b)64   public static void assertEqual(double a, double b) {
65     boolean aproxEquals = (a > b)
66       ? ((a - b) < 0.0001d)
67       : ((b - a) < 0.0001d);
68     if (!aproxEquals) {
69       throw new RuntimeException("Expected: " + a + " Found: " + b);
70     }
71   }
72 }
73