Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 34 additions & 19 deletions src/MortalityTable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,39 @@ function MortalityTable(ultimate; metadata = TableMetaData())
end


Base.show(io::IO, ::MIME"text/plain", mt::MortalityTable) = print(
io,
"""
MortalityTable ($(mt.metadata.content_type)):
Name:
$(mt.metadata.name)
Fields:
$(fieldnames(typeof(mt)))
Provider:
$(mt.metadata.provider)
mort.SOA.org ID:
$(mt.metadata.id)
mort.SOA.org link:
https://mort.soa.org/ViewTable.aspx?&TableIdentity=$(mt.metadata.id)
Description:
$(mt.metadata.description)
""",
)
function Base.show(io::IO, ::MIME"text/plain", mt::MortalityTable)
print(
io,
"""
MortalityTable ($(mt.metadata.content_type)):
Name:
$(mt.metadata.name)
Fields:
$(fieldnames(typeof(mt)))
Provider:
$(mt.metadata.provider)
""",
)
# only mort.SOA.org sourced tables have an id and a link
if mt.metadata.id !== nothing
print(
io,
"""
mort.SOA.org ID:
$(mt.metadata.id)
mort.SOA.org link:
https://mort.soa.org/ViewTable.aspx?&TableIdentity=$(mt.metadata.id)
""",
)
end
print(
io,
"""
Description:
$(mt.metadata.description)
""",
)
end


"""
Expand Down Expand Up @@ -307,7 +322,7 @@ function omega(x)
return lastindex(x)
end

蠅 = omega
const 蠅 = omega


"""
Expand Down
4 changes: 0 additions & 4 deletions src/MortalityTables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ include("get_SOA_table.jl")
include("parameterized_models.jl")
include("life_expectancy.jl")

table_dirs = Dict(
"mort.soa.org" => artifact"mort.soa.org",
)

export MortalityTable,
survival,
decrement,
Expand Down
4 changes: 2 additions & 2 deletions src/get_SOA_table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function get_SOA_table(table_name::String; source_map = table_source_map)
if entry === nothing
search_method = StringDistances.Partial(StringDistances.Levenshtein())
suggestion, _ = StringDistances.findnearest(table_name,collect(keys(source_map)), search_method)
throw(ArgumentError("table name \"table_name\" not found in table set; " *
throw(ArgumentError("table name \"$table_name\" not found in table set; " *
"most similar available name is: \"$suggestion\""))
end
readXTbML(joinpath(artifact"mort.soa.org", "t$entry.xml"))
Expand All @@ -29,4 +29,4 @@ Given the id or name of a `mort.SOA.org` table, grab it and return it as a `Mort

!!! Remember that not all tables have been tested to work.
"""
table = get_SOA_table
const table = get_SOA_table
11 changes: 11 additions & 0 deletions test/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@
@test d.name == "test"
end

@testset "show" begin
# a custom table has no mort.SOA.org id, so no link should be printed
s = sprint(show, MIME"text/plain"(), MortalityTable(UltimateMortality([0.1, 0.2])))
@test !occursin("TableIdentity=nothing", s)
@test !occursin("mort.SOA.org ID", s)
@test occursin("Description", s)

s = sprint(show, MIME"text/plain"(), MortalityTable(UltimateMortality([0.1, 0.2]), metadata = TableMetaData(id = "42")))
@test occursin("TableIdentity=42", s)
end

@testset "mortality_vector" begin
v = [i for i = 3:10]
q = mortality_vector(v, start_age = 3)
Expand Down
10 changes: 10 additions & 0 deletions test/get_SOA_tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@
@test tbl isa MortalityTable

@test_throws ArgumentError get_SOA_table("hello")

# the error message should name the table that was not found
err = try
get_SOA_table("no such table")
nothing
catch e
e
end
@test err isa ArgumentError
@test occursin("no such table", err.msg)
end
Loading