comparison test/SbpOperators/readoperator_test.jl @ 746:ddb52db10f37 feature/static_dict

Merge in default
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 19 Mar 2021 13:41:25 +0100
parents 6114274447f5
children 0158c3fd521c
comparison
equal deleted inserted replaced
742:6377a5fba0a1 746:ddb52db10f37
1 using Test
2
3 using TOML
4 using Sbplib.SbpOperators
5
6 import Sbplib.SbpOperators.Stencil
7
8
9 @testset "parse_rational" begin
10 @test SbpOperators.parse_rational("1") isa Rational
11 @test SbpOperators.parse_rational("1") == 1//1
12 @test SbpOperators.parse_rational("1/2") isa Rational
13 @test SbpOperators.parse_rational("1/2") == 1//2
14 @test SbpOperators.parse_rational("37/13") isa Rational
15 @test SbpOperators.parse_rational("37/13") == 37//13
16 end
17
18 @testset "readoperator" begin
19 toml_str = """
20 [meta]
21 type = "equidistant"
22
23 [order2]
24 H.inner = ["1"]
25
26 D1.inner_stencil = ["-1/2", "0", "1/2"]
27 D1.closure_stencils = [
28 ["-1", "1"],
29 ]
30
31 d1.closure = ["-3/2", "2", "-1/2"]
32
33 [order4]
34 H.closure = ["17/48", "59/48", "43/48", "49/48"]
35
36 D2.inner_stencil = ["-1/12","4/3","-5/2","4/3","-1/12"]
37 D2.closure_stencils = [
38 [ "2", "-5", "4", "-1", "0", "0"],
39 [ "1", "-2", "1", "0", "0", "0"],
40 [ "-4/43", "59/43", "-110/43", "59/43", "-4/43", "0"],
41 [ "-1/49", "0", "59/49", "-118/49", "64/49", "-4/49"],
42 ]
43 """
44
45 parsed_toml = TOML.parse(toml_str)
46 @testset "get_stencil" begin
47 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil") == Stencil(-1/2, 0., 1/2, center=2)
48 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil", center=1) == Stencil(-1/2, 0., 1/2; center=1)
49 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil", center=3) == Stencil(-1/2, 0., 1/2; center=3)
50
51 @test get_stencil(parsed_toml, "order2", "H", "inner") == Stencil(1.; center=1)
52
53 @test_throws AssertionError get_stencil(parsed_toml, "meta", "type")
54 @test_throws AssertionError get_stencil(parsed_toml, "order2", "D1", "closure_stencils")
55 end
56
57 @testset "get_stencils" begin
58 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=(1,)) == (Stencil(-1., 1., center=1),)
59 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=(2,)) == (Stencil(-1., 1., center=2),)
60 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=[2]) == (Stencil(-1., 1., center=2),)
61
62 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=[1,1,1,1]) == (
63 Stencil( 2., -5., 4., -1., 0., 0., center=1),
64 Stencil( 1., -2., 1., 0., 0., 0., center=1),
65 Stencil( -4/43, 59/43, -110/43, 59/43, -4/43, 0., center=1),
66 Stencil( -1/49, 0., 59/49, -118/49, 64/49, -4/49, center=1),
67 )
68
69 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(4,2,3,1)) == (
70 Stencil( 2., -5., 4., -1., 0., 0., center=4),
71 Stencil( 1., -2., 1., 0., 0., 0., center=2),
72 Stencil( -4/43, 59/43, -110/43, 59/43, -4/43, 0., center=3),
73 Stencil( -1/49, 0., 59/49, -118/49, 64/49, -4/49, center=1),
74 )
75
76 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=1:4) == (
77 Stencil( 2., -5., 4., -1., 0., 0., center=1),
78 Stencil( 1., -2., 1., 0., 0., 0., center=2),
79 Stencil( -4/43, 59/43, -110/43, 59/43, -4/43, 0., center=3),
80 Stencil( -1/49, 0., 59/49, -118/49, 64/49, -4/49, center=4),
81 )
82
83 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(1,2,3))
84 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(1,2,3,5,4))
85 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "inner_stencil",centers=(1,2))
86 end
87
88 @testset "get_tuple" begin
89 @test get_tuple(parsed_toml, "order2", "d1", "closure") == (-3/2, 2, -1/2)
90
91 @test_throws AssertionError get_tuple(parsed_toml, "meta", "type")
92 end
93 end