def test_cdf_invcdf_again():
    rdz = Rediz(**REDIZ_TEST_CONFIG)
    normcdf = rdz._normcdf_function()
    norminv = rdz._norminv_function()
    for x in np.random.randn(100):
        x1 = norminv(normcdf(x))
        assert abs(x - x1) < 1e-4
def test_is_valid_name():

    nc = Rediz(**REDIZ_FAKE_CONFIG)
    s = 'dog-7214.json'
    assert nc.is_valid_name(s), "oops"
    for s in ["25824ee3-d9bf-4923-9be7-19d6c2aafcee.json"]:
        assert nc.is_valid_name(s),"Got it wrong for "+s
def test_its_testing_tuesday_i_am_so_happy():
    okay_names = ['mystream.json','ice_cream.json','tilde~in_there.json']
    bad_names  = ['toomanycolons::.json','*****@*****.**','forgotjson']
    for name in okay_names:
        assert Rediz.is_valid_name(name)
    for name in bad_names:
        assert not Rediz.is_valid_name(name)
def test_mean_percentile():
    zscores = np.random.randn(100)
    normcdf = Rediz._normcdf_function()
    norminv = Rediz._norminv_function()
    p = [normcdf(z) for z in zscores]
    avg_p = Rediz.zmean_percentile(p)
    implied_avg = norminv(avg_p)
    actual_avg = np.mean(zscores)
    assert abs(implied_avg - actual_avg) < 1e-4
def test_morton():
    zc = Rediz(**REDIZ_TEST_CONFIG)
    for dim in [2, 3]:
        for _ in range(100):
            prtcls = list(np.random.rand(dim))
            z = zc.to_zcurve(prctls=prtcls)
            prtcls_back = zc.from_zcurve(z, dim=len(prtcls))
            assert all(
                abs(p1 - p2) < 10. / zc.morton_scale(dim=3) for p1, p2 in zip(
                    prtcls, prtcls_back)), "Morton embedding failed "
def test_mean_percentile_again():
    rdz = Rediz(**REDIZ_TEST_CONFIG)
    zscores = np.random.randn(100)
    normcdf = rdz._normcdf_function()
    norminv = rdz._norminv_function()
    p = [normcdf(z) for z in zscores]
    avg_p = rdz.zmean_percentile(p)
    implied_avg = norminv(avg_p)
    actual_avg = np.mean(zscores)
    assert abs(implied_avg - actual_avg) < 1e-4
def test_conv():
    rdz = Rediz(**REDIZ_TEST_CONFIG)
    assert rdz.min_len > 6
    assert rdz.MIN_LEN > 7
    assert rdz.min_len == rdz.MIN_LEN
def test_conv():
    rdz = Rediz(**REDIZ_TEST_CONFIG)
    xs = rdz.percentile_abscissa()
    assert len(xs) > 5
def test_cdf_invcdf():
    normcdf = Rediz._normcdf_function()
    norminv = Rediz._norminv_function()
    for x in np.random.randn(100):
        x1 = norminv(normcdf(x))
        assert abs(x - x1) < 1e-4