< prev index next >

test/jdk/java/lang/Math/DivModTests.java

Print this page




  74         testIntFloorDivMod(4, -3, -2, -2);
  75         testIntFloorDivMod(3, -3, -1, 0);
  76         testIntFloorDivMod(2, -3, -1, -1);
  77         testIntFloorDivMod(1, -3, -1, -2);
  78         testIntFloorDivMod(0, -3, 0, 0);
  79         testIntFloorDivMod(-1, 3, -1, 2);
  80         testIntFloorDivMod(-2, 3, -1, 1);
  81         testIntFloorDivMod(-3, 3, -1, 0);
  82         testIntFloorDivMod(-4, 3, -2, 2);
  83         testIntFloorDivMod(-1, -3, 0, -1);
  84         testIntFloorDivMod(-2, -3, 0, -2);
  85         testIntFloorDivMod(-3, -3, 1, 0);
  86         testIntFloorDivMod(-4, -3, 1, -1);
  87         testIntFloorDivMod(Integer.MAX_VALUE, 1, Integer.MAX_VALUE, 0);
  88         testIntFloorDivMod(Integer.MAX_VALUE, -1, -Integer.MAX_VALUE, 0);
  89         testIntFloorDivMod(Integer.MAX_VALUE, 3, 715827882, 1);
  90         testIntFloorDivMod(Integer.MAX_VALUE - 1, 3, 715827882, 0);
  91         testIntFloorDivMod(Integer.MIN_VALUE, 3, -715827883, 1);
  92         testIntFloorDivMod(Integer.MIN_VALUE + 1, 3, -715827883, 2);
  93         testIntFloorDivMod(Integer.MIN_VALUE + 1, -1, Integer.MAX_VALUE, 0);
  94         testIntFloorDivMod(Integer.MAX_VALUE, Integer.MAX_VALUE, 1, 0);
  95         testIntFloorDivMod(Integer.MAX_VALUE, Integer.MIN_VALUE, -1, -1);
  96         testIntFloorDivMod(Integer.MIN_VALUE, Integer.MIN_VALUE, 1, 0);
  97         testIntFloorDivMod(Integer.MIN_VALUE, Integer.MAX_VALUE, -2, 2147483646);
  98         // Special case of integer overflow
  99         testIntFloorDivMod(Integer.MIN_VALUE, -1, Integer.MIN_VALUE, 0);
 100     }
 101 
 102     /**
 103      * Test FloorDiv and then FloorMod with int data.
 104      */
 105     static void testIntFloorDivMod(int x, int y, Object divExpected, Object modExpected) {
 106         testIntFloorDiv(x, y, divExpected);
 107         testIntFloorMod(x, y, modExpected);
 108     }
 109 
 110     /**
 111      * Test FloorDiv with int data.
 112      */
 113     static void testIntFloorDiv(int x, int y, Object expected) {
 114         Object result = doFloorDiv(x, y);
 115         if (!resultEquals(result, expected)) {
 116             fail("FAIL: Math.floorDiv(%d, %d) = %s; expected %s%n", x, y, result, expected);
 117         }


 166         testLongFloorDivMod(3L, -3L, -1L, 0l);
 167         testLongFloorDivMod(2L, -3L, -1L, -1L);
 168         testLongFloorDivMod(1L, -3L, -1L, -2L);
 169         testLongFloorDivMod(0L, -3L, 0L, 0L);
 170         testLongFloorDivMod(-1L, 3L, -1L, 2L);
 171         testLongFloorDivMod(-2L, 3L, -1L, 1L);
 172         testLongFloorDivMod(-3L, 3L, -1L, 0L);
 173         testLongFloorDivMod(-4L, 3L, -2L, 2L);
 174         testLongFloorDivMod(-1L, -3L, 0L, -1L);
 175         testLongFloorDivMod(-2L, -3L, 0L, -2L);
 176         testLongFloorDivMod(-3L, -3L, 1L, 0L);
 177         testLongFloorDivMod(-4L, -3L, 1L, -1L);
 178 
 179         testLongFloorDivMod(Long.MAX_VALUE, 1, Long.MAX_VALUE, 0L);
 180         testLongFloorDivMod(Long.MAX_VALUE, -1, -Long.MAX_VALUE, 0L);
 181         testLongFloorDivMod(Long.MAX_VALUE, 3L, Long.MAX_VALUE / 3L, 1L);
 182         testLongFloorDivMod(Long.MAX_VALUE - 1L, 3L, (Long.MAX_VALUE - 1L) / 3L, 0L);
 183         testLongFloorDivMod(Long.MIN_VALUE, 3L, Long.MIN_VALUE / 3L - 1L, 1L);
 184         testLongFloorDivMod(Long.MIN_VALUE + 1L, 3L, Long.MIN_VALUE / 3L - 1L, 2L);
 185         testLongFloorDivMod(Long.MIN_VALUE + 1, -1, Long.MAX_VALUE, 0L);
 186         testLongFloorDivMod(Long.MAX_VALUE, Long.MAX_VALUE, 1L, 0L);
 187         testLongFloorDivMod(Long.MAX_VALUE, Long.MIN_VALUE, -1L, -1L);
 188         testLongFloorDivMod(Long.MIN_VALUE, Long.MIN_VALUE, 1L, 0L);
 189         testLongFloorDivMod(Long.MIN_VALUE, Long.MAX_VALUE, -2L, 9223372036854775806L);
 190         // Special case of integer overflow
 191         testLongFloorDivMod(Long.MIN_VALUE, -1, Long.MIN_VALUE, 0L);
 192     }
 193 
 194     /**
 195      * Test the long floorDiv and floorMod methods.
 196      * Math and StrictMath are tested and the same results are expected for both.
 197      */
 198     static void testLongFloorDivMod(long x, long y, Object divExpected, Object modExpected) {
 199         testLongFloorDiv(x, y, divExpected);
 200         testLongFloorMod(x, y, modExpected);
 201     }
 202 
 203     /**
 204      * Test FloorDiv with long arguments against expected value.
 205      * The expected value is usually a Long but in some cases  is
 206      * an ArithmeticException.
 207      *
 208      * @param x dividend
 209      * @param y modulus


 274         testLongIntFloorDivMod(3L, -3, -1L, 0);
 275         testLongIntFloorDivMod(2L, -3, -1L, -1);
 276         testLongIntFloorDivMod(1L, -3, -1L, -2);
 277         testLongIntFloorDivMod(0L, -3, 0L, 0);
 278         testLongIntFloorDivMod(-1L, 3, -1L, 2);
 279         testLongIntFloorDivMod(-2L, 3, -1L, 1);
 280         testLongIntFloorDivMod(-3L, 3, -1L, 0);
 281         testLongIntFloorDivMod(-4L, 3, -2L, 2);
 282         testLongIntFloorDivMod(-1L, -3, 0L, -1);
 283         testLongIntFloorDivMod(-2L, -3, 0L, -2);
 284         testLongIntFloorDivMod(-3L, -3, 1L, 0);
 285         testLongIntFloorDivMod(-4L, -3, 1L, -1);
 286 
 287         testLongIntFloorDivMod(Long.MAX_VALUE, 1, Long.MAX_VALUE, 0L);
 288         testLongIntFloorDivMod(Long.MAX_VALUE, -1, -Long.MAX_VALUE, 0L);
 289         testLongIntFloorDivMod(Long.MAX_VALUE, 3, Long.MAX_VALUE / 3L, 1L);
 290         testLongIntFloorDivMod(Long.MAX_VALUE - 1L, 3, (Long.MAX_VALUE - 1L) / 3L, 0L);
 291         testLongIntFloorDivMod(Long.MIN_VALUE, 3, Long.MIN_VALUE / 3L - 1L, 1L);
 292         testLongIntFloorDivMod(Long.MIN_VALUE + 1L, 3, Long.MIN_VALUE / 3L - 1L, 2L);
 293         testLongIntFloorDivMod(Long.MIN_VALUE + 1, -1, Long.MAX_VALUE, 0L);
 294         testLongIntFloorDivMod(Long.MAX_VALUE, Integer.MAX_VALUE, 4294967298L, 1);
 295         testLongIntFloorDivMod(Long.MAX_VALUE, Integer.MIN_VALUE, -4294967296L, -1);
 296         testLongIntFloorDivMod(Long.MIN_VALUE, Integer.MIN_VALUE, 4294967296L, 0);
 297         testLongIntFloorDivMod(Long.MIN_VALUE, Integer.MAX_VALUE, -4294967299L, 2147483645);
 298         // Special case of integer overflow
 299         testLongIntFloorDivMod(Long.MIN_VALUE, -1, Long.MIN_VALUE, 0L);
 300     }
 301 
 302     /**
 303      * Test the integer floorDiv and floorMod methods.
 304      * Math and StrictMath are tested and the same results are expected for both.
 305      */
 306     static void testLongIntFloorDivMod(long x, int y, Object divExpected, Object modExpected) {
 307         testLongIntFloorDiv(x, y, divExpected);
 308         testLongIntFloorMod(x, y, modExpected);
 309     }
 310 
 311     /**
 312      * Test FloorDiv with long arguments against expected value.
 313      * The expected value is usually a Long but in some cases  is
 314      * an ArithmeticException.
 315      *
 316      * @param x dividend
 317      * @param y modulus




  74         testIntFloorDivMod(4, -3, -2, -2);
  75         testIntFloorDivMod(3, -3, -1, 0);
  76         testIntFloorDivMod(2, -3, -1, -1);
  77         testIntFloorDivMod(1, -3, -1, -2);
  78         testIntFloorDivMod(0, -3, 0, 0);
  79         testIntFloorDivMod(-1, 3, -1, 2);
  80         testIntFloorDivMod(-2, 3, -1, 1);
  81         testIntFloorDivMod(-3, 3, -1, 0);
  82         testIntFloorDivMod(-4, 3, -2, 2);
  83         testIntFloorDivMod(-1, -3, 0, -1);
  84         testIntFloorDivMod(-2, -3, 0, -2);
  85         testIntFloorDivMod(-3, -3, 1, 0);
  86         testIntFloorDivMod(-4, -3, 1, -1);
  87         testIntFloorDivMod(Integer.MAX_VALUE, 1, Integer.MAX_VALUE, 0);
  88         testIntFloorDivMod(Integer.MAX_VALUE, -1, -Integer.MAX_VALUE, 0);
  89         testIntFloorDivMod(Integer.MAX_VALUE, 3, 715827882, 1);
  90         testIntFloorDivMod(Integer.MAX_VALUE - 1, 3, 715827882, 0);
  91         testIntFloorDivMod(Integer.MIN_VALUE, 3, -715827883, 1);
  92         testIntFloorDivMod(Integer.MIN_VALUE + 1, 3, -715827883, 2);
  93         testIntFloorDivMod(Integer.MIN_VALUE + 1, -1, Integer.MAX_VALUE, 0);




  94         // Special case of integer overflow
  95         testIntFloorDivMod(Integer.MIN_VALUE, -1, Integer.MIN_VALUE, 0);
  96     }
  97 
  98     /**
  99      * Test FloorDiv and then FloorMod with int data.
 100      */
 101     static void testIntFloorDivMod(int x, int y, Object divExpected, Object modExpected) {
 102         testIntFloorDiv(x, y, divExpected);
 103         testIntFloorMod(x, y, modExpected);
 104     }
 105 
 106     /**
 107      * Test FloorDiv with int data.
 108      */
 109     static void testIntFloorDiv(int x, int y, Object expected) {
 110         Object result = doFloorDiv(x, y);
 111         if (!resultEquals(result, expected)) {
 112             fail("FAIL: Math.floorDiv(%d, %d) = %s; expected %s%n", x, y, result, expected);
 113         }


 162         testLongFloorDivMod(3L, -3L, -1L, 0l);
 163         testLongFloorDivMod(2L, -3L, -1L, -1L);
 164         testLongFloorDivMod(1L, -3L, -1L, -2L);
 165         testLongFloorDivMod(0L, -3L, 0L, 0L);
 166         testLongFloorDivMod(-1L, 3L, -1L, 2L);
 167         testLongFloorDivMod(-2L, 3L, -1L, 1L);
 168         testLongFloorDivMod(-3L, 3L, -1L, 0L);
 169         testLongFloorDivMod(-4L, 3L, -2L, 2L);
 170         testLongFloorDivMod(-1L, -3L, 0L, -1L);
 171         testLongFloorDivMod(-2L, -3L, 0L, -2L);
 172         testLongFloorDivMod(-3L, -3L, 1L, 0L);
 173         testLongFloorDivMod(-4L, -3L, 1L, -1L);
 174 
 175         testLongFloorDivMod(Long.MAX_VALUE, 1, Long.MAX_VALUE, 0L);
 176         testLongFloorDivMod(Long.MAX_VALUE, -1, -Long.MAX_VALUE, 0L);
 177         testLongFloorDivMod(Long.MAX_VALUE, 3L, Long.MAX_VALUE / 3L, 1L);
 178         testLongFloorDivMod(Long.MAX_VALUE - 1L, 3L, (Long.MAX_VALUE - 1L) / 3L, 0L);
 179         testLongFloorDivMod(Long.MIN_VALUE, 3L, Long.MIN_VALUE / 3L - 1L, 1L);
 180         testLongFloorDivMod(Long.MIN_VALUE + 1L, 3L, Long.MIN_VALUE / 3L - 1L, 2L);
 181         testLongFloorDivMod(Long.MIN_VALUE + 1, -1, Long.MAX_VALUE, 0L);




 182         // Special case of integer overflow
 183         testLongFloorDivMod(Long.MIN_VALUE, -1, Long.MIN_VALUE, 0L);
 184     }
 185 
 186     /**
 187      * Test the long floorDiv and floorMod methods.
 188      * Math and StrictMath are tested and the same results are expected for both.
 189      */
 190     static void testLongFloorDivMod(long x, long y, Object divExpected, Object modExpected) {
 191         testLongFloorDiv(x, y, divExpected);
 192         testLongFloorMod(x, y, modExpected);
 193     }
 194 
 195     /**
 196      * Test FloorDiv with long arguments against expected value.
 197      * The expected value is usually a Long but in some cases  is
 198      * an ArithmeticException.
 199      *
 200      * @param x dividend
 201      * @param y modulus


 266         testLongIntFloorDivMod(3L, -3, -1L, 0);
 267         testLongIntFloorDivMod(2L, -3, -1L, -1);
 268         testLongIntFloorDivMod(1L, -3, -1L, -2);
 269         testLongIntFloorDivMod(0L, -3, 0L, 0);
 270         testLongIntFloorDivMod(-1L, 3, -1L, 2);
 271         testLongIntFloorDivMod(-2L, 3, -1L, 1);
 272         testLongIntFloorDivMod(-3L, 3, -1L, 0);
 273         testLongIntFloorDivMod(-4L, 3, -2L, 2);
 274         testLongIntFloorDivMod(-1L, -3, 0L, -1);
 275         testLongIntFloorDivMod(-2L, -3, 0L, -2);
 276         testLongIntFloorDivMod(-3L, -3, 1L, 0);
 277         testLongIntFloorDivMod(-4L, -3, 1L, -1);
 278 
 279         testLongIntFloorDivMod(Long.MAX_VALUE, 1, Long.MAX_VALUE, 0L);
 280         testLongIntFloorDivMod(Long.MAX_VALUE, -1, -Long.MAX_VALUE, 0L);
 281         testLongIntFloorDivMod(Long.MAX_VALUE, 3, Long.MAX_VALUE / 3L, 1L);
 282         testLongIntFloorDivMod(Long.MAX_VALUE - 1L, 3, (Long.MAX_VALUE - 1L) / 3L, 0L);
 283         testLongIntFloorDivMod(Long.MIN_VALUE, 3, Long.MIN_VALUE / 3L - 1L, 1L);
 284         testLongIntFloorDivMod(Long.MIN_VALUE + 1L, 3, Long.MIN_VALUE / 3L - 1L, 2L);
 285         testLongIntFloorDivMod(Long.MIN_VALUE + 1, -1, Long.MAX_VALUE, 0L);




 286         // Special case of integer overflow
 287         testLongIntFloorDivMod(Long.MIN_VALUE, -1, Long.MIN_VALUE, 0L);
 288     }
 289 
 290     /**
 291      * Test the integer floorDiv and floorMod methods.
 292      * Math and StrictMath are tested and the same results are expected for both.
 293      */
 294     static void testLongIntFloorDivMod(long x, int y, Object divExpected, Object modExpected) {
 295         testLongIntFloorDiv(x, y, divExpected);
 296         testLongIntFloorMod(x, y, modExpected);
 297     }
 298 
 299     /**
 300      * Test FloorDiv with long arguments against expected value.
 301      * The expected value is usually a Long but in some cases  is
 302      * an ArithmeticException.
 303      *
 304      * @param x dividend
 305      * @param y modulus


< prev index next >