### Question:
Gmp { public static BigInteger modInverse(BigInteger val, BigInteger modulus) { if (modulus.signum() <= 0) { throw new ArithmeticException("modulus must be positive"); } return INSTANCE.get().modInverseImpl(val, modulus); } private  Gmp(); static void checkLoaded(); static int kronecker(BigInteger a, BigInteger p); static BigInteger modPowInsecure(BigInteger base, BigInteger exponent,
      BigInteger modulus); static BigInteger modInverse(BigInteger val, BigInteger modulus); static BigInteger exactDivide(BigInteger dividend, BigInteger divisor); static BigInteger gcd(BigInteger value1, BigInteger value2);  }### Answer:
@Test public void testModInverse() { assertEquals(BigInteger.valueOf(2), modInverse(BigInteger.valueOf(3), BigInteger.valueOf(5))); Random rnd = new Random(); BigInteger m = new BigInteger(1024, rnd).nextProbablePrime(); for (int i = 0; i < 100; i++) { BigInteger x = new BigInteger(1023, rnd); assertEquals(x.modInverse(m), modInverse(x, m)); } }
@Test public void testModInverseSmallExhaustive() { for (int val = 10; val >= 0; --val) { for (int mod = 10; mod >= -1; --mod) { BigInteger bVal = BigInteger.valueOf(val); BigInteger bMod = BigInteger.valueOf(mod); try { BigInteger expected = bVal.modInverse(bMod); BigInteger actual = modInverse(bVal, bMod); assertEquals(String.format("val %d, mod %d", val, mod) + mod, expected, actual); } catch (ArithmeticException e) { try { modInverse(bVal, bMod); fail("ArithmeticException expected"); } catch (ArithmeticException expected) { } } } } }
@Test public void testModInverseArithmeticException() { try { modInverse(BigInteger.ONE, BigInteger.valueOf(-1)); fail("ArithmeticException expected"); } catch (ArithmeticException expected) { } try { modInverse(BigInteger.valueOf(3), BigInteger.valueOf(9)); fail("ArithmeticException expected"); } catch (ArithmeticException expected) { } }