Skip to content

Commit

Permalink
Increase test coverage by sometimes returning Float64 roots
Browse files Browse the repository at this point in the history
  • Loading branch information
kagalenko-m-b authored and kagalenko-m-b committed Apr 11, 2020
1 parent d9249de commit 30bf601
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
16 changes: 13 additions & 3 deletions .travis.yml
@@ -1,19 +1,29 @@
language: julia

os:
- linux

arch:
- amd64

julia:
- nightly
- 1.3
- 1.4

notifications:
email: false

coveralls: true

before_install:
- sudo apt-add-repository -y ppa:leo.robol/mpsolve
- sudo apt-get update -qq
- sudo apt-get install -y libmps3-dev
- sudo apt-get install -y libmps3 libmps3-dev

script:
- julia --color=yes -e 'using Pkg; Pkg.test(; coverage=true)'
- julia --color=yes -e 'using Pkg; Pkg.test(; coverage=true)';

after_success:
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder());Codecov.submit(Codecov.process_folder())';
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage;
Coveralls.submit(Coveralls.process_folder())'
4 changes: 1 addition & 3 deletions README.md
@@ -1,7 +1,5 @@
[![Build Status](https://travis-ci.org/kagalenko-m-b/MPSolve.jl.svg?branch=master)](https://travis-ci.org/kagalenko-m-b/MPSolve.jl)
[![Coverage Status](https://coveralls.io/repos/github/kagalenko-m-b/MPSolve.jl/badge.svg?branch=master)](https://coveralls.io/github/kagalenko-m-b/MPSolve.jl?branch=master)
[![codecov](https://codecov.io/gh/kagalenko-m-b/MPSolve.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/kagalenko-m-b/MPSolve.jl/)

[![Coverage Status](https://coveralls.io/repos/github/kagalenko-m-b/MPSolve.jl/badge.svg)](https://coveralls.io/github/kagalenko-m-b/MPSolve.jl)

# MPSolve.jl
This repository contains the Julia interface to the MPSolve
Expand Down
1 change: 1 addition & 0 deletions src/MPSolve.jl
Expand Up @@ -97,6 +97,7 @@ struct Mpf
end
end

Base.convert(::Type{Mpf}, x::Int64) = Mpf(x)
Base.convert(::Type{Mpf}, x::T) where T<:Union{Int32,Int16,Int8} = Mpf(Int64(x))

function BigFloat(f::Mpf)
Expand Down
36 changes: 25 additions & 11 deletions test/runtests.jl
Expand Up @@ -18,17 +18,31 @@ end

function roots2secular_coeffs(roots)
M = length(roots)
D = exp.(im*pi*range(1/M, stop=2-1/M, length=M))
L = -D/M
R = 1.01
D = R*exp.(im*pi*range(1/M, stop=2-1/M, length=M))
L = -D/(M*R^M)
F = [-prod(d .- roots) for d in D]
return L.*F,D
end

function solve_test(rts, args...)
(app, rad) = mps_roots(args..., 54)
function solve_test(rts, args...;n_digits=nothing)
if isnothing(n_digits)
if real(eltype(args[1])) <:Union{BigFloat,BigInt}
n_digits=55
else
n_digits=53
end
end
(app, rad) = mps_roots(args...,n_digits)
for i = 1:length(rts)
(err, ind) = findmin(map(abs, app .- rts[i]))
@test err <= rad[ind]
if isnan(rad[ind])
err_radius = 10*eps(real(eltype(app)))
else
err_radius = max(rad[ind],
abs(app[ind])*eps(real(eltype(app))))
end
@test err <= err_radius
end
end

Expand Down Expand Up @@ -63,7 +77,7 @@ end
function test_secular_roots_unity(n)
E = unity_roots(n)
A,B = roots2secular_coeffs(E)
solve_test(E, ComplexF64.(A), ComplexF64.(B))
solve_test(E, ComplexF64.(A), ComplexF64.(B), n_digits=54)
end
"""
Test solving the Wilkinson polynomial
Expand All @@ -74,11 +88,11 @@ function test_wilkinson(n)
solve_test(roots, C)
end

# function test_secular_wilkinson(n)
# roots = big.(range(1, stop=n))
# A,B = roots2secular_coeffs(roots)
# solve_test(roots, A, B)
# end
function test_secular_wilkinson(n)
roots = big.(range(1, stop=n))
A,B = roots2secular_coeffs(roots)
solve_test(roots, A, B)
end
"""
Test if solving a polynomial with complex integer coefficients
works.
Expand Down

0 comments on commit 30bf601

Please sign in to comment.