package franck.eecs1030; import java.util.Random; public class ConverterTest { public static void main(String[] args) { Random random = new Random(System.currentTimeMillis()); final int RANDOM = 10; final double EPSILON = 0.0001; for (int from = Converter.CENTIMETER; from <= Converter.FOOT; from++) { for (int to = Converter.CENTIMETER; to <= Converter.FOOT; to++) { for (int r = 0; r < RANDOM; r++) { try { double amount = Math.abs(random.nextDouble()); double converted = Converter.convert(amount, from, to); double doubleConverted = Converter.convert(converted, to, from); if (Math.abs(amount - doubleConverted) > EPSILON * amount) { System.out.printf("Test failed for amount = %f, from = %d, to = %d%n", amount, from, to); } } catch (IllegalArgumentException e) {} } try { double amount = 0; double converted = Converter.convert(amount, from, to); double doubleConverted = Converter.convert(converted, to, from); if (Math.abs(amount - doubleConverted) > EPSILON * amount) { System.out.printf("Test failed for amount = %f, from = %d, to = %d%n", amount, from, to); } } catch (IllegalArgumentException e) {} try { double amount = Double.MAX_VALUE; double converted = Converter.convert(amount, from, to); double doubleConverted = Converter.convert(converted, to, from); if (Math.abs(amount - doubleConverted) > EPSILON * amount) { System.out.printf("Test failed for amount = %f, from = %d, to = %d%n", amount, from, to); } } catch (IllegalArgumentException e) {} } } } }