Skip to content

testapprox should be moved or inlined #133

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

Closed
kimikage opened this issue Nov 5, 2019 · 1 comment · Fixed by #135
Closed

testapprox should be moved or inlined #133

kimikage opened this issue Nov 5, 2019 · 1 comment · Fixed by #135

Comments

@kimikage
Copy link
Collaborator

kimikage commented Nov 5, 2019

The "fixed" testset depends on testapprox which is defined in "test/normed.jl" (formerly named ufixed.jl).

@testset "testapprox" begin
for T in [Fixed{Int8,7}, Fixed{Int16,8}, Fixed{Int16,10}]
testapprox(T) # defined in ufixed.jl
end
end

function testapprox(::Type{T}) where {T}
for x = typemin(T):eps(T):typemax(T)-eps(T)
y = x+eps(T)
@test x y
@test y x
@test !(x y+eps(T))
end
end

This thwarts the selective execution of tests and causes an error(UndefVarError: testapprox not defined) in certain environments (e.g. Julia v1.0.3 32-bit ARMv7).

I think testapprox is not so complicated. It may be a good idea to inline the function or define it locally.
This may be off topic, but I also think there are too many test cases generated by testapprox (or its friend testtrunc). @test should be outside the loop.

@kimikage
Copy link
Collaborator Author

kimikage commented Nov 6, 2019

Umm...:confused:
Should I fix only the "approx"?

function testtrunc(inc::T) where {T}
    incf = convert(Float64, inc)
    tm = reinterpret(typemax(T))/reinterpret(one(T))
    Ti = FixedPointNumbers.rawtype(T)
    itr = zero(Ti):Ti(min(1e6, typemax(Ti)-1))
    pairs = ((x = reinterpret(T, i), xf = incf * i) for i in itr)
    @test all(t -> typeof(trunc(t.x)) == T,   pairs)
    @test all(t -> trunc(t.x) == trunc(t.xf), pairs)
    @test all(t -> typeof(round(t.x)) == T,   pairs)
    @test all(t -> round(t.x) == round(t.xf), pairs)
    @test all(t -> typeof(floor(t.x)) == T,   pairs)
    @test all(t -> floor(t.x) == floor(t.xf), pairs)
    @test all(t -> typeof(ceil(t.x)) == T,    pairs)
    @test all(t -> ceil(t.x) == ceil(t.xf) || ceil(t.xf) > tm, pairs)

    @test all(t -> trunc(Int, t.x) == trunc(Int, t.xf), pairs)
    @test all(t -> round(Int, t.x) == round(Int, t.xf), pairs)
    @test all(t -> floor(Int, t.x) == floor(Int, t.xf), pairs)
    @test all(t -> ceil(Int, t.x) == ceil(Int, t.xf) || ceil(t.xf) > tm, pairs)
end

@testset "trunc" begin
    @testset "trunc $T" for T in (FixedPointNumbers.UF..., UF2...)
        testtrunc(eps(T))
    end
end

@testset "approx" begin
    @testset "approx $T" for T in FixedPointNumbers.UF
        xs = typemin(T):eps(T):typemax(T)-eps(T)
        @test all(x -> x  x + eps(T), xs)
        @test all(x -> x + eps(T)  x, xs)
        @test !any(x -> x - eps(T)  x + eps(T), xs)
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant