Skip to content

Commit

Permalink
Merge pull request #1 from putianyi889/coverage-1
Browse files Browse the repository at this point in the history
add doctest and try to see the coverage
  • Loading branch information
putianyi889 authored Feb 28, 2024
2 parents f0cd665 + 34c5a38 commit 3110f77
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ jobs:
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: lcov.info
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ version = "1.0.0-DEV"

[compat]
Aqua = "0.8"
Documenter = "0.27, 1"
Test = "1"
julia = "1"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "Test"]
test = ["Aqua", "Documenter", "Test"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://putianyi889.github.io/EltypeExtensions.jl/stable)
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://putianyi889.github.io/EltypeExtensions.jl/dev)
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)
[![codecov](https://codecov.io/gh/putianyi889/EltypeExtensions.jl/branch/master/graph/badge.svg?label=codecov)](https://codecov.io/gh/putianyi889/EltypeExtensions.jl)
16 changes: 11 additions & 5 deletions src/EltypeExtensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import Base: convert

export elconvert, basetype, baseconvert, precisiontype, precisionconvert

@static if VERSION < v"1.10"
@inline bigfloatconvert(x, prec) = BigFloat(x, prec)
else
@inline bigfloatconvert(x, prec) = BigFloat(x, precision = prec)
end

"""
elconvert(T, A)
Expand All @@ -19,7 +25,7 @@ $(repr("text/plain", Matrix{Float64}))
```
"""
elconvert(::Type{T}, A::AbstractArray) where T = AbstractArray{T}(A)
elconvert(::Type{T}, A::AbstractRange) where T = AbstractRange{T}(A)
elconvert(::Type{T}, A::AbstractRange) where T = T(first(A)):T(step(A)):T(last(A))
elconvert(::Type{T}, A::AbstractSet) where T = AbstractSet{T}(A)

"""
Expand Down Expand Up @@ -116,19 +122,19 @@ Convert `A` to have the [`precisiontype`](@ref) of `T`. If `T` has adjustable pr
# Examples
```jldoctest; setup = :(using EltypeExtensions: precisionconvert)
julia> precisionconvert(BigFloat, 1//3+im, 128)
0.3333333333333333333333333333333333333338 + 1.0im
$(repr(bigfloatconvert(1//3, 128))) + 1.0im
julia> precisionconvert(Float16, [[m/n for n in 1:3] for m in 1:3])
3-element Vector{Vector{Float16}}:
3-element $(repr(Vector{Vector{Float16}})):
[1.0, 0.5, 0.3333]
[2.0, 1.0, 0.6665]
[3.0, 1.5, 1.0]
```
"""
precisionconvert(T,A) = precisionconvert(T,A,precision(T))
precisionconvert(::Type{T}, A::S, prec) where {T,S} = convert(_to_precisiontype(T,S), A)
precisionconvert(::Type{BigFloat}, x::Real, prec) = BigFloat(x, prec)
precisionconvert(::Type{BigFloat}, x::Complex, prec) = Complex(BigFloat(real(x), prec), BigFloat(imag(x), prec))
precisionconvert(::Type{BigFloat}, x::Real, prec) = bigfloatconvert(x, prec)
precisionconvert(::Type{BigFloat}, x::Complex, prec) = Complex(bigfloatconvert(real(x), prec), bigfloatconvert(imag(x), prec))
precisionconvert(::Type{BigFloat}, A, prec) = precisionconvert.(BigFloat, A, prec)

end
5 changes: 3 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Documenter
using EltypeExtensions
using Test
using Aqua

@testset "EltypeExtensions.jl" begin
# Write your tests here.
@testset "Doctest" begin
doctest(EltypeExtensions)
end

@testset "Aqua" begin
Expand Down

0 comments on commit 3110f77

Please sign in to comment.