diff options
Diffstat (limited to 'android/guava-tests/test/com/google/common/math/PairedStatsTest.java')
-rw-r--r-- | android/guava-tests/test/com/google/common/math/PairedStatsTest.java | 116 |
1 files changed, 31 insertions, 85 deletions
diff --git a/android/guava-tests/test/com/google/common/math/PairedStatsTest.java b/android/guava-tests/test/com/google/common/math/PairedStatsTest.java index 7dd9e94d6..3219bb5f9 100644 --- a/android/guava-tests/test/com/google/common/math/PairedStatsTest.java +++ b/android/guava-tests/test/com/google/common/math/PairedStatsTest.java @@ -48,6 +48,7 @@ import static com.google.common.math.StatsTesting.assertVerticalLinearTransforma import static com.google.common.math.StatsTesting.createPairedStatsOf; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; +import static org.junit.Assert.assertThrows; import com.google.common.collect.ImmutableList; import com.google.common.math.StatsTesting.ManyValues; @@ -87,11 +88,7 @@ public class PairedStatsTest extends TestCase { } public void testPopulationCovariance() { - try { - EMPTY_PAIRED_STATS.populationCovariance(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } + assertThrows(IllegalStateException.class, () -> EMPTY_PAIRED_STATS.populationCovariance()); assertThat(ONE_VALUE_PAIRED_STATS.populationCovariance()).isWithin(0.0).of(0.0); assertThat(createSingleStats(Double.POSITIVE_INFINITY, 1.23).populationCovariance()).isNaN(); assertThat(createSingleStats(Double.NEGATIVE_INFINITY, 1.23).populationCovariance()).isNaN(); @@ -121,16 +118,8 @@ public class PairedStatsTest extends TestCase { } public void testSampleCovariance() { - try { - EMPTY_PAIRED_STATS.sampleCovariance(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - ONE_VALUE_PAIRED_STATS.sampleCovariance(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } + assertThrows(IllegalStateException.class, () -> EMPTY_PAIRED_STATS.sampleCovariance()); + assertThrows(IllegalStateException.class, () -> ONE_VALUE_PAIRED_STATS.sampleCovariance()); assertThat(TWO_VALUES_PAIRED_STATS.sampleCovariance()) .isWithin(ALLOWED_ERROR) .of(TWO_VALUES_SUM_OF_PRODUCTS_OF_DELTAS); @@ -143,21 +132,13 @@ public class PairedStatsTest extends TestCase { } public void testPearsonsCorrelationCoefficient() { - try { - EMPTY_PAIRED_STATS.pearsonsCorrelationCoefficient(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - ONE_VALUE_PAIRED_STATS.pearsonsCorrelationCoefficient(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - createSingleStats(Double.POSITIVE_INFINITY, 1.23).pearsonsCorrelationCoefficient(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } + assertThrows( + IllegalStateException.class, () -> EMPTY_PAIRED_STATS.pearsonsCorrelationCoefficient()); + assertThrows( + IllegalStateException.class, () -> ONE_VALUE_PAIRED_STATS.pearsonsCorrelationCoefficient()); + assertThrows( + IllegalStateException.class, + () -> createSingleStats(Double.POSITIVE_INFINITY, 1.23).pearsonsCorrelationCoefficient()); assertThat(TWO_VALUES_PAIRED_STATS.pearsonsCorrelationCoefficient()) .isWithin(ALLOWED_ERROR) .of( @@ -183,39 +164,23 @@ public class PairedStatsTest extends TestCase { * stats.yStats().populationStandardDeviation())); } } - try { - HORIZONTAL_VALUES_PAIRED_STATS.pearsonsCorrelationCoefficient(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - VERTICAL_VALUES_PAIRED_STATS.pearsonsCorrelationCoefficient(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - CONSTANT_VALUES_PAIRED_STATS.pearsonsCorrelationCoefficient(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } + assertThrows( + IllegalStateException.class, + () -> HORIZONTAL_VALUES_PAIRED_STATS.pearsonsCorrelationCoefficient()); + assertThrows( + IllegalStateException.class, + () -> VERTICAL_VALUES_PAIRED_STATS.pearsonsCorrelationCoefficient()); + assertThrows( + IllegalStateException.class, + () -> CONSTANT_VALUES_PAIRED_STATS.pearsonsCorrelationCoefficient()); } public void testLeastSquaresFit() { - try { - EMPTY_PAIRED_STATS.leastSquaresFit(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - ONE_VALUE_PAIRED_STATS.leastSquaresFit(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - createSingleStats(Double.POSITIVE_INFINITY, 1.23).leastSquaresFit(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } + assertThrows(IllegalStateException.class, () -> EMPTY_PAIRED_STATS.leastSquaresFit()); + assertThrows(IllegalStateException.class, () -> ONE_VALUE_PAIRED_STATS.leastSquaresFit()); + assertThrows( + IllegalStateException.class, + () -> createSingleStats(Double.POSITIVE_INFINITY, 1.23).leastSquaresFit()); assertDiagonalLinearTransformation( TWO_VALUES_PAIRED_STATS.leastSquaresFit(), TWO_VALUES_PAIRED_STATS.xStats().mean(), @@ -244,11 +209,7 @@ public class PairedStatsTest extends TestCase { assertVerticalLinearTransformation( VERTICAL_VALUES_PAIRED_STATS.leastSquaresFit(), VERTICAL_VALUES_PAIRED_STATS.xStats().mean()); - try { - CONSTANT_VALUES_PAIRED_STATS.leastSquaresFit(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } + assertThrows(IllegalStateException.class, () -> CONSTANT_VALUES_PAIRED_STATS.leastSquaresFit()); } public void testEqualsAndHashCode() { @@ -303,19 +264,11 @@ public class PairedStatsTest extends TestCase { } public void testFromByteArray_withNullInputThrowsNullPointerException() { - try { - PairedStats.fromByteArray(null); - fail("Expected NullPointerException"); - } catch (NullPointerException expected) { - } + assertThrows(NullPointerException.class, () -> PairedStats.fromByteArray(null)); } public void testFromByteArray_withEmptyArrayInputThrowsIllegalArgumentException() { - try { - PairedStats.fromByteArray(new byte[0]); - fail("Expected IllegalArgumentException"); - } catch (IllegalArgumentException expected) { - } + assertThrows(IllegalArgumentException.class, () -> PairedStats.fromByteArray(new byte[0])); } public void testFromByteArray_withTooLongArrayInputThrowsIllegalArgumentException() { @@ -326,11 +279,7 @@ public class PairedStatsTest extends TestCase { .put(buffer) .putChar('.') .array(); - try { - PairedStats.fromByteArray(tooLongByteArray); - fail("Expected IllegalArgumentException"); - } catch (IllegalArgumentException expected) { - } + assertThrows(IllegalArgumentException.class, () -> PairedStats.fromByteArray(tooLongByteArray)); } public void testFromByteArrayWithTooShortArrayInputThrowsIllegalArgumentException() { @@ -340,10 +289,7 @@ public class PairedStatsTest extends TestCase { .order(ByteOrder.LITTLE_ENDIAN) .put(buffer, 0, buffer.length - 1) .array(); - try { - PairedStats.fromByteArray(tooShortByteArray); - fail("Expected IllegalArgumentException"); - } catch (IllegalArgumentException expected) { - } + assertThrows( + IllegalArgumentException.class, () -> PairedStats.fromByteArray(tooShortByteArray)); } } |