Skip to content

Commit

Permalink
Add test for unsafe_trunc returning arbitrary values
Browse files Browse the repository at this point in the history
  • Loading branch information
kimikage committed Apr 28, 2024
1 parent 37e83e7 commit 68c6fca
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 15 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/UnitTest.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Unit test

on:
create:
tags:
push:
branches:
- master
- release-*
tags: ['*']
pull_request:

jobs:
Expand All @@ -15,13 +15,15 @@ jobs:
fail-fast: false
matrix:
julia-version: ['1.0', '1', '1.6', 'nightly']
os: [ubuntu-latest, windows-latest, macOS-latest]
os: [ubuntu-latest, windows-latest, macos-13]
julia-arch: [x64]
# only test one 32-bit job
include:
- os: ubuntu-latest
- os: ubuntu-latest # only test one 32-bit job
julia-version: '1'
julia-arch: x86
- os: macos-latest
julia-version: '1'
julia-arch: aarch64

steps:
- uses: actions/checkout@v4
Expand Down
19 changes: 10 additions & 9 deletions .github/workflows/UnitTestArm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ jobs:
strategy:
fail-fast: false
matrix:
julia-version: ['1.0', '1', '1.6', 'nightly']
os: [ubuntu-latest]
julia-version: ['1.0', '1.6', '1', 'nightly']
os: [macos-latest]
distro: [ubuntu_latest]
arch: [aarch64]

steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.julia-version }}
version: '1'
arch: aarch64
- uses: julia-actions/cache@v1
- name: Download Julia Binary
run: >
Expand All @@ -46,8 +47,8 @@ jobs:
- name: Extract Julia Files
run: |
mkdir -p /home/runner/work/julia/
tar -xf /tmp/julia-aarch64.tar.gz --strip-components=1 -C /home/runner/work/julia/
mkdir -p /Users/runner/work/julia/
tar -xf /tmp/julia-aarch64.tar.gz --strip-components=1 -C /Users/runner/work/julia/
rm /tmp/julia-aarch64.tar.gz
- uses: uraimo/[email protected]
Expand All @@ -56,12 +57,12 @@ jobs:
arch: ${{ matrix.arch }}
distro: ${{ matrix.distro }}
dockerRunArgs: |
-v "/home/runner/work/julia:/home/runner/work/julia"
-v "/home/runner/.julia/registries:/root/.julia/registries"
-v "/Users/runner/work/julia:/home/runner/work/julia"
-v "/Users/runner/.julia/registries:/root/.julia/registries"
--net=host
install: |
ln -s /home/runner/work/julia/bin/julia /usr/local/bin/julia
echo /home/runner/work/julia/lib > /etc/ld.so.conf.d/julia.conf
ln -s /Users/runner/work/julia/bin/julia /usr/local/bin/julia
echo /Users/runner/work/julia/lib > /etc/ld.so.conf.d/julia.conf
mkdir -p /root/.julia/registries/General
run: |
julia --compile=min -O0 -e 'using InteractiveUtils; versioninfo();'
Expand Down
36 changes: 36 additions & 0 deletions test/fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions test/normed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using FixedPointNumbers, Test, Aqua

@info Sys.ARCH
Aqua.test_all(FixedPointNumbers)

if Sys.ARCH === :x86_64 || Sys.ARCH === :i686
Expand Down

0 comments on commit 68c6fca

Please sign in to comment.