Repository: scipy/scipy
File: scipy/stats/tests/test_hypotests.py (Python)

Code before:

    def test_epps_singleton_size(self):
        # warns if sample contains fewer than 5 elements
        x, y = (1, 2, 3, 4), np.arange(10)
        with pytest.warns(SmallSampleWarning, match=too_small_1d_not_omit):
            res = epps_singleton_2samp(x, y)
            assert_equal(res.statistic, np.nan)
            assert_equal(res.pvalue, np.nan)

    def test_epps_singleton_nonfinite(self):
        rng = np.random.default_rng(83249872384543)
        x = rng.random(size=(10, 11))
        y = rng.random(size=(10, 12))
        i = np.asarray([1, 4, 9])  # arbitrary rows

        w_ref, p_ref = epps_singleton_2samp(x, y, axis=-1)
        w_ref[i] = np.nan
        p_ref[i] = np.nan

        x[i[0], 0] = np.nan
        x[i[1], 1] = np.inf
        y[i[2], 2] = -np.inf
        w_res, p_res = epps_singleton_2samp(x, y, axis=-1)

        assert_equal(w_ref, w_res)
        assert_equal(p_ref, p_res)

    def test_names(self):
        x, y = np.arange(20), np.arange(30)
        res = epps_singleton_2samp(x, y)
        attributes = ('statistic', 'pvalue')
        check_named_results(res, attributes)


class TestCvm:
    # the expected values of the cdfs are taken from Table 1 in
    # Csorgo / Faraway: The Exact and Asymptotic Distribution of
    # Cramér-von Mises Statistics, 1996.
    def test_cdf_4(self):
        assert_allclose(
                _cdf_cvm([0.02983, 0.04111, 0.12331, 0.94251], 4),
                [0.01, 0.05, 0.5, 0.999],
                atol=1e-4)

    def test_cdf_10(self):
        assert_allclose(
                _cdf_cvm([0.02657, 0.03830, 0.12068, 0.56643], 10),
                [0.01, 0.05, 0.5, 0.975],
                atol=1e-4)

    def test_cdf_1000(self):

Review comment (suggestion):
```suggestion
        assert_allclose(w_res, w_ref)
        assert_allclose(p_res, p_ref)
```

Code after:

    def test_epps_singleton_size(self):
        # warns if sample contains fewer than 5 elements
        x, y = (1, 2, 3, 4), np.arange(10)
        with pytest.warns(SmallSampleWarning, match=too_small_1d_not_omit):
            res = epps_singleton_2samp(x, y)
            assert_equal(res.statistic, np.nan)
            assert_equal(res.pvalue, np.nan)

    def test_epps_singleton_nonfinite(self):
        rng = np.random.default_rng(83249872384543)
        x = rng.random(size=(10, 11))
        y = rng.random(size=(10, 12))
        i = np.asarray([1, 4, 9])  # arbitrary rows

        w_ref, p_ref = epps_singleton_2samp(x, y, axis=-1)
        w_ref[i] = np.nan
        p_ref[i] = np.nan

        x[i[0], 0] = np.nan
        x[i[1], 1] = np.inf
        y[i[2], 2] = -np.inf
        w_res, p_res = epps_singleton_2samp(x, y, axis=-1)

        assert_allclose(w_res, w_ref)
        assert_allclose(p_res, p_ref)

    def test_names(self):
        x, y = np.arange(20), np.arange(30)
        res = epps_singleton_2samp(x, y)
        attributes = ('statistic', 'pvalue')
        check_named_results(res, attributes)


class TestCvm:
    # the expected values of the cdfs are taken from Table 1 in
    # Csorgo / Faraway: The Exact and Asymptotic Distribution of
    # Cramér-von Mises Statistics, 1996.
    def test_cdf_4(self):
        assert_allclose(
                _cdf_cvm([0.02983, 0.04111, 0.12331, 0.94251], 4),
                [0.01, 0.05, 0.5, 0.999],
                atol=1e-4)

    def test_cdf_10(self):
        assert_allclose(
                _cdf_cvm([0.02657, 0.03830, 0.12068, 0.56643], 10),
                [0.01, 0.05, 0.5, 0.975],
                atol=1e-4)

    def test_cdf_1000(self):