-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
118 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
julia 0.7-beta | ||
QuadGK 0.1.1 | ||
Unitful 0.9.0 | ||
UnitfulAstro 0.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,88 @@ | ||
using Cosmology | ||
using Test | ||
|
||
function test_approx_eq_rtol(va, vb, rtol, astr, bstr) | ||
diff = maximum(abs(va - vb)) | ||
tol = rtol*max(maximum(abs(va)), maximum(abs(vb))) | ||
if diff > tol | ||
sdiff = string("|", astr, " - ", bstr, "| <= ", tol) | ||
error("assertion failed: ", sdiff, | ||
"\n ", astr, " = ", va, | ||
"\n ", bstr, " = ", vb, | ||
"\n difference = ", diff, " > ", tol) | ||
end | ||
end | ||
|
||
macro test_approx_eq_rtol(a, b, c) | ||
:(test_approx_eq_rtol($(esc(a)), $(esc(b)), $(esc(c)), $(string(a)), $(string(b)))) | ||
end | ||
using Test, Unitful, UnitfulAstro | ||
|
||
# values from http://icosmos.co.uk/ | ||
|
||
dist_rtol = 1e-6 | ||
age_rtol = 2e-4 | ||
|
||
c = cosmology(h=0.7, OmegaM=0.3, OmegaR=0) | ||
@test_approx_eq_rtol angular_diameter_dist_mpc(c,1) 1651.9145 dist_rtol | ||
@test_approx_eq_rtol comoving_radial_dist_mpc(c,1) 3303.829 dist_rtol | ||
@test_approx_eq_rtol comoving_volume_gpc3(c,1) 151.0571 dist_rtol | ||
@test_approx_eq_rtol luminosity_dist_mpc(c,1) 6607.6579 dist_rtol | ||
@test_approx_eq_rtol distmod(c,1) 44.1002 dist_rtol | ||
@test_approx_eq_rtol age_gyr(c,0) 13.4694 age_rtol | ||
@test_approx_eq_rtol age_gyr(c,1) 5.7527 age_rtol | ||
@test_approx_eq_rtol lookback_time_gyr(c,1) 13.4694-5.7527 age_rtol | ||
|
||
c = cosmology(h=0.7, OmegaK=0.1, OmegaM=0.3, OmegaR=0) | ||
@test_approx_eq_rtol angular_diameter_dist_mpc(c,1) 1619.9588 dist_rtol | ||
@test_approx_eq_rtol comoving_radial_dist_mpc(c,1) 3209.784 dist_rtol | ||
@test_approx_eq_rtol comoving_volume_gpc3(c,1) 140.0856 dist_rtol | ||
@test_approx_eq_rtol luminosity_dist_mpc(c,1) 6479.8352 dist_rtol | ||
@test_approx_eq_rtol distmod(c,1) 44.0578 dist_rtol | ||
@test_approx_eq_rtol age_gyr(c,0) 13.064 age_rtol | ||
@test_approx_eq_rtol age_gyr(c,1) 5.5466 age_rtol | ||
@test_approx_eq_rtol lookback_time_gyr(c,1) 13.064-5.5466 age_rtol | ||
@testset "FlatLCDM" begin | ||
c = cosmology(h=0.7, OmegaM=0.3, OmegaR=0) | ||
@test angular_diameter_dist(c,1) ≈ 1651.9145u"Mpc" rtol = dist_rtol | ||
@test comoving_radial_dist(c,1) ≈ 3303.829u"Mpc" rtol = dist_rtol | ||
@test comoving_volume(c,1) ≈ 151.0571u"Gpc^3" rtol = dist_rtol | ||
@test luminosity_dist(c,1) ≈ 6607.6579u"Mpc" rtol = dist_rtol | ||
@test distmod(c,1) ≈ 44.1002 rtol = dist_rtol | ||
@test age(c,0) ≈ 13.4694u"Gyr" rtol = age_rtol | ||
@test age(c,1) ≈ 5.7527u"Gyr" rtol = age_rtol | ||
@test lookback_time(c,1) ≈ (13.4694-5.7527)u"Gyr" rtol = age_rtol | ||
end | ||
|
||
c = cosmology(h=0.7, OmegaK=-0.1, OmegaM=0.3, OmegaR=0) | ||
@test_approx_eq_rtol angular_diameter_dist_mpc(c,1) 1686.5272 dist_rtol | ||
@test_approx_eq_rtol comoving_radial_dist_mpc(c,1) 3408.937 dist_rtol | ||
@test_approx_eq_rtol comoving_volume_gpc3(c,1) 163.8479 dist_rtol | ||
@test_approx_eq_rtol luminosity_dist_mpc(c,1) 6746.1088 dist_rtol | ||
@test_approx_eq_rtol distmod(c,1) 44.1453 dist_rtol | ||
@test_approx_eq_rtol age_gyr(c,0) 13.925 age_rtol | ||
@test_approx_eq_rtol age_gyr(c,1) 5.9868 age_rtol | ||
@test_approx_eq_rtol lookback_time_gyr(c,1) 13.925-5.9868 age_rtol | ||
@testset "OpenLCDM" begin | ||
c = cosmology(h=0.7, OmegaK=0.1, OmegaM=0.3, OmegaR=0) | ||
@test angular_diameter_dist(c,1) ≈ 1619.9588u"Mpc" rtol = dist_rtol | ||
@test comoving_radial_dist(c,1) ≈ 3209.784u"Mpc" rtol = dist_rtol | ||
@test comoving_volume(c,1) ≈ 140.0856u"Gpc^3" rtol = dist_rtol | ||
@test luminosity_dist(c,1) ≈ 6479.8352u"Mpc" rtol = dist_rtol | ||
@test distmod(c,1) ≈ 44.0578 rtol = dist_rtol | ||
@test age(c,0) ≈ 13.064u"Gyr" rtol = age_rtol | ||
@test age(c,1) ≈ 5.5466u"Gyr" rtol = age_rtol | ||
@test lookback_time(c,1) ≈ (13.064-5.5466)u"Gyr" rtol = age_rtol | ||
end | ||
|
||
c = cosmology(h=0.7, OmegaM=0.3, OmegaR=0, w0=-0.9, wa=0.1) | ||
@test_approx_eq_rtol angular_diameter_dist_mpc(c,1) 1612.0585 dist_rtol | ||
@test_approx_eq_rtol comoving_radial_dist_mpc(c,1) 3224.1169 dist_rtol | ||
@test_approx_eq_rtol comoving_volume_gpc3(c,1) 140.3851 dist_rtol | ||
@test_approx_eq_rtol luminosity_dist_mpc(c,1) 6448.2338 dist_rtol | ||
@test_approx_eq_rtol distmod(c,1) 44.0472 dist_rtol | ||
@test_approx_eq_rtol age_gyr(c,0) 13.1915 age_rtol | ||
@test_approx_eq_rtol age_gyr(c,1) 5.6464 age_rtol | ||
@test_approx_eq_rtol lookback_time_gyr(c,1) 13.1915-5.6464 age_rtol | ||
@testset "ClosedLCDM" begin | ||
c = cosmology(h=0.7, OmegaK=-0.1, OmegaM=0.3, OmegaR=0) | ||
@test angular_diameter_dist(c,1) ≈ 1686.5272u"Mpc" rtol = dist_rtol | ||
@test comoving_radial_dist(c,1) ≈ 3408.937u"Mpc" rtol = dist_rtol | ||
@test comoving_volume(c,1) ≈ 163.8479u"Gpc^3" rtol = dist_rtol | ||
@test luminosity_dist(c,1) ≈ 6746.1088u"Mpc" rtol = dist_rtol | ||
@test distmod(c,1) ≈ 44.1453 rtol = dist_rtol | ||
@test age(c,0) ≈ 13.925u"Gyr" rtol = age_rtol | ||
@test age(c,1) ≈ 5.9868u"Gyr" rtol = age_rtol | ||
@test lookback_time(c,1) ≈ (13.925-5.9868)u"Gyr" rtol = age_rtol | ||
end | ||
|
||
c = cosmology(h=0.7, OmegaK=0.1, OmegaM=0.3, OmegaR=0, w0=-0.9, wa=0.1) | ||
@test_approx_eq_rtol angular_diameter_dist_mpc(c,1) 1588.0181 dist_rtol | ||
@test_approx_eq_rtol comoving_radial_dist_mpc(c,1) 3147.6227 dist_rtol | ||
@test_approx_eq_rtol comoving_volume_gpc3(c,1) 132.0466 dist_rtol | ||
@test_approx_eq_rtol luminosity_dist_mpc(c,1) 6352.0723 dist_rtol | ||
@test_approx_eq_rtol distmod(c,1) 44.0146 dist_rtol | ||
@test_approx_eq_rtol age_gyr(c,0) 12.8488 age_rtol | ||
@test_approx_eq_rtol age_gyr(c,1) 5.4659 age_rtol | ||
@test_approx_eq_rtol lookback_time_gyr(c,1) 12.8488-5.4659 age_rtol | ||
@testset "FlatWCDM" begin | ||
c = cosmology(h=0.7, OmegaM=0.3, OmegaR=0, w0=-0.9, wa=0.1) | ||
@test angular_diameter_dist(c,1) ≈ 1612.0585u"Mpc" rtol = dist_rtol | ||
@test comoving_radial_dist(c,1) ≈ 3224.1169u"Mpc" rtol = dist_rtol | ||
@test comoving_volume(c,1) ≈ 140.3851u"Gpc^3" rtol = dist_rtol | ||
@test luminosity_dist(c,1) ≈ 6448.2338u"Mpc" rtol = dist_rtol | ||
@test distmod(c,1) ≈ 44.0472 rtol = dist_rtol | ||
@test age(c,0) ≈ 13.1915u"Gyr" rtol = age_rtol | ||
@test age(c,1) ≈ 5.6464u"Gyr" rtol = age_rtol | ||
@test lookback_time(c,1) ≈ (13.1915-5.6464)u"Gyr" rtol = age_rtol | ||
end | ||
|
||
c = cosmology(h=0.7, OmegaK=-0.1, OmegaM=0.3, OmegaR=0, w0=-0.9, wa=0.1) | ||
@test_approx_eq_rtol angular_diameter_dist_mpc(c,1) 1637.5993 dist_rtol | ||
@test_approx_eq_rtol comoving_radial_dist_mpc(c,1) 3307.9932 dist_rtol | ||
@test_approx_eq_rtol comoving_volume_gpc3(c,1) 149.8301 dist_rtol | ||
@test_approx_eq_rtol luminosity_dist_mpc(c,1) 6550.3973 dist_rtol | ||
@test_approx_eq_rtol distmod(c,1) 44.0813 dist_rtol | ||
@test_approx_eq_rtol age_gyr(c,0) 13.5702 age_rtol | ||
@test_approx_eq_rtol age_gyr(c,1) 5.8482 age_rtol | ||
@test_approx_eq_rtol lookback_time_gyr(c,1) 13.5702-5.8482 age_rtol | ||
@testset "OpenWCDM" begin | ||
c = cosmology(h=0.7, OmegaK=0.1, OmegaM=0.3, OmegaR=0, w0=-0.9, wa=0.1) | ||
@test angular_diameter_dist(c,1) ≈ 1588.0181u"Mpc" rtol = dist_rtol | ||
@test comoving_radial_dist(c,1) ≈ 3147.6227u"Mpc" rtol = dist_rtol | ||
@test comoving_volume(c,1) ≈ 132.0466u"Gpc^3" rtol = dist_rtol | ||
@test luminosity_dist(c,1) ≈ 6352.0723u"Mpc" rtol = dist_rtol | ||
@test distmod(c,1) ≈ 44.0146 rtol = dist_rtol | ||
@test age(c,0) ≈ 12.8488u"Gyr" rtol = age_rtol | ||
@test age(c,1) ≈ 5.4659u"Gyr" rtol = age_rtol | ||
@test lookback_time(c,1) ≈ (12.8488-5.4659)u"Gyr" rtol = age_rtol | ||
end | ||
|
||
# Test that FlatLCDM works with non-Float64 (BigFloat in this example) | ||
c = cosmology(h=0.7, OmegaM=big(0.3), OmegaR=0) | ||
@test_approx_eq_rtol angular_diameter_dist_mpc(c,1) 1651.9145 dist_rtol | ||
@testset "ClosedWCDM" begin | ||
c = cosmology(h=0.7, OmegaK=-0.1, OmegaM=0.3, OmegaR=0, w0=-0.9, wa=0.1) | ||
@test angular_diameter_dist(c,1) ≈ 1637.5993u"Mpc" rtol = dist_rtol | ||
@test comoving_radial_dist(c,1) ≈ 3307.9932u"Mpc" rtol = dist_rtol | ||
@test comoving_volume(c,1) ≈ 149.8301u"Gpc^3" rtol = dist_rtol | ||
@test luminosity_dist(c,1) ≈ 6550.3973u"Mpc" rtol = dist_rtol | ||
@test distmod(c,1) ≈ 44.0813 rtol = dist_rtol | ||
@test age(c,0) ≈ 13.5702u"Gyr" rtol = age_rtol | ||
@test age(c,1) ≈ 5.8482u"Gyr" rtol = age_rtol | ||
@test lookback_time(c,1) ≈ (13.5702-5.8482)u"Gyr" rtol = age_rtol | ||
end | ||
|
||
# Test that FlatWCDM works with non-Float64 (BigFloat in this example) | ||
c = cosmology(h=big(0.7), OmegaM=0.3, OmegaR=0, w0=-0.9, wa=0.1) | ||
@test_approx_eq_rtol angular_diameter_dist_mpc(c,1) 1612.0585 dist_rtol | ||
@testset "Non-Float64" begin | ||
# Test that FlatLCDM works with non-Float64 (BigFloat in this example) | ||
c = cosmology(h=0.7, OmegaM=big(0.3), OmegaR=0) | ||
@test angular_diameter_dist(c,1) ≈ 1651.9145u"Mpc" rtol = dist_rtol | ||
# Test that FlatWCDM works with non-Float64 (BigFloat in this example) | ||
c = cosmology(h=big(0.7), OmegaM=0.3, OmegaR=0, w0=-0.9, wa=0.1) | ||
@test angular_diameter_dist(c,1) ≈ 1612.0585u"Mpc" rtol = dist_rtol | ||
end |