Home | History | Annotate | Download | only in double_to_int
      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.double_to_int;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.double_to_int.d.T_double_to_int_1;
     22 import dot.junit.opcodes.double_to_int.d.T_double_to_int_3;
     23 
     24 
     25 public class Test_double_to_int extends DxTestCase {
     26     /**
     27      * @title Argument = 2.9999999d
     28      */
     29     public void testN1() {
     30         T_double_to_int_1 t = new T_double_to_int_1();
     31         assertEquals(2, t.run(2.9999999d));
     32     }
     33 
     34     /**
     35      * @title Argument = 1
     36      */
     37     public void testN2() {
     38         T_double_to_int_1 t = new T_double_to_int_1();
     39         assertEquals(1, t.run(1d));
     40     }
     41 
     42     /**
     43      * @title Argument = -1
     44      */
     45     public void testN3() {
     46         T_double_to_int_1 t = new T_double_to_int_1();
     47         assertEquals(-1, t.run(-1d));
     48     }
     49 
     50     /**
     51      * @title Type of argument - long. Dalvik doens't distinguish 64-bits types internally,
     52      * so this conversion of long to int makes no sense but shall not crash the VM.
     53      */
     54     public void testN4() {
     55         T_double_to_int_3 t = new T_double_to_int_3();
     56         try {
     57             t.run(12345l);
     58         } catch (Throwable e) {
     59         }
     60     }
     61 
     62     /**
     63      * @title Argument = -0
     64      */
     65     public void testB1() {
     66         T_double_to_int_1 t = new T_double_to_int_1();
     67         assertEquals(0, t.run(-0d));
     68     }
     69 
     70     /**
     71      * @title Argument = Double.MAX_VALUE
     72      */
     73     public void testB2() {
     74         T_double_to_int_1 t = new T_double_to_int_1();
     75         assertEquals(Integer.MAX_VALUE, t.run(Double.MAX_VALUE));
     76     }
     77 
     78     /**
     79      * @title Argument = Double.MIN_VALUE
     80      */
     81     public void testB3() {
     82         T_double_to_int_1 t = new T_double_to_int_1();
     83         assertEquals(0, t.run(Double.MIN_VALUE));
     84     }
     85 
     86     /**
     87      * @title Argument = NaN
     88      */
     89     public void testB4() {
     90         T_double_to_int_1 t = new T_double_to_int_1();
     91         assertEquals(0, t.run(Double.NaN));
     92     }
     93 
     94     /**
     95      * @title Argument = POSITIVE_INFINITY
     96      */
     97     public void testB5() {
     98         T_double_to_int_1 t = new T_double_to_int_1();
     99         assertEquals(Integer.MAX_VALUE, t.run(Double.POSITIVE_INFINITY));
    100     }
    101 
    102     /**
    103      * @title Argument = NEGATIVE_INFINITY
    104      */
    105     public void testB6() {
    106         T_double_to_int_1 t = new T_double_to_int_1();
    107         assertEquals(Integer.MIN_VALUE, t.run(Double.NEGATIVE_INFINITY));
    108     }
    109 
    110 
    111 
    112     /**
    113      * @constraint B1
    114      * @title  type of argument - float
    115      */
    116     public void testVFE2() {
    117         try {
    118             Class.forName("dot.junit.opcodes.double_to_int.d.T_double_to_int_2");
    119             fail("expected a verification exception");
    120         } catch (Throwable t) {
    121             DxUtil.checkVerifyException(t);
    122         }
    123     }
    124 
    125     /**
    126      *
    127      * @constraint A24
    128      * @title  number of registers
    129      */
    130     public void testVFE3() {
    131         try {
    132             Class.forName("dot.junit.opcodes.double_to_int.d.T_double_to_int_5");
    133             fail("expected a verification exception");
    134         } catch (Throwable t) {
    135             DxUtil.checkVerifyException(t);
    136         }
    137     }
    138 
    139     /**
    140      *
    141      * @constraint B1
    142      * @title  type of argument - reference
    143      */
    144     public void testVFE4() {
    145         try {
    146             Class.forName("dot.junit.opcodes.double_to_int.d.T_double_to_int_4");
    147             fail("expected a verification exception");
    148         } catch (Throwable t) {
    149             DxUtil.checkVerifyException(t);
    150         }
    151     }
    152 
    153     /**
    154      *
    155      * @constraint B1
    156      * @title  type of argument - reference
    157      */
    158     public void testVFE5() {
    159         try {
    160             Class.forName("dot.junit.opcodes.double_to_int.d.T_double_to_int_6");
    161             fail("expected a verification exception");
    162         } catch (Throwable t) {
    163             DxUtil.checkVerifyException(t);
    164         }
    165     }
    166 
    167 }
    168