Skip to content

Commit 3ac2fbe

Browse files
committed
Plug more holes in test coverage
1 parent d8ec6ae commit 3ac2fbe

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/fixed_rational.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ Base.inv(x::F) where {F<:FixedRational} = unsafe_fixed_rational(widemul(denom(F)
4848
Base.:*(l::F, r::Integer) where {F<:FixedRational} = unsafe_fixed_rational(l.num * r, eltype(F), val_denom(F))
4949
Base.:*(l::Integer, r::F) where {F<:FixedRational} = unsafe_fixed_rational(l * r.num, eltype(F), val_denom(F))
5050

51-
Base.:(==)(x::F, y::F) where {F<:FixedRational} = x.num == y.num
52-
Base.isless(x::F, y::F) where {F<:FixedRational} = isless(x.num, y.num)
53-
Base.:<(x::F, y::F) where {F<:FixedRational} = x.num < y.num
54-
Base.:<=(x::F, y::F) where {F<:FixedRational} = x.num <= y.num
55-
Base.isapprox(x::F, y::F; kws...) where {F<:FixedRational} = isapprox(x.num, y.num; kws...)
51+
for comp in (:(==), :isequal, :<, :(isless), :<=)
52+
@eval Base.$comp(x::F, y::F) where {F<:FixedRational} = $comp(x.num, y.num)
53+
end
54+
5655
Base.iszero(x::FixedRational) = iszero(x.num)
5756
Base.isone(x::F) where {F<:FixedRational} = x.num == denom(F)
5857
Base.isinteger(x::F) where {F<:FixedRational} = iszero(x.num % denom(F))

test/unittests.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,21 @@ end
413413
# Required to hit integer branch (otherwise will go to `literal_pow`)
414414
f(i::Int) = Dimensions(length=1, mass=-1)^i
415415
@test f(2) == Dimensions(length=2, mass=-2)
416+
417+
# Null conversion
418+
@test typeof(FixedRational{Int,10}(FixedRational{Int,10}(2))) == FixedRational{Int,10}
419+
420+
# Conversion to Rational without specifying type
421+
@test convert(Rational, FixedRational{UInt8,6}(2)) === Rational{UInt8}(2)
422+
423+
# Showing rationals
424+
function show_string(i)
425+
io = IOBuffer()
426+
show(io, i)
427+
return String(take!(io))
428+
end
429+
@test show_string(FixedRational{Int,10}(2)) == "2"
430+
@test show_string(FixedRational{Int,10}(11//10)) == "11//10"
416431
end
417432

418433
@testset "Quantity promotion" begin
@@ -514,6 +529,9 @@ end
514529
# So the numerical value is different from other constants:
515530
@test ustrip(us"Constants.h") == ustrip(u"Constants.h")
516531
@test ustrip(us"Constants.au") != ustrip(u"Constants.au")
532+
533+
# Test conversion
534+
@test typeof(SymbolicDimensions{Rational{Int}}(dimension(us"km/s"))) == SymbolicDimensions{Rational{Int}}
517535
end
518536

519537
@testset "Test ambiguities" begin

0 commit comments

Comments
 (0)