def test_outputs_xi_nfw_at_R(): #List vs. numpy.array npt.assert_array_equal(xi.xi_nfw_at_R(Ra, Mass, conc, Omega_m), xi.xi_nfw_at_R(Ra.tolist(), Mass, conc, Omega_m)) #Single value vs numpy.array arrout = xi.xi_nfw_at_R(Ra, Mass, conc, Omega_m) for i in range(len(Ra)): npt.assert_equal(xi.xi_nfw_at_R(Ra[i], Mass, conc, Omega_m), arrout[i])
def test_rho_vs_xi_nfw(): #Note: testing fractional precision to avoid numerical issues arr1 = density.rho_nfw_at_R(R_arr, Mass, conc, Omega_m) arr2 = xi.xi_nfw_at_R(R_arr, Mass, conc, Omega_m) arr2 = rhom * (1 + arr2) arr2 = arr2 / arr1 ones = np.ones_like(arr1) npt.assert_array_equal(ones, arr2)
def test_combination(): xinfw = xi.xi_nfw_at_R(Ra, Mass, conc, Omega_m) ximm = xi.xi_mm_at_R(Ra, knl, pnl) from cluster_toolkit import bias b = bias.bias_at_M(Mass, klin, plin, Omega_m) xi2h = xi.xi_2halo(b, ximm) xihm = xi.xi_hm(xinfw, xi2h) xihm2 = xi.xi_hm(xinfw, xi2h, combination='max') npt.assert_array_equal(xihm, xihm2) xihm2 = xi.xi_hm(xinfw, xi2h, combination='sum') npt.assert_raises(AssertionError, npt.assert_array_equal, xihm, xihm2) with pytest.raises(Exception): xi.xi_hm(xinfw, xi2h, combination='blah')
def test_nfw_mass_dependence(): masses = np.array([1e13, 1e14, 1e15]) for i in range(len(masses)-1): xi1 = xi.xi_nfw_at_R(Ra, masses[i], conc, Omega_m) xi2 = xi.xi_nfw_at_R(Ra, masses[i+1], conc, Omega_m) npt.assert_array_less(xi1, xi2)
def test_exceptions_xi_nfw_at_R(): with pytest.raises(TypeError): xi.xi_nfw_at_R() #No args xi.xi_nfw_at_R(R, Mass, conc) #Too few args xi.xi_nfw_at_R(R, Mass, conc, Omega_m, Omega_m) #Too many args xi.xi_nfw_at_R("a string", Mass, conc, Omega_m, Omega_m) #Wrong type