Mercurial > repos > public > sbplib_julia
changeset 603:fbff4009c08a refactor/toml_operator_format
Add tests for parse_rational()
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 05 Dec 2020 13:07:07 +0100 |
parents | c2239c7cd71e |
children | 8fcf9c9afb30 |
files | src/SbpOperators/readoperator.jl test/testSbpOperators.jl |
diffstat | 2 files changed, 10 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/SbpOperators/readoperator.jl Sat Dec 05 13:05:53 2020 +0100 +++ b/src/SbpOperators/readoperator.jl Sat Dec 05 13:07:07 2020 +0100 @@ -104,7 +104,7 @@ function parse_rational(str) expr = Meta.parse(replace(str, "/"=>"//")) - return eval(expr) + return eval(:(Rational($expr))) end function pad_tuple(t::NTuple{N, T}, n::Integer) where {N,T}
--- a/test/testSbpOperators.jl Sat Dec 05 13:05:53 2020 +0100 +++ b/test/testSbpOperators.jl Sat Dec 05 13:07:07 2020 +0100 @@ -19,6 +19,15 @@ @test SbpOperators.Stencil((1,2,3,4), center=4) == SbpOperators.Stencil((-3, 0),(1,2,3,4)) end +@testset "parse_rational" begin + @test SbpOperators.parse_rational("1") isa Rational + @test SbpOperators.parse_rational("1") == 1//1 + @test SbpOperators.parse_rational("1/2") isa Rational + @test SbpOperators.parse_rational("1/2") == 1//2 + @test SbpOperators.parse_rational("37/13") isa Rational + @test SbpOperators.parse_rational("37/13") == 37//13 +end + # @testset "apply_quadrature" begin # op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) # h = 0.5