diff options
Diffstat (limited to 'guava-tests/test/com/google/common/math/PairedStatsAccumulatorTest.java')
-rw-r--r-- | guava-tests/test/com/google/common/math/PairedStatsAccumulatorTest.java | 169 |
1 files changed, 59 insertions, 110 deletions
diff --git a/guava-tests/test/com/google/common/math/PairedStatsAccumulatorTest.java b/guava-tests/test/com/google/common/math/PairedStatsAccumulatorTest.java index 34f82e907..1f3d68ff6 100644 --- a/guava-tests/test/com/google/common/math/PairedStatsAccumulatorTest.java +++ b/guava-tests/test/com/google/common/math/PairedStatsAccumulatorTest.java @@ -44,6 +44,7 @@ import static com.google.common.math.StatsTesting.createFilledPairedStatsAccumul import static com.google.common.math.StatsTesting.createPartitionedFilledPairedStatsAccumulator; 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.math.StatsTesting.ManyValues; import java.util.Collections; @@ -174,16 +175,10 @@ public class PairedStatsAccumulatorTest extends TestCase { } public void testPopulationCovariance() { - try { - emptyAccumulator.populationCovariance(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - emptyAccumulatorByAddAllEmptyPairedStats.populationCovariance(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } + assertThrows(IllegalStateException.class, () -> emptyAccumulator.populationCovariance()); + assertThrows( + IllegalStateException.class, + () -> emptyAccumulatorByAddAllEmptyPairedStats.populationCovariance()); assertThat(oneValueAccumulator.populationCovariance()).isWithin(0.0).of(0.0); assertThat(oneValueAccumulatorByAddAllEmptyPairedStats.populationCovariance()) .isWithin(0.0) @@ -241,26 +236,14 @@ public class PairedStatsAccumulatorTest extends TestCase { } public void testSampleCovariance() { - try { - emptyAccumulator.sampleCovariance(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - emptyAccumulatorByAddAllEmptyPairedStats.sampleCovariance(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - oneValueAccumulator.sampleCovariance(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - oneValueAccumulatorByAddAllEmptyPairedStats.sampleCovariance(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } + assertThrows(IllegalStateException.class, () -> emptyAccumulator.sampleCovariance()); + assertThrows( + IllegalStateException.class, + () -> emptyAccumulatorByAddAllEmptyPairedStats.sampleCovariance()); + assertThrows(IllegalStateException.class, () -> oneValueAccumulator.sampleCovariance()); + assertThrows( + IllegalStateException.class, + () -> oneValueAccumulatorByAddAllEmptyPairedStats.sampleCovariance()); assertThat(twoValuesAccumulator.sampleCovariance()) .isWithin(ALLOWED_ERROR) .of(TWO_VALUES_SUM_OF_PRODUCTS_OF_DELTAS); @@ -288,26 +271,16 @@ public class PairedStatsAccumulatorTest extends TestCase { } public void testPearsonsCorrelationCoefficient() { - try { - emptyAccumulator.pearsonsCorrelationCoefficient(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - emptyAccumulatorByAddAllEmptyPairedStats.pearsonsCorrelationCoefficient(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - oneValueAccumulator.pearsonsCorrelationCoefficient(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - oneValueAccumulatorByAddAllEmptyPairedStats.pearsonsCorrelationCoefficient(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } + assertThrows( + IllegalStateException.class, () -> emptyAccumulator.pearsonsCorrelationCoefficient()); + assertThrows( + IllegalStateException.class, + () -> emptyAccumulatorByAddAllEmptyPairedStats.pearsonsCorrelationCoefficient()); + assertThrows( + IllegalStateException.class, () -> oneValueAccumulator.pearsonsCorrelationCoefficient()); + assertThrows( + IllegalStateException.class, + () -> oneValueAccumulatorByAddAllEmptyPairedStats.pearsonsCorrelationCoefficient()); assertThat(twoValuesAccumulator.pearsonsCorrelationCoefficient()) .isWithin(ALLOWED_ERROR) .of( @@ -368,59 +341,41 @@ public class PairedStatsAccumulatorTest extends TestCase { .populationStandardDeviation())); } } - try { - horizontalValuesAccumulator.pearsonsCorrelationCoefficient(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - horizontalValuesAccumulatorByAddAllPartitionedPairedStats.pearsonsCorrelationCoefficient(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - verticalValuesAccumulator.pearsonsCorrelationCoefficient(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - verticalValuesAccumulatorByAddAllPartitionedPairedStats.pearsonsCorrelationCoefficient(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - constantValuesAccumulator.pearsonsCorrelationCoefficient(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - constantValuesAccumulatorByAddAllPartitionedPairedStats.pearsonsCorrelationCoefficient(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } + assertThrows( + IllegalStateException.class, + () -> horizontalValuesAccumulator.pearsonsCorrelationCoefficient()); + assertThrows( + IllegalStateException.class, + () -> + horizontalValuesAccumulatorByAddAllPartitionedPairedStats + .pearsonsCorrelationCoefficient()); + assertThrows( + IllegalStateException.class, + () -> verticalValuesAccumulator.pearsonsCorrelationCoefficient()); + assertThrows( + IllegalStateException.class, + () -> + verticalValuesAccumulatorByAddAllPartitionedPairedStats + .pearsonsCorrelationCoefficient()); + assertThrows( + IllegalStateException.class, + () -> constantValuesAccumulator.pearsonsCorrelationCoefficient()); + assertThrows( + IllegalStateException.class, + () -> + constantValuesAccumulatorByAddAllPartitionedPairedStats + .pearsonsCorrelationCoefficient()); } public void testLeastSquaresFit() { - try { - emptyAccumulator.leastSquaresFit(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - emptyAccumulatorByAddAllEmptyPairedStats.leastSquaresFit(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - oneValueAccumulator.leastSquaresFit(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - oneValueAccumulatorByAddAllEmptyPairedStats.leastSquaresFit(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } + assertThrows(IllegalStateException.class, () -> emptyAccumulator.leastSquaresFit()); + assertThrows( + IllegalStateException.class, + () -> emptyAccumulatorByAddAllEmptyPairedStats.leastSquaresFit()); + assertThrows(IllegalStateException.class, () -> oneValueAccumulator.leastSquaresFit()); + assertThrows( + IllegalStateException.class, + () -> oneValueAccumulatorByAddAllEmptyPairedStats.leastSquaresFit()); assertDiagonalLinearTransformation( twoValuesAccumulator.leastSquaresFit(), twoValuesAccumulator.xStats().mean(), @@ -483,15 +438,9 @@ public class PairedStatsAccumulatorTest extends TestCase { assertVerticalLinearTransformation( verticalValuesAccumulatorByAddAllPartitionedPairedStats.leastSquaresFit(), verticalValuesAccumulatorByAddAllPartitionedPairedStats.xStats().mean()); - try { - constantValuesAccumulator.leastSquaresFit(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - constantValuesAccumulatorByAddAllPartitionedPairedStats.leastSquaresFit(); - fail("Expected IllegalStateException"); - } catch (IllegalStateException expected) { - } + assertThrows(IllegalStateException.class, () -> constantValuesAccumulator.leastSquaresFit()); + assertThrows( + IllegalStateException.class, + () -> constantValuesAccumulatorByAddAllPartitionedPairedStats.leastSquaresFit()); } } |