Mercurial > repos > public > sbplib_julia
changeset 703:988e9cfcd58d feature/laplace_opset
Add function for == comparison of the fields for a struct, and apply to Laplace tests
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Mon, 15 Feb 2021 17:20:03 +0100 |
parents | 3cd582257072 |
children | a7efedbdede9 |
files | test/runtests.jl test/testSbpOperators.jl test/test_utils.jl |
diffstat | 3 files changed, 12 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/test/runtests.jl Mon Feb 15 11:30:34 2021 +0100 +++ b/test/runtests.jl Mon Feb 15 17:20:03 2021 +0100 @@ -1,3 +1,4 @@ +include("test_utils.jl") using Test using TestSetExtensions
--- a/test/testSbpOperators.jl Mon Feb 15 11:30:34 2021 +0100 +++ b/test/testSbpOperators.jl Mon Feb 15 17:20:03 2021 +0100 @@ -358,17 +358,8 @@ H_r = inner_product(boundary_grid(g_1D,id_r),op.quadratureClosure) Hb_dict = Dict(Pair(id_l,H_l),Pair(id_r,H_r)) - # TODO: Not sure why this doesnt work? Comparing the fields of - # Laplace seems to work. Reformulate below once solved. - @test_broken Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict) == Laplace(g_1D, sbp_operators_path()*"standard_diagonal.toml"; order=4) L = Laplace(g_1D, sbp_operators_path()*"standard_diagonal.toml"; order=4) - @test L.D == Δ - @test L.H == H - @test L.H_inv == Hi - @test L.e == e_dict - @test L.d == d_dict - @test L.H_boundary == Hb_dict - + @test cmp_fields(L,Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict)) @test L isa TensorMapping{T,1,1} where T @inferred Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict) end @@ -410,16 +401,8 @@ Pair(id_s,H_s),Pair(id_n,H_n), Pair(id_b,H_b),Pair(id_t,H_t)) - # TODO: Not sure why this doesnt work? Comparing the fields of - # Laplace seems to work. Reformulate below once solved. - @test_broken Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict) == Laplace(g_3D, sbp_operators_path()*"standard_diagonal.toml"; order=4) L = Laplace(g_3D, sbp_operators_path()*"standard_diagonal.toml"; order=4) - @test L.D == Δ - @test L.H == H - @test L.H_inv == Hi - @test L.e == e_dict - @test L.d == d_dict - @test L.H_boundary == Hb_dict + @test cmp_fields(L,Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict)) @test L isa TensorMapping{T,3,3} where T @inferred Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict) end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test_utils.jl Mon Feb 15 17:20:03 2021 +0100 @@ -0,0 +1,9 @@ +""" + cmp_fields(s1,s2) + +Compares the fields of two structs s1, s2, using the == operator. +""" +function cmp_fields(s1::T,s2::T) where T + f = fieldnames(T) + return getfield.(Ref(s1),f) == getfield.(Ref(s2),f) +end