### Question:
Library { public static int gcd(int x, int y) { if (x < 0 || y < 0) throw new IllegalArgumentException("Negative number"); while (y != 0) { int z = x % y; x = y; y = z; } return x; }  static String reverse(String s); static boolean isPalindrome(String s); static boolean isPalindrome(int x); static int sqrt(int x); static long sqrt(long x); static BigInteger sqrt(BigInteger x); static boolean isSquare(int x); static int pow(int x, int y); static int powMod(int x, int y, int m); static int reciprocalMod(int x, int m); static BigInteger factorial(int n); static BigInteger binomial(int n, int k); static int gcd(int x, int y); static boolean isPrime(int x); static boolean[] listPrimality(int n); static int[] listPrimes(int n); static int[] listSmallestPrimeFactors(int n); static int totient(int n); static int[] listTotients(int n); static boolean nextPermutation(int[] arr);  }### Answer:
@Test public void testGcd() { assertEquals(0, Library.gcd(0, 0)); assertEquals(1, Library.gcd(0, 1)); assertEquals(1, Library.gcd(1, 0)); assertEquals(6, Library.gcd(0, 6)); assertEquals(6, Library.gcd(6, 0)); assertEquals(1, Library.gcd(1, 1)); assertEquals(2, Library.gcd(2, 2)); assertEquals(1, Library.gcd(2, 3)); assertEquals(1, Library.gcd(10, 3)); assertEquals(3, Library.gcd(9, 3)); assertEquals(2, Library.gcd(6, 4)); assertEquals(2, Library.gcd(18, 14)); assertEquals(300, Library.gcd(44100, 48000)); assertEquals(2147483647, Library.gcd(0, 2147483647)); assertEquals(2147483647, Library.gcd(2147483647, 2147483647)); assertEquals(1, Library.gcd(2147483646, 2147483647)); }
@Test public void testGcdRandomly() { final int trials = 1000000; for (int i = 0; i < trials; i++) { int x = rand.nextInt() >>> 1; int y = rand.nextInt() >>> 1; int z = Library.gcd(x, y); if (x == 0) assertEquals(y, z); else if (y == 0) assertEquals(x, z); else assertTrue(0 < z && z <= x && z <= y && x % z == 0 && y % z == 0); } }