Home | History | Annotate | Download | only in idiv
      1 /*
      2  * Copyright (C) 2008 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 package dxc.junit.opcodes.idiv;
     18 
     19 import dxc.junit.DxTestCase;
     20 import dxc.junit.DxUtil;
     21 import dxc.junit.opcodes.idiv.jm.T_idiv_1;
     22 
     23 public class Test_idiv extends DxTestCase {
     24 
     25     /**
     26      * @title Arguments = 8, 4
     27      */
     28     public void testN1() {
     29         T_idiv_1 t = new T_idiv_1();
     30         assertEquals(2, t.run(8, 4));
     31     }
     32 
     33     /**
     34      * @title  Rounding
     35      */
     36     public void testN2() {
     37         T_idiv_1 t = new T_idiv_1();
     38         assertEquals(268435455, t.run(1073741823, 4));
     39     }
     40 
     41     /**
     42      * @title  Dividend = 0
     43      */
     44     public void testN3() {
     45         T_idiv_1 t = new T_idiv_1();
     46         assertEquals(0, t.run(0, 4));
     47     }
     48 
     49     /**
     50      * @title  Dividend is negative
     51      */
     52     public void testN4() {
     53         T_idiv_1 t = new T_idiv_1();
     54         assertEquals(-3, t.run(-10, 3));
     55     }
     56 
     57     /**
     58      * @title  Divisor is negative
     59      */
     60     public void testN5() {
     61         T_idiv_1 t = new T_idiv_1();
     62         assertEquals(-357913941, t.run(1073741824, -3));
     63     }
     64 
     65     /**
     66      * @title  Both Dividend and divisor are negative
     67      */
     68     public void testN6() {
     69         T_idiv_1 t = new T_idiv_1();
     70         assertEquals(5965, t.run(-17895697, -3000));
     71     }
     72 
     73     /**
     74      * @title Arguments = Integer.MIN_VALUE, -1
     75      */
     76     public void testB1() {
     77         T_idiv_1 t = new T_idiv_1();
     78         // result is MIN_VALUE because overflow occurs in this case
     79         assertEquals(Integer.MIN_VALUE, t.run(Integer.MIN_VALUE, -1));
     80     }
     81 
     82     /**
     83      * @title Arguments = Integer.MIN_VALUE, 1
     84      */
     85     public void testB2() {
     86         T_idiv_1 t = new T_idiv_1();
     87         assertEquals(Integer.MIN_VALUE, t.run(Integer.MIN_VALUE, 1));
     88     }
     89 
     90     /**
     91      * @title Arguments = Integer.MAX_VALUE, 1
     92      */
     93     public void testB3() {
     94         T_idiv_1 t = new T_idiv_1();
     95         assertEquals(Integer.MAX_VALUE, t.run(Integer.MAX_VALUE, 1));
     96     }
     97 
     98     /**
     99      * @title Arguments = Integer.MIN_VALUE, Integer.MAX_VALUE
    100      */
    101     public void testB4() {
    102         T_idiv_1 t = new T_idiv_1();
    103         assertEquals(-1, t.run(Integer.MIN_VALUE, Integer.MAX_VALUE));
    104     }
    105 
    106     /**
    107      * @title Arguments = 1, Integer.MAX_VALUE
    108      */
    109     public void testB5() {
    110         T_idiv_1 t = new T_idiv_1();
    111         assertEquals(0, t.run(1, Integer.MAX_VALUE));
    112     }
    113 
    114     /**
    115      * @title Arguments = 1, Integer.MIN_VALUE
    116      */
    117     public void testB6() {
    118         T_idiv_1 t = new T_idiv_1();
    119         assertEquals(0, t.run(1, Integer.MIN_VALUE));
    120     }
    121 
    122     /**
    123      * @title  Divisor is 0
    124      */
    125     public void testE1() {
    126         T_idiv_1 t = new T_idiv_1();
    127         try {
    128             t.run(1, 0);
    129             fail("expected ArithmeticException");
    130         } catch (ArithmeticException ae) {
    131             // expected
    132         }
    133     }
    134 
    135     /**
    136      * @constraint 4.8.2.1
    137      * @title number of arguments
    138      */
    139     public void testVFE1() {
    140         try {
    141             Class.forName("dxc.junit.opcodes.idiv.jm.T_idiv_2");
    142             fail("expected a verification exception");
    143         } catch (Throwable t) {
    144             DxUtil.checkVerifyException(t);
    145         }
    146     }
    147 
    148     /**
    149      * @constraint 4.8.2.1
    150      * @title types of arguments - int / double
    151      */
    152     public void testVFE2() {
    153         try {
    154             Class.forName("dxc.junit.opcodes.idiv.jm.T_idiv_3");
    155             fail("expected a verification exception");
    156         } catch (Throwable t) {
    157             DxUtil.checkVerifyException(t);
    158         }
    159     }
    160 
    161     /**
    162      * @constraint 4.8.2.1
    163      * @title types of arguments - long / int
    164      */
    165     public void testVFE3() {
    166         try {
    167             Class.forName("dxc.junit.opcodes.idiv.jm.T_idiv_4");
    168             fail("expected a verification exception");
    169         } catch (Throwable t) {
    170             DxUtil.checkVerifyException(t);
    171         }
    172     }
    173 
    174     /**
    175      * @constraint 4.8.2.1
    176      * @title types of arguments - reference / int
    177      */
    178     public void testVFE4() {
    179         try {
    180             Class.forName("dxc.junit.opcodes.idiv.jm.T_idiv_5");
    181             fail("expected a verification exception");
    182         } catch (Throwable t) {
    183             DxUtil.checkVerifyException(t);
    184         }
    185     }
    186 
    187 }
    188