comparison test/testSbpOperators.jl @ 613:eaa8c852ddf2 refactor/toml_operator_format

Import Stecil in tests to make it less verbose
author Jonatan Werpers <jonatan@werpers.com>
date Sun, 06 Dec 2020 10:49:41 +0100
parents 8fcf9c9afb30
children f59e1732eacc a78bda7084f6
comparison
equal deleted inserted replaced
609:7975143118e8 613:eaa8c852ddf2
4 using Sbplib.RegionIndices 4 using Sbplib.RegionIndices
5 using Sbplib.LazyTensors 5 using Sbplib.LazyTensors
6 using LinearAlgebra 6 using LinearAlgebra
7 using TOML 7 using TOML
8 8
9 import Sbplib.SbpOperators.Stencil
10
9 @testset "SbpOperators" begin 11 @testset "SbpOperators" begin
10 12
11 @testset "Stencil" begin 13 @testset "Stencil" begin
12 s = SbpOperators.Stencil((-2,2), (1.,2.,2.,3.,4.)) 14 s = Stencil((-2,2), (1.,2.,2.,3.,4.))
13 @test s isa SbpOperators.Stencil{Float64, 5} 15 @test s isa Stencil{Float64, 5}
14 16
15 @test eltype(s) == Float64 17 @test eltype(s) == Float64
16 @test SbpOperators.scale(s, 2) == SbpOperators.Stencil((-2,2), (2.,4.,4.,6.,8.)) 18 @test SbpOperators.scale(s, 2) == Stencil((-2,2), (2.,4.,4.,6.,8.))
17 19
18 @test SbpOperators.Stencil((1,2,3,4), center=1) == SbpOperators.Stencil((0, 3),(1,2,3,4)) 20 @test Stencil((1,2,3,4), center=1) == Stencil((0, 3),(1,2,3,4))
19 @test SbpOperators.Stencil((1,2,3,4), center=2) == SbpOperators.Stencil((-1, 2),(1,2,3,4)) 21 @test Stencil((1,2,3,4), center=2) == Stencil((-1, 2),(1,2,3,4))
20 @test SbpOperators.Stencil((1,2,3,4), center=4) == SbpOperators.Stencil((-3, 0),(1,2,3,4)) 22 @test Stencil((1,2,3,4), center=4) == Stencil((-3, 0),(1,2,3,4))
21 end 23 end
22 24
23 @testset "parse_rational" begin 25 @testset "parse_rational" begin
24 @test SbpOperators.parse_rational("1") isa Rational 26 @test SbpOperators.parse_rational("1") isa Rational
25 @test SbpOperators.parse_rational("1") == 1//1 27 @test SbpOperators.parse_rational("1") == 1//1
56 ] 58 ]
57 """ 59 """
58 60
59 parsed_toml = TOML.parse(toml_str) 61 parsed_toml = TOML.parse(toml_str)
60 @testset "get_stencil" begin 62 @testset "get_stencil" begin
61 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil") == SbpOperators.Stencil((-1/2, 0., 1/2), center=2) 63 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil") == Stencil((-1/2, 0., 1/2), center=2)
62 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil", center=1) == SbpOperators.Stencil((-1/2, 0., 1/2); center=1) 64 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil", center=1) == Stencil((-1/2, 0., 1/2); center=1)
63 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil", center=3) == SbpOperators.Stencil((-1/2, 0., 1/2); center=3) 65 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil", center=3) == Stencil((-1/2, 0., 1/2); center=3)
64 66
65 @test get_stencil(parsed_toml, "order2", "H", "inner") == SbpOperators.Stencil((1.,), center=1) 67 @test get_stencil(parsed_toml, "order2", "H", "inner") == Stencil((1.,), center=1)
66 68
67 @test_throws AssertionError get_stencil(parsed_toml, "meta", "type") 69 @test_throws AssertionError get_stencil(parsed_toml, "meta", "type")
68 @test_throws AssertionError get_stencil(parsed_toml, "order2", "D1", "closure_stencils") 70 @test_throws AssertionError get_stencil(parsed_toml, "order2", "D1", "closure_stencils")
69 end 71 end
70 72
71 @testset "get_stencils" begin 73 @testset "get_stencils" begin
72 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=(1,)) == (SbpOperators.Stencil((-1., 1.), center=1),) 74 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=(1,)) == (Stencil((-1., 1.), center=1),)
73 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=(2,)) == (SbpOperators.Stencil((-1., 1.), center=2),) 75 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=(2,)) == (Stencil((-1., 1.), center=2),)
74 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=[2]) == (SbpOperators.Stencil((-1., 1.), center=2),) 76 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=[2]) == (Stencil((-1., 1.), center=2),)
75 77
76 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=[1,1,1,1]) == ( 78 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=[1,1,1,1]) == (
77 SbpOperators.Stencil(( 2., -5., 4., -1., 0., 0.), center=1), 79 Stencil(( 2., -5., 4., -1., 0., 0.), center=1),
78 SbpOperators.Stencil(( 1., -2., 1., 0., 0., 0.), center=1), 80 Stencil(( 1., -2., 1., 0., 0., 0.), center=1),
79 SbpOperators.Stencil(( -4/43, 59/43, -110/43, 59/43, -4/43, 0.), center=1), 81 Stencil(( -4/43, 59/43, -110/43, 59/43, -4/43, 0.), center=1),
80 SbpOperators.Stencil(( -1/49, 0., 59/49, -118/49, 64/49, -4/49), center=1), 82 Stencil(( -1/49, 0., 59/49, -118/49, 64/49, -4/49), center=1),
81 ) 83 )
82 84
83 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(4,2,3,1)) == ( 85 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(4,2,3,1)) == (
84 SbpOperators.Stencil(( 2., -5., 4., -1., 0., 0.), center=4), 86 Stencil(( 2., -5., 4., -1., 0., 0.), center=4),
85 SbpOperators.Stencil(( 1., -2., 1., 0., 0., 0.), center=2), 87 Stencil(( 1., -2., 1., 0., 0., 0.), center=2),
86 SbpOperators.Stencil(( -4/43, 59/43, -110/43, 59/43, -4/43, 0.), center=3), 88 Stencil(( -4/43, 59/43, -110/43, 59/43, -4/43, 0.), center=3),
87 SbpOperators.Stencil(( -1/49, 0., 59/49, -118/49, 64/49, -4/49), center=1), 89 Stencil(( -1/49, 0., 59/49, -118/49, 64/49, -4/49), center=1),
88 ) 90 )
89 91
90 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=1:4) == ( 92 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=1:4) == (
91 SbpOperators.Stencil(( 2., -5., 4., -1., 0., 0.), center=1), 93 Stencil(( 2., -5., 4., -1., 0., 0.), center=1),
92 SbpOperators.Stencil(( 1., -2., 1., 0., 0., 0.), center=2), 94 Stencil(( 1., -2., 1., 0., 0., 0.), center=2),
93 SbpOperators.Stencil(( -4/43, 59/43, -110/43, 59/43, -4/43, 0.), center=3), 95 Stencil(( -4/43, 59/43, -110/43, 59/43, -4/43, 0.), center=3),
94 SbpOperators.Stencil(( -1/49, 0., 59/49, -118/49, 64/49, -4/49), center=4), 96 Stencil(( -1/49, 0., 59/49, -118/49, 64/49, -4/49), center=4),
95 ) 97 )
96 98
97 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(1,2,3)) 99 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(1,2,3))
98 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(1,2,3,5,4)) 100 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(1,2,3,5,4))
99 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "inner_stencil",centers=(1,2)) 101 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "inner_stencil",centers=(1,2))