Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for unsafe_trunc returning arbitrary values #289

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions test/fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,46 @@ 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.
_to_fixed(::Val, x) = x % Q0f7
_to_fixed(::Val{:Q0f7}, x) = x % Q0f7
_to_fixed(::Val{:Q0f15}, x) = x % Q0f15
buf = IOBuffer()
# in range
for vs in ((:Q0f7, :Q0f15), (:Q0f15, :Q0f7))
for v in vs
show(buf, _to_fixed(Val(v), -1.0))
print(buf, " ")
end
end
issue288_in = String(take!(buf))
# out of range
for vs in ((:Q0f7, :Q0f15), (:Q0f15, :Q0f7))
for v in vs
show(buf, _to_fixed(Val(v), 1.0))
print(buf, " ")
end
end
issue288_out = String(take!(buf))

@testset "issue288" begin
expected_issue288 = "-1.0Q0f7 -1.0Q0f15 -1.0Q0f15 -1.0Q0f7 "
if issue288_in == expected_issue288 # just leave it in the report
@test issue288_in == expected_issue288
else
@test_broken issue288_in == expected_issue288
@warn """broken: "$issue288_in"\nexpected: "$expected_issue288" """
end
expected_issue288 = "-1.0Q0f7 -1.0Q0f15 -1.0Q0f15 -1.0Q0f7 "
if issue288_out == expected_issue288 # just leave it in the report
@test issue288_out == expected_issue288
else
@test_broken issue288_out == expected_issue288
@warn """broken: "$issue288_out"\nexpected: "$expected_issue288" """
end
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)
Expand Down
40 changes: 40 additions & 0 deletions test/normed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,46 @@ 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.
_to_normed(::Val, x) = x % N0f8
_to_normed(::Val{:N0f8}, x) = x % N0f8
_to_normed(::Val{:N0f16}, x) = x % N0f16
buf = IOBuffer()
# in range
for vs in ((:N0f8, :N0f16), (:N0f16, :N0f8))
for v in vs
show(buf, _to_normed(Val(v), 1.0))
print(buf, " ")
end
end
issue288_in = String(take!(buf))
# out of range
for vs in ((:N0f8, :N0f16), (:N0f16, :N0f8))
for v in vs
show(buf, _to_normed(Val(v), -1.0))
print(buf, " ")
end
end
issue288_out = String(take!(buf))

@testset "issue288" begin
expected_issue288 = "1.0N0f8 1.0N0f16 1.0N0f16 1.0N0f8 "
if issue288_in == expected_issue288 # just leave it in the report
@test issue288_in == expected_issue288
else
@test_broken issue288_in == expected_issue288
@warn """broken: "$issue288_in"\nexpected: "$expected_issue288" """
end
expected_issue288 = "0.004N0f8 2.0e-5N0f16 2.0e-5N0f16 0.004N0f8 "
if issue288_out == expected_issue288 # just leave it in the report
@test issue288_out == expected_issue288
else
@test_broken issue288_out == expected_issue288
@warn """broken: "$issue288_out"\nexpected: "$expected_issue288" """
end
end

@testset "domain of f" begin
@test_throws DomainError zero(Normed{UInt8,-1})
@test_throws DomainError zero(Normed{UInt8,0})
Expand Down
Loading