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