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