public void testMin_noArgs() { try { Doubles.min(); fail(); } catch (IllegalArgumentException expected) { } }
public void testMax_noArgs() { try { Doubles.max(); fail(); } catch (IllegalArgumentException expected) { } }
public void testToArray_withNull() { List<Double> list = Arrays.asList((double) 0, (double) 1, null); try { Doubles.toArray(list); fail(); } catch (NullPointerException expected) { } }
public void testEnsureCapacity_fail() { try { Doubles.ensureCapacity(ARRAY1, -1, 1); fail(); } catch (IllegalArgumentException expected) { } try { // notice that this should even fail when no growth was needed Doubles.ensureCapacity(ARRAY1, 1, -1); fail(); } catch (IllegalArgumentException expected) { } }
public void testStringConverter_convertError() { try { Doubles.stringConverter().convert("notanumber"); fail(); } catch (NumberFormatException expected) { } }
@GwtIncompatible // Doubles.tryParse private static void checkTryParse(String input) { Double expected = referenceTryParse(input); assertEquals(expected, Doubles.tryParse(input)); if (expected != null && !Doubles.FLOATING_POINT_PATTERN.matcher(input).matches()) { // TODO(cpovirk): Use SourceCodeEscapers if it is added to Guava. StringBuilder escapedInput = new StringBuilder(); for (char c : input.toCharArray()) { if (c >= 0x20 && c <= 0x7E) { escapedInput.append(c); } else { escapedInput.append(String.format("\\u%04x", (int) c)); } } fail("FLOATING_POINT_PATTERN should have matched valid input <" + escapedInput + ">"); } }
@GwtIncompatible public void testTryParse_withNullNoGwt() { assertNull(Doubles.tryParse("null")); try { Doubles.tryParse(null); fail("Expected NPE"); } catch (NullPointerException expected) { } } }
public void testConstrainToRange() { double tolerance = 1e-10; assertEquals( (double) 1, Doubles.constrainToRange((double) 1, (double) 0, (double) 5), tolerance); assertEquals( (double) 1, Doubles.constrainToRange((double) 1, (double) 1, (double) 5), tolerance); assertEquals( (double) 3, Doubles.constrainToRange((double) 1, (double) 3, (double) 5), tolerance); assertEquals( (double) -1, Doubles.constrainToRange((double) 0, (double) -5, (double) -1), tolerance); assertEquals( (double) 2, Doubles.constrainToRange((double) 5, (double) 2, (double) 2), tolerance); try { Doubles.constrainToRange((double) 1, (double) 3, (double) 2); fail(); } catch (IllegalArgumentException expected) { } }
public void testMax_noArgs() { try { Doubles.max(); fail(); } catch (IllegalArgumentException expected) { } }
public void testToArray_withNull() { List<Double> list = Arrays.asList((double) 0, (double) 1, null); try { Doubles.toArray(list); fail(); } catch (NullPointerException expected) { } }
public void testMin_noArgs() { try { Doubles.min(); fail(); } catch (IllegalArgumentException expected) { } }
public void testEnsureCapacity_fail() { try { Doubles.ensureCapacity(ARRAY1, -1, 1); fail(); } catch (IllegalArgumentException expected) { } try { // notice that this should even fail when no growth was needed Doubles.ensureCapacity(ARRAY1, 1, -1); fail(); } catch (IllegalArgumentException expected) { } }
public void testStringConverter_convertError() { try { Doubles.stringConverter().convert("notanumber"); fail(); } catch (NumberFormatException expected) { } }
@GwtIncompatible // Doubles.tryParse private static void checkTryParse(String input) { Double expected = referenceTryParse(input); assertEquals(expected, Doubles.tryParse(input)); if (expected != null && !Doubles.FLOATING_POINT_PATTERN.matcher(input).matches()) { // TODO(cpovirk): Use SourceCodeEscapers if it is added to Guava. StringBuilder escapedInput = new StringBuilder(); for (char c : input.toCharArray()) { if (c >= 0x20 && c <= 0x7E) { escapedInput.append(c); } else { escapedInput.append(String.format("\\u%04x", (int) c)); } } fail("FLOATING_POINT_PATTERN should have matched valid input <" + escapedInput + ">"); } }
@GwtIncompatible public void testTryParse_withNullNoGwt() { assertNull(Doubles.tryParse("null")); try { Doubles.tryParse(null); fail("Expected NPE"); } catch (NullPointerException expected) { } }
public void testConstrainToRange() { double tolerance = 1e-10; assertEquals( (double) 1, Doubles.constrainToRange((double) 1, (double) 0, (double) 5), tolerance); assertEquals( (double) 1, Doubles.constrainToRange((double) 1, (double) 1, (double) 5), tolerance); assertEquals( (double) 3, Doubles.constrainToRange((double) 1, (double) 3, (double) 5), tolerance); assertEquals( (double) -1, Doubles.constrainToRange((double) 0, (double) -5, (double) -1), tolerance); assertEquals( (double) 2, Doubles.constrainToRange((double) 5, (double) 2, (double) 2), tolerance); try { Doubles.constrainToRange((double) 1, (double) 3, (double) 2); fail(); } catch (IllegalArgumentException expected) { } }