diff --git a/test/fixed.jl b/test/fixed.jl index 8fbb1bf8..3836a9a2 100644 --- a/test/fixed.jl +++ b/test/fixed.jl @@ -7,6 +7,25 @@ function symbol_to_inttype(::Type{Fixed}, s::Symbol) d[s] end +# issue #288 +# The following needs to be outside of `@testset` to reproduce the issue. +# issue #288 +# The following needs to be outside of `@testset` to reproduce the issue. +@inline _to_fixed(::Val, x) = x % Q0f7 +@inline _to_fixed(::Val{:Q0f15}, x) = x % Q0f15 +function _issue288(::Type{Fixed}, x) + buf = IOBuffer() + for sym in (:Q0f7, :Q0f15) + show(buf, _to_fixed(Val(sym), x)) + print(buf, " ") + end + for sym in (:Q0f15, :Q0f7) + show(buf, _to_fixed(Val(sym), x)) + print(buf, " ") + end + return String(take!(buf)) +end + function test_op(fun::Fun, fx::F, fy::F, fxf, fyf, tol) where {Fun, F} # Make sure that the result is representable zf = fun(fxf, fyf) @@ -282,6 +301,23 @@ end @test -1 % Q0f7 === Q0f7(-1) @test -2 % Q0f7 === Q0f7(0) + + # issue #288 + expected_issue288 = "-1.0Q0f7 -1.0Q0f15 -1.0Q0f15 -1.0Q0f7 " + if _issue288(Fixed, -1.0) == expected_issue288 # just leave it in the report + @test _issue288(Fixed, -1.0) == expected_issue288 + else + @test_broken _issue288(Fixed, -1.0) == expected_issue288 + @warn """broken: "$(_issue288(Fixed, -1.0))"\nexpected: "$expected_issue288" """ + end + # out of range + expected_issue288 = "-1.0Q0f7 -1.0Q0f15 -1.0Q0f15 -1.0Q0f7 " + if _issue288(Fixed, 1.0) == expected_issue288 # just leave it in the report + @test _issue288(Fixed, 1.0) == expected_issue288 + else + @test_broken _issue288(Fixed, 1.0) == expected_issue288 + @warn """broken: "$(_issue288(Fixed, 1.0))"\nexpected: "$expected_issue288" """ + end end @testset "neg" begin diff --git a/test/normed.jl b/test/normed.jl index 4678182c..8bed8337 100644 --- a/test/normed.jl +++ b/test/normed.jl @@ -7,6 +7,25 @@ function symbol_to_inttype(::Type{Normed}, s::Symbol) d[s] end +# issue #288 +# The following needs to be outside of `@testset` to reproduce the issue. +@inline _to_normed(::Val, x) = x % N0f8 +@inline _to_normed(::Val{:N0f16}, x) = x % N0f16 +function _issue288(::Type{Normed}, x) + buf = IOBuffer() + for sym in (:N0f8, :N0f16) + print(buf, _to_normed(Val(sym), -1.0)) + print(buf, " ") + end + #= + for sym in (:N0f16, :N0f8) + show(buf, _to_normed(Val(sym), -1.0)) + print(buf, " ") + end + =# + return String(take!(buf)) +end + @testset "domain of f" begin @test_throws DomainError zero(Normed{UInt8,-1}) @test_throws DomainError zero(Normed{UInt8,0}) @@ -279,6 +298,23 @@ end # issue #211 @test big"1.2" % N0f8 === 0.196N0f8 @test reinterpret(BigFloat(0x0_01234567_89abcdef) % N63f1) === 0x01234567_89abcdef + + # issue #288 + expected_issue288 = "1.0N0f8 1.0N0f16 1.0N0f16 1.0N0f8 " + if _issue288(Normed, 1.0) == expected_issue288 # just leave it in the report + @test _issue288(Normed, 1.0) == expected_issue288 + else + @test_broken _issue288(Normed, 1.0) == expected_issue288 + @warn """broken: "$(_issue288(Normed, 1.0))"\nexpected: "$expected_issue288" """ + end + # out of range + expected_issue288 = "0.502N0f8 0.50001N0f16 0.50001N0f16 0.502N0f8 " + if _issue288(Normed, -0.5) == expected_issue288 # just leave it in the report + @test _issue288(Normed, -0.5) == expected_issue288 + else + @test_broken _issue288(Normed, -0.5) == expected_issue288 + @warn """broken: "$(_issue288(Normed, -0.5))"\nexpected: "$expected_issue288" """ + end end @testset "arithmetic" begin diff --git a/test/runtests.jl b/test/runtests.jl index d037d440..32b74c61 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ using FixedPointNumbers, Test, Aqua - +@info Sys.ARCH Aqua.test_all(FixedPointNumbers) if Sys.ARCH === :x86_64 || Sys.ARCH === :i686