Skip to content

Commit aa4c38f

Browse files
authored
Remove string interpolation in show (#40)
* Remove string interpolation in `show` * Add tests
1 parent 1eeab05 commit aa4c38f

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.jl.cov
22
*.jl.*.cov
33
*.jl.mem
4+
Manifest.toml

src/DiffResults.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,7 @@ hessian!(f, r::DiffResult, x) = derivative!(f, r, x, Val{2})
327327
# Pretty Printing #
328328
###################
329329

330-
Base.show(io::IO, r::ImmutableDiffResult) = print(io, "ImmutableDiffResult($(r.value), $(r.derivs))")
331-
332-
Base.show(io::IO, r::MutableDiffResult) = print(io, "MutableDiffResult($(r.value), $(r.derivs))")
330+
Base.show(io::IO, r::ImmutableDiffResult) = print(io, "ImmutableDiffResult(", r.value, ", ", r.derivs, ")")
331+
Base.show(io::IO, r::MutableDiffResult) = print(io, "MutableDiffResult(", r.value, ", ", r.derivs, ")")
333332

334333
end # module

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
2424
@test rs === DiffResult(s0, s1, s2)
2525
@test rsmix === DiffResult(n0, s0, s1)
2626

27+
@test repr(rn) == "ImmutableDiffResult($n0, ($n1, $n2))"
28+
@test repr(rx) == "MutableDiffResult($x0, ($x1, $x2))"
29+
@test repr(rs) == "ImmutableDiffResult($s0, ($s1, $s2))"
30+
@test repr(rsmix) == "ImmutableDiffResult($n0, ($s0, $s1))"
31+
2732
@test issimilar(GradientResult(x0), DiffResult(first(x0), x0))
2833
@test issimilar(JacobianResult(x0), DiffResult(x0, similar(x0, k, k)))
2934
@test issimilar(JacobianResult(similar(x0, k + 1), x0), DiffResult(similar(x0, k + 1), similar(x0, k + 1, k)))

0 commit comments

Comments
 (0)