diff options
Diffstat (limited to 'jack-tests/tests/com/android/jack/arithmetic')
26 files changed, 957 insertions, 0 deletions
diff --git a/jack-tests/tests/com/android/jack/arithmetic/test001/dx/Tests.java b/jack-tests/tests/com/android/jack/arithmetic/test001/dx/Tests.java new file mode 100644 index 0000000..68f00d2 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test001/dx/Tests.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test001.dx; + +import com.android.jack.arithmetic.test001.jack.Add; +import com.android.jack.arithmetic.test001.jack.And; +import com.android.jack.arithmetic.test001.jack.Div; +import com.android.jack.arithmetic.test001.jack.Mod; +import com.android.jack.arithmetic.test001.jack.Mul; +import com.android.jack.arithmetic.test001.jack.Or; +import com.android.jack.arithmetic.test001.jack.Shl; +import com.android.jack.arithmetic.test001.jack.Shr; +import com.android.jack.arithmetic.test001.jack.Sub; +import com.android.jack.arithmetic.test001.jack.Ushr; +import com.android.jack.arithmetic.test001.jack.Xor; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Tests about arithmetic. + */ +public class Tests { + + @Test + public void test1() { + Assert.assertEquals(0, Add.apply(0, 0)); + Assert.assertEquals(10 + 7, Add.apply(10, 7)); + Assert.assertEquals(21 - 3, Sub.apply(21, 3)); + Assert.assertEquals(-1 & 19, And.apply(-1, 19)); + Assert.assertEquals(21 & 54, And.apply(21, 54)); + Assert.assertEquals(210 / 10, Div.apply(210, 10)); + Assert.assertEquals(119 / 5, Div.apply(119, 5)); + Assert.assertEquals(119 % 5, Mod.apply(119, 5)); + Assert.assertEquals(6 * 5, Mul.apply(6, 5)); + Assert.assertEquals(30 | 1, Or.apply(30, 1)); + Assert.assertEquals(-1 | 27, Or.apply(-1, 27)); + Assert.assertEquals(-1 >> 10, Shr.apply(-1, 10)); + Assert.assertEquals(472758 >> 3, Shr.apply(472758, 3)); + Assert.assertEquals(-1 >>> 10, Ushr.apply(-1, 10)); + Assert.assertEquals(472758 >>> 3, Ushr.apply(472758, 3)); + Assert.assertEquals(-1 << 10, Shl.apply(-1, 10)); + Assert.assertEquals(472758 << 3, Shl.apply(472758, 3)); + Assert.assertEquals(472758 ^ 758996, Xor.apply(472758, 758996)); +} + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Add.java b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Add.java new file mode 100644 index 0000000..05c31ca --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Add.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test001.jack; + +/** + * Add test. + */ +public class Add { + + public static int apply(byte a, byte b) { + return a + b; + } + + public static int apply(byte a, char b) { + return a + b; + } + + public static int apply(byte a, short b) { + return a + b; + } + + public static int apply(byte a, int b) { + return a + b; + } + + public static int apply(char a, byte b) { + return a + b; + } + + public static int apply(char a, char b) { + return a + b; + } + + public static int apply(short a, byte b) { + return a + b; + } + + public static int apply(short a, short b) { + return a + b; + } + + public static int apply(int a, byte b) { + return a + b; + } + + public static int apply(int a, int b) { + return a + b; + } + + public static long apply(long a, long b) { + return a + b; + } + + public static float apply(float a, float b) { + return a + b; + } + + public static double apply(double a, double b) { + return a + b; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test001/jack/And.java b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/And.java new file mode 100644 index 0000000..e772653 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/And.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test001.jack; + +/** + * Bitwise and test + */ +public class And { + + public static int apply(int a, int b) { + return a & b; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Div.java b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Div.java new file mode 100644 index 0000000..04f85f7 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Div.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test001.jack; + +/** + * Division test. + */ +public class Div { + + public static int apply(int a, int b) { + return a / b; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Mod.java b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Mod.java new file mode 100644 index 0000000..cd0300c --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Mod.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test001.jack; + +/** + * Modulo test. + */ +public class Mod { + + public static int apply(int a, int b) { + return a % b; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Mul.java b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Mul.java new file mode 100644 index 0000000..8a10d0c --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Mul.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test001.jack; + +/** + * Multiply test. + */ +public class Mul { + + public static int apply(int a, int b) { + return a * b; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Or.java b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Or.java new file mode 100644 index 0000000..388cd07 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Or.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test001.jack; + +/** + * Bitwise or test. + */ +public class Or { + + public static int apply(int a, int b) { + return a | b; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Shl.java b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Shl.java new file mode 100644 index 0000000..9a9b977 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Shl.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test001.jack; + +/** + * Bitwise left shift test. + */ +public class Shl { + + public static int apply(int a, int b) { + return a << b; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Shr.java b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Shr.java new file mode 100644 index 0000000..df3526c --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Shr.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test001.jack; + +/** + * Bitwise signed right shift test. + */ +public class Shr { + + public static int apply(int a, int b) { + return a >> b; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Sub.java b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Sub.java new file mode 100644 index 0000000..a0a5d66 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Sub.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test001.jack; + +/** + * Subtract test. + */ +public class Sub { + + public static int apply(int a, int b) { + return a - b; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Ushr.java b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Ushr.java new file mode 100644 index 0000000..b8f61d3 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Ushr.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test001.jack; + +/** + * Bitwise unsigned right shift test. + */ +public class Ushr { + + public static int apply(int a, int b) { + return a >>> b; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Xor.java b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Xor.java new file mode 100644 index 0000000..49e48e6 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test001/jack/Xor.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test001.jack; + +/** + * Bitwise xor test. + */ +public class Xor { + + public static int apply(int a, int b) { + return a ^ b; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test002/dx/Tests.java b/jack-tests/tests/com/android/jack/arithmetic/test002/dx/Tests.java new file mode 100644 index 0000000..7a06578 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test002/dx/Tests.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test002.dx; + +import org.junit.Assert; +import org.junit.Test; + +import com.android.jack.arithmetic.test002.jack.Add; +import com.android.jack.arithmetic.test002.jack.And; +import com.android.jack.arithmetic.test002.jack.Div; +import com.android.jack.arithmetic.test002.jack.Mod; +import com.android.jack.arithmetic.test002.jack.Mul; +import com.android.jack.arithmetic.test002.jack.Or; +import com.android.jack.arithmetic.test002.jack.Shl; +import com.android.jack.arithmetic.test002.jack.Shr; +import com.android.jack.arithmetic.test002.jack.Sub; +import com.android.jack.arithmetic.test002.jack.Ushr; +import com.android.jack.arithmetic.test002.jack.Xor; + +/** + * Tests about arithmetic. + */ +public class Tests { + + @Test + public void test1() { + Assert.assertEquals(1 + 2, Add.apply(1, 2)); + Assert.assertEquals(21 - 3, Sub.apply(21, 3)); + Assert.assertEquals(3 & 2, And.apply(3, 2)); + Assert.assertEquals(4 | 8, Or.apply(4, 8)); + Assert.assertEquals(4 ^ 8, Xor.apply(4, 8)); + Assert.assertEquals(8 ^ 8, Xor.apply(8, 8)); + Assert.assertEquals(8 / 4, Div.apply(8, 4)); + Assert.assertEquals(8 % 4, Mod.apply(8, 4)); + Assert.assertEquals(8 % 5, Mod.apply(8, 5)); + Assert.assertEquals(8 * 5, Mul.apply(8, 5)); + Assert.assertEquals(-1 >> 10, Shr.apply(-1, 10)); + Assert.assertEquals(472758 >> 3, Shr.apply(472758, 3)); + Assert.assertEquals(-1 >>> 10, Ushr.apply(-1, 10)); + Assert.assertEquals(472758 >>> 3, Ushr.apply(472758, 3)); + Assert.assertEquals(-1 << 10, Shl.apply(-1, 10)); + Assert.assertEquals(472758 << 3, Shl.apply(472758, 3)); + Assert.assertTrue(Or.applyBool(true, false)); + Assert.assertTrue(Xor.applyBool(true, false)); + Assert.assertFalse(And.applyBool(true, false)); + +} + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Add.java b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Add.java new file mode 100644 index 0000000..2c744df --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Add.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test002.jack; + +/** + * Add test. + */ +public class Add { + + public static int apply(int a, int b) { + a += b; + return a; + } +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test002/jack/And.java b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/And.java new file mode 100644 index 0000000..8ed8da3 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/And.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test002.jack; + +/** + * Bitwise and test + */ +public class And { + + public static int apply(int a, int b) { + a &= b; + return a; + } + + public static boolean applyBool(boolean a, boolean b) { + if ( a && (a & b)) { + return true; + } + return false; + } +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Div.java b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Div.java new file mode 100644 index 0000000..e9b7a28 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Div.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test002.jack; + +/** + * Division test. + */ +public class Div { + + public static int apply(int a, int b) { + a /= b; + return a; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Mod.java b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Mod.java new file mode 100644 index 0000000..9610caf --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Mod.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test002.jack; + +/** + * Modulo test. + */ +public class Mod { + + public static int apply(int a, int b) { + a %= b; + return a; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Mul.java b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Mul.java new file mode 100644 index 0000000..9eea229 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Mul.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test002.jack; + +/** + * Multiply test. + */ +public class Mul { + + public static int apply(int a, int b) { + a *= b; + return a; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Or.java b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Or.java new file mode 100644 index 0000000..a574a83 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Or.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test002.jack; + +/** + * Bitwise or test. + */ +public class Or { + + public static int apply(int a, int b) { + a |= b; + return a; + } + + public static boolean applyBool(boolean a, boolean b) { + if ( a && (a | b)) { + return true; + } + return false; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Shl.java b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Shl.java new file mode 100644 index 0000000..8f0cf3b --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Shl.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test002.jack; + +/** + * Bitwise left shift test. + */ +public class Shl { + + public static int apply(int a, int b) { + a <<= b; + return a ; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Shr.java b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Shr.java new file mode 100644 index 0000000..754a691 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Shr.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test002.jack; + +/** + * Bitwise signed right shift test. + */ +public class Shr { + + public static int apply(int a, int b) { + a >>= b; + return a; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Sub.java b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Sub.java new file mode 100644 index 0000000..dc3bb04 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Sub.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test002.jack; + +/** + * Subtract test. + */ +public class Sub { + + public static int apply(int a, int b) { + a -= b; + return a; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Ushr.java b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Ushr.java new file mode 100644 index 0000000..8bd67a6 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Ushr.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test002.jack; + +/** + * Bitwise unsigned right shift test. + */ +public class Ushr { + + public static int apply(int a, int b) { + a >>>= b; + return a; + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Xor.java b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Xor.java new file mode 100644 index 0000000..5757f1f --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test002/jack/Xor.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test002.jack; + +/** + * Bitwise xor test. + */ +public class Xor { + + public static int apply(int a, int b) { + a ^= b; + return a; + } + + public static boolean applyBool(boolean a, boolean b) { + if ( a && (a ^ b)) { + return true; + } + return false; + } +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test003/dx/Tests.java b/jack-tests/tests/com/android/jack/arithmetic/test003/dx/Tests.java new file mode 100644 index 0000000..87eff98 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test003/dx/Tests.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test003.dx; + +import junit.framework.Assert; + +import org.junit.Test; + +import com.android.jack.arithmetic.test003.jack.ZeroUsage; + +/** + * Tests about arithmetic with zero. + */ +public class Tests { + + @Test + public void test1() { + try { + ZeroUsage.divByZeroInt(); + Assert.fail(); + } catch (ArithmeticException e) { + // Test is ok + } + + try { + ZeroUsage.modByZeroInt(); + Assert.fail(); + } catch (ArithmeticException e) { + // Test is ok + } + + try { + ZeroUsage.divByZeroLong(); + Assert.fail(); + } catch (ArithmeticException e) { + // Test is ok + } + + try { + ZeroUsage.modByZeroLong(); + Assert.fail(); + } catch (ArithmeticException e) { + // Test is ok + } + + try { + ZeroUsage.divByZeroDouble(); + } catch (ArithmeticException e) { + Assert.fail(); + } + + try { + ZeroUsage.modByZeroDouble(); + } catch (ArithmeticException e) { + Assert.fail(); + } + + try { + ZeroUsage.divByZeroFloat(); + } catch (ArithmeticException e) { + Assert.fail(); + } + + try { + ZeroUsage.modByZeroFloat(); + } catch (ArithmeticException e) { + Assert.fail(); + } + } + +} diff --git a/jack-tests/tests/com/android/jack/arithmetic/test003/jack/ZeroUsage.java b/jack-tests/tests/com/android/jack/arithmetic/test003/jack/ZeroUsage.java new file mode 100644 index 0000000..ca65d31 --- /dev/null +++ b/jack-tests/tests/com/android/jack/arithmetic/test003/jack/ZeroUsage.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.arithmetic.test003.jack; + +/** + * Division by zero test. + */ +public class ZeroUsage { + + public static int divByZeroInt() { + return 1 / 0; + } + + public static int modByZeroInt() { + return 1 % 0; + } + + public static long divByZeroLong() { + return 1L / 0L; + } + + public static long modByZeroLong() { + return 1L % 0L; + } + + public static float divByZeroFloat() { + return 1f / 0f; + } + + public static float modByZeroFloat() { + return 1f % 0f; + } + + public static double divByZeroDouble() { + return 1d / 0d; + } + + public static double modByZeroDouble() { + return 1d % 0d; + } +} |