Skip to content

Commit

Permalink
Value equality for MortalityTable types (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-b1 authored Mar 3, 2023
1 parent aa662ae commit 616a20f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ docs/site/
# environment.
Manifest.toml

.vscode

.DS_Store
10 changes: 10 additions & 0 deletions src/MortalityTable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ end
Base.getindex(u::UltimateTable, x) = u.ultimate[x]
Base.lastindex(u::UltimateTable) = lastindex(u.ultimate)

Base.:(==)(tbl1::UltimateTable, tbl2::UltimateTable) = tbl1.metadata == tbl2.metadata && isequal(tbl1.ultimate, tbl2.ultimate)
function Base.:(==)(tbl1::SelectUltimateTable, tbl2::SelectUltimateTable)
return (
tbl1.metadata == tbl2.metadata &&
isequal(tbl1.ultimate, tbl2.ultimate) &&
isequal(tbl1.select, tbl2.select)
)
end



function MortalityTable(select, ultimate; metadata = TableMetaData())
return SelectUltimateTable(select, ultimate, metadata)
Expand Down
14 changes: 11 additions & 3 deletions test/MortalityTables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,17 @@

end




@testset "value equality" begin
ult_table_name = "1980 CSO Basic Table – Male, ANB"
cso1980_a = MortalityTables.table(ult_table_name)
cso1980_b = MortalityTables.table(ult_table_name)
@test cso1980_a == cso1980_b

select_table_name = "2001 CSO Super Preferred Select and Ultimate - Male Nonsmoker, ANB"
cso2001_a = MortalityTables.table(select_table_name)
cso2001_b = MortalityTables.table(select_table_name)
@test cso2001_a == cso2001_b
end

end
end

0 comments on commit 616a20f

Please sign in to comment.