Mercurial > repos > public > sbplib_julia
comparison test/SbpOperators/readoperator_test.jl @ 832:00f6bbdcd73a operator_storage_array_of_table
Review: Include latest changes
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 12 Jan 2022 15:54:21 +0100 |
parents | 760c11e81fd4 |
children | 06c510d40ebb |
comparison
equal
deleted
inserted
replaced
813:cdc2b5ebf7cb | 832:00f6bbdcd73a |
---|---|
2 | 2 |
3 using TOML | 3 using TOML |
4 using Sbplib.SbpOperators | 4 using Sbplib.SbpOperators |
5 | 5 |
6 import Sbplib.SbpOperators.Stencil | 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 | 7 |
18 @testset "readoperator" begin | 8 @testset "readoperator" begin |
19 toml_str = """ | 9 toml_str = """ |
20 [meta] | 10 [meta] |
21 authors = "Ken Mattson" | 11 authors = "Ken Mattson" |
109 Stencil( 2//1, -5//1, 4//1, -1//1, 0//1, 0//1; center=1), | 99 Stencil( 2//1, -5//1, 4//1, -1//1, 0//1, 0//1; center=1), |
110 Stencil( 1//1, -2//1, 1//1, 0//1, 0//1, 0//1; center=2), | 100 Stencil( 1//1, -2//1, 1//1, 0//1, 0//1, 0//1; center=2), |
111 Stencil(-4//43, 59//43, -110//43, 59//43, -4//43, 0//1; center=3), | 101 Stencil(-4//43, 59//43, -110//43, 59//43, -4//43, 0//1; center=3), |
112 Stencil(-1//49, 0//1, 59//49, -118//49, 64//49, -4//49; center=4), | 102 Stencil(-1//49, 0//1, 59//49, -118//49, 64//49, -4//49; center=4), |
113 ] | 103 ] |
104 | |
105 | |
106 @test parse_stencil(Float64, TOML.parse(toml)["s1"]) == CenteredStencil(-1/12, 4/3, -5/2, 4/3, -1/12) | |
107 @test parse_stencil(Float64, TOML.parse(toml)["s2"]) == Stencil(2/1, -5/1, 4/1, -1/1, 0/1, 0/1; center=1) | |
108 @test parse_stencil(Float64, TOML.parse(toml)["s3"]) == Stencil(1/1, -2/1, 1/1, 0/1, 0/1, 0/1; center=2) | |
109 end | |
110 | |
111 @testset "parse_scalar" begin | |
112 toml = TOML.parse(""" | |
113 a1 = 1 | |
114 a2 = 1.5 | |
115 a3 = 1.0 | |
116 a4 = 10 | |
117 a5 = "1/2" | |
118 a6 = "1.5" | |
119 | |
120 e1 = [1,2,3] | |
121 e2 = "a string value" | |
122 """) | |
123 | |
124 @test parse_scalar(toml["a1"]) == 1//1 | |
125 @test parse_scalar(toml["a2"]) == 3//2 | |
126 @test parse_scalar(toml["a3"]) == 1//1 | |
127 @test parse_scalar(toml["a4"]) == 10//1 | |
128 @test parse_scalar(toml["a5"]) == 1//2 | |
129 @test parse_scalar(toml["a6"]) == 3//2 | |
130 | |
131 @test_throws ArgumentError parse_scalar(toml["e1"]) | |
132 @test_throws ArgumentError parse_scalar(toml["e2"]) | |
133 end | |
134 | |
135 @testset "parse_tuple" begin | |
136 toml = TOML.parse(""" | |
137 t1 = [1,3,4] | |
138 t2 = ["1/2","3/4","2/1"] | |
139 | |
140 e1 = "not a tuple" | |
141 e2.a="1" | |
142 e3 = 1 | |
143 e4 = ["1/2","3/4","not a number"] | |
144 """) | |
145 | |
146 @test parse_tuple(toml["t1"]) == (1//1,3//1,4//1) | |
147 @test parse_tuple(toml["t2"]) == (1//2,3//4,2//1) | |
148 | |
149 @test_throws ArgumentError parse_tuple(toml["e1"]) | |
150 @test_throws ArgumentError parse_tuple(toml["e2"]) | |
151 @test_throws ArgumentError parse_tuple(toml["e3"]) | |
152 @test_throws ArgumentError parse_tuple(toml["e4"]) | |
114 end | 153 end |
115 end | 154 end |
155 | |
156 @testset "parse_rational" begin | |
157 @test SbpOperators.parse_rational("1") isa Rational | |
158 @test SbpOperators.parse_rational("1") == 1//1 | |
159 @test SbpOperators.parse_rational("1/2") isa Rational | |
160 @test SbpOperators.parse_rational("1/2") == 1//2 | |
161 @test SbpOperators.parse_rational("37/13") isa Rational | |
162 @test SbpOperators.parse_rational("37/13") == 37//13 | |
163 | |
164 @test SbpOperators.parse_rational(0.5) isa Rational | |
165 @test SbpOperators.parse_rational(0.5) == 1//2 | |
166 | |
167 @test SbpOperators.parse_rational("0.5") isa Rational | |
168 @test SbpOperators.parse_rational("0.5") == 1//2 | |
169 | |
170 @test SbpOperators.parse_rational(2) isa Rational | |
171 @test SbpOperators.parse_rational(2) == 2//1 | |
172 end |