LoremIpsum { static int chooseClosest(Integer[] values, int target) { int closest = values[0]; for (int value : values) { if (Math.abs(target - value) < Math.abs(target - closest)) { closest = value; } } return closest; } LoremIpsum();  LoremIpsum(String sample, String dictionary);  LoremIpsum(String sample, String[] newDictionary);  LoremIpsum(String sample); String generateParagraph(boolean optStartWithLorem); String generateSentence(boolean optStartWithLorem); String getSample(); void setSample(String sample); String getDictionary(); void setDictionary(String dictionary); static double mean(int[] values); static double mean(double[] values); static double variance(double[] values); static double sigma(int[] values); static double sigma(double[] values); static int sum(int[] values); static double sum(double[] values); static boolean contains(String[] array, String val); String generateParagraphsHtml(int quantity, boolean startWithLorem); void generateParagraphsHtml(Appendable writer, int quantity, boolean startWithLorem); String generateOneParagraphHtml(int quantity, boolean startWithLorem); String generateParagraphsFullHtml(int quantity, boolean startWithLorem); void generateParagraphsFullHtml(Appendable writer, int quantity, boolean startWithLorem); String generateParagraphsPlainText(int quantity, boolean startWithLorem); void generateParagraphsPlainText(Appendable writer, int quantity, boolean startWithLorem); String generateParagraphsPlainText(int quantity, int maxCols, boolean startWithLorem); void generateParagraphsPlainText(Appendable writer, int quantity, int maxCols, boolean startWithLorem);  }
@Test public void test_choose_closest() { Integer[] intArray1 = { 1, 2, 3, 4 }; assertEquals(1, LoremIpsum.chooseClosest(intArray1, 1)); Integer[] intArray2 = { 1, 2, 3, 4 }; assertEquals(4, LoremIpsum.chooseClosest(intArray2, 4)); assertEquals(4, LoremIpsum.chooseClosest(intArray2, 20)); assertEquals(1, LoremIpsum.chooseClosest(intArray2, -10)); Integer[] intArray3 = { 1, 4 }; assertEquals(1, LoremIpsum.chooseClosest(intArray3, 2)); assertEquals(4, LoremIpsum.chooseClosest(intArray3, 3)); Integer[] intArray4 = { 1, 3 }; assertEquals(1, LoremIpsum.chooseClosest(intArray4, 2)); Integer[] intArray5 = { 3, 1 }; assertEquals(3, LoremIpsum.chooseClosest(intArray5, 2)); Integer[] intArray6 = { 1 }; assertEquals(1, LoremIpsum.chooseClosest(intArray6, 200)); }