Home | History | Annotate | Download | only in div_double
      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 dot.junit.opcodes.div_double;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.div_double.d.T_div_double_1;
     22 import dot.junit.opcodes.div_double.d.T_div_double_3;
     23 
     24 public class Test_div_double extends DxTestCase {
     25     /**
     26      * @title Arguments = 2.7d, 3.14d
     27      */
     28     public void testN1() {
     29 
     30         T_div_double_1 t = new T_div_double_1();
     31         assertEquals(0.8598726114649682d, t.run(2.7d, 3.14d));
     32     }
     33 
     34     /**
     35      * @title Dividend = 0
     36      */
     37     public void testN2() {
     38         T_div_double_1 t = new T_div_double_1();
     39         assertEquals(0d, t.run(0, 3.14d));
     40     }
     41 
     42     /**
     43      * @title Dividend is negative
     44      */
     45     public void testN3() {
     46 
     47         T_div_double_1 t = new T_div_double_1();
     48         assertEquals(-1.162962962962963d, t.run(-3.14d, 2.7d));
     49     }
     50 
     51     /**
     52      * @title Dividend is negative
     53      */
     54     public void testN4() {
     55 
     56         T_div_double_1 t = new T_div_double_1();
     57         assertEquals(-1.162962962962963d, t.run(-3.14d, 2.7d));
     58     }
     59 
     60     /**
     61      * @title Types of arguments - long, double. Dalvik doens't distinguish 64-bits types internally,
     62      * so this division of long and double makes no sense but shall not crash the VM.
     63      */
     64     public void testN5() {
     65         T_div_double_3 t = new T_div_double_3();
     66         try {
     67             t.run(3.14d, 12345l);
     68         } catch (Throwable e) {
     69         }
     70     }
     71 
     72     /**
     73      * @title Arguments = Double.POSITIVE_INFINITY,
     74      * Double.NEGATIVE_INFINITY
     75      */
     76     public void testB2() {
     77         T_div_double_1 t = new T_div_double_1();
     78         assertEquals(Double.NaN, t.run(Double.POSITIVE_INFINITY,
     79                 Double.NEGATIVE_INFINITY));
     80     }
     81 
     82     /**
     83      * @title Arguments = Double.POSITIVE_INFINITY, -2.7d
     84      */
     85     public void testB3() {
     86         T_div_double_1 t = new T_div_double_1();
     87         assertEquals(Double.NEGATIVE_INFINITY, t.run(Double.POSITIVE_INFINITY,
     88                 -2.7d));
     89     }
     90 
     91     /**
     92      * @title Arguments = -2.7d, Double.NEGATIVE_INFINITY
     93      */
     94     public void testB4() {
     95         T_div_double_1 t = new T_div_double_1();
     96         assertEquals(0d, t.run(-2.7d, Double.NEGATIVE_INFINITY));
     97     }
     98 
     99     /**
    100      * @title Arguments = 0, 0
    101      */
    102     public void testB5() {
    103         T_div_double_1 t = new T_div_double_1();
    104         assertEquals(Double.NaN, t.run(0, 0));
    105     }
    106 
    107     /**
    108      * @title Arguments = 0, -2.7
    109      */
    110     public void testB6() {
    111         T_div_double_1 t = new T_div_double_1();
    112         assertEquals(-0d, t.run(0, -2.7d));
    113     }
    114 
    115     /**
    116      * @title Arguments = -2.7, 0
    117      */
    118     public void testB7() {
    119         T_div_double_1 t = new T_div_double_1();
    120         assertEquals(Double.NEGATIVE_INFINITY, t.run(-2.7d, 0));
    121     }
    122 
    123     /**
    124      * @title Arguments = 1, Double.MAX_VALUE
    125      */
    126     public void testB8() {
    127         T_div_double_1 t = new T_div_double_1();
    128         assertEquals(Double.POSITIVE_INFINITY, t.run(1, Double.MIN_VALUE));
    129     }
    130 
    131     /**
    132      * @title Arguments = Double.MAX_VALUE, -1E-9f
    133      */
    134     public void testB9() {
    135         T_div_double_1 t = new T_div_double_1();
    136         assertEquals(Double.NEGATIVE_INFINITY, t.run(Double.MAX_VALUE, -1E-9f));
    137     }
    138 
    139 
    140 
    141     /**
    142      * @constraint B1
    143      * @title  types of arguments - float / double
    144      */
    145     public void testVFE1() {
    146         try {
    147             Class.forName("dot.junit.opcodes.div_double.d.T_div_double_2");
    148             fail("expected a verification exception");
    149         } catch (Throwable t) {
    150             DxUtil.checkVerifyException(t);
    151         }
    152     }
    153 
    154     /**
    155      * @constraint A24
    156      * @title  number of registers
    157      */
    158     public void testVFE2() {
    159         try {
    160             Class.forName("dot.junit.opcodes.div_double.d.T_div_double_5");
    161             fail("expected a verification exception");
    162         } catch (Throwable t) {
    163             DxUtil.checkVerifyException(t);
    164         }
    165     }
    166 
    167     /**
    168      * @constraint B1
    169      * @title  types of arguments - double / reference
    170      */
    171     public void testVFE3() {
    172         try {
    173             Class.forName("dot.junit.opcodes.div_double.d.T_div_double_4");
    174             fail("expected a verification exception");
    175         } catch (Throwable t) {
    176             DxUtil.checkVerifyException(t);
    177         }
    178     }
    179 
    180     /**
    181      * @constraint B1
    182      * @title  types of arguments - int / int
    183      */
    184     public void testVFE4() {
    185         try {
    186             Class.forName("dot.junit.opcodes.div_double.d.T_div_double_6");
    187             fail("expected a verification exception");
    188         } catch (Throwable t) {
    189             DxUtil.checkVerifyException(t);
    190         }
    191     }
    192 
    193 }
    194