Skip to content

Commit

Permalink
Prettier printing for custom types
Browse files Browse the repository at this point in the history
  • Loading branch information
brenhinkeller committed Mar 25, 2023
1 parent d185c71 commit b7cb60c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
22 changes: 17 additions & 5 deletions src/show.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@

# Custom pretty-printing for York fit results
function Base.show(io::IO, ::MIME"text/plain", x::YorkFit{T}) where T
print(io, "YorkFit{$T}:\nLeast-squares linear fit of the form y = a + bx where")
print(io, "\n intercept a : $(x.intercept) (1σ)")
print(io, "\n slope b : $(x.slope) (1σ)")
print(io, "\n MSWD : $(x.mswd)\n")
print(io, """YorkFit{$T}:
Least-squares linear fit of the form y = a + bx with
intercept: $(x.intercept) (1σ)
slope : $(x.slope) (1σ)
MSWD : $(x.mswd)
"""
)
end

Base.show(io::IO, ::MIME"text/plain", x::CI) = print(io, x)
function Base.show(io::IO, ::MIME"text/plain", x::CI{T}) where T
print(io, """CI{$T} $x
mean : $(x.mean)
sigma : $(x.sigma)
median: $(x.median)
lower : $(x.lower)
upper : $(x.upper)
"""
)
end
function Base.print(io::IO, x::CI)
l = round(x.mean - x.lower, sigdigits=3)
u = round(x.upper - x.mean, sigdigits=3)
Expand Down
16 changes: 10 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ using Test, Statistics
using Plots
using Measurements

@testset "General" begin
@test Isoplot.val(1±1) === 1.0
@test Isoplot.err(1±1) === 1.0
@test Isoplot.val(1) === 1
@test Isoplot.err(1) === 0
@testset "Show" begin
yf = Isoplot.YorkFit(1±1, 1±1, 1.0)
@test display(yf) != NaN

ci = CI(1:10)
@test ci == CI{Float64}(5.5, 3.0276503540974917, 5.5, 1.225, 9.775)
@test "$ci" === "5.5 +4.28/-4.28"
@test display(ci) != NaN
end

@testset "General" begin
@test Isoplot.val(1±1) === 1.0
@test Isoplot.err(1±1) === 1.0
@test Isoplot.val(1) === 1
@test Isoplot.err(1) === 0
end

@testset "U-Pb" begin
r75 = 22.6602
σ75 = 0.017516107998
Expand Down Expand Up @@ -109,7 +114,6 @@ end
@test fobj.slope.val 1.041124018512526
@test fobj.slope.err 0.0035683808205783673
@test fobj.mswd 1.1419901440278089
@test display(fobj) != NaN

x = ((1:100) .+ randn.()) 1
y = (2*(1:100) .+ randn.()) 1
Expand Down

2 comments on commit b7cb60c

@brenhinkeller
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register
Release notes:

  • Add a CI type and constructors
  • Add new method for plotting a distribution of many concordialines
  • Allow upperintercept to work with a Measurement for a lower intercept
  • Prettier printing

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/80299

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.3 -m "<description of version>" b7cb60c3fef96623af33aece6be57205354a636e
git push origin v0.2.3

Please sign in to comment.