Mercurial > repos > public > sbplib_julia
comparison test/Grids/EquidistantGrid_test.jl @ 716:3e64e102e161 feature/selectable_tests
Rename Grids_test.jl to EquidistantGrid_test.jl
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Sat, 20 Feb 2021 21:19:24 +0100 |
| parents | test/Grids/Grids_test.jl@11a444d6fc93 |
| children | dd2ab001a7b6 |
comparison
equal
deleted
inserted
replaced
| 715:6aa7677b5129 | 716:3e64e102e161 |
|---|---|
| 1 using Sbplib.Grids | |
| 2 using Test | |
| 3 using Sbplib.RegionIndices | |
| 4 | |
| 5 | |
| 6 @testset "EquidistantGrid" begin | |
| 7 @test EquidistantGrid(4,0.0,1.0) isa EquidistantGrid | |
| 8 @test EquidistantGrid(4,0.0,8.0) isa EquidistantGrid | |
| 9 # constuctor | |
| 10 @test_throws DomainError EquidistantGrid(0,0.0,1.0) | |
| 11 @test_throws DomainError EquidistantGrid(1,1.0,1.0) | |
| 12 @test_throws DomainError EquidistantGrid(1,1.0,-1.0) | |
| 13 @test EquidistantGrid(4,0.0,1.0) == EquidistantGrid((4,),(0.0,),(1.0,)) | |
| 14 | |
| 15 @testset "Base" begin | |
| 16 @test eltype(EquidistantGrid(4,0.0,1.0)) == Float64 | |
| 17 @test eltype(EquidistantGrid((4,3),(0,0),(1,3))) == Int | |
| 18 @test size(EquidistantGrid(4,0.0,1.0)) == (4,) | |
| 19 @test size(EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))) == (5,3) | |
| 20 end | |
| 21 | |
| 22 # dimension | |
| 23 @test dimension(EquidistantGrid(4,0.0,1.0)) == 1 | |
| 24 @test dimension(EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))) == 2 | |
| 25 | |
| 26 # spacing | |
| 27 @test [spacing(EquidistantGrid(4,0.0,1.0))...] ≈ [(1. /3,)...] atol=5e-13 | |
| 28 @test [spacing(EquidistantGrid((5,3), (0.0,-1.0), (2.0,1.0)))...] ≈ [(0.5, 1.)...] atol=5e-13 | |
| 29 | |
| 30 # inverse_spacing | |
| 31 @test [inverse_spacing(EquidistantGrid(4,0.0,1.0))...] ≈ [(3.,)...] atol=5e-13 | |
| 32 @test [inverse_spacing(EquidistantGrid((5,3), (0.0,-1.0), (2.0,1.0)))...] ≈ [(2, 1.)...] atol=5e-13 | |
| 33 | |
| 34 # points | |
| 35 g = EquidistantGrid((5,3), (-1.0,0.0), (0.0,7.11)) | |
| 36 gp = points(g); | |
| 37 p = [(-1.,0.) (-1.,7.11/2) (-1.,7.11); | |
| 38 (-0.75,0.) (-0.75,7.11/2) (-0.75,7.11); | |
| 39 (-0.5,0.) (-0.5,7.11/2) (-0.5,7.11); | |
| 40 (-0.25,0.) (-0.25,7.11/2) (-0.25,7.11); | |
| 41 (0.,0.) (0.,7.11/2) (0.,7.11)] | |
| 42 for i ∈ eachindex(gp) | |
| 43 @test [gp[i]...] ≈ [p[i]...] atol=5e-13 | |
| 44 end | |
| 45 | |
| 46 # restrict | |
| 47 g = EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0)) | |
| 48 @test restrict(g, 1) == EquidistantGrid(5,0.0,2.0) | |
| 49 @test restrict(g, 2) == EquidistantGrid(3,0.0,1.0) | |
| 50 | |
| 51 g = EquidistantGrid((2,5,3), (0.0,0.0,0.0), (2.0,1.0,3.0)) | |
| 52 @test restrict(g, 1) == EquidistantGrid(2,0.0,2.0) | |
| 53 @test restrict(g, 2) == EquidistantGrid(5,0.0,1.0) | |
| 54 @test restrict(g, 3) == EquidistantGrid(3,0.0,3.0) | |
| 55 @test restrict(g, 1:2) == EquidistantGrid((2,5),(0.0,0.0),(2.0,1.0)) | |
| 56 @test restrict(g, 2:3) == EquidistantGrid((5,3),(0.0,0.0),(1.0,3.0)) | |
| 57 @test restrict(g, [1,3]) == EquidistantGrid((2,3),(0.0,0.0),(2.0,3.0)) | |
| 58 @test restrict(g, [2,1]) == EquidistantGrid((5,2),(0.0,0.0),(1.0,2.0)) | |
| 59 | |
| 60 @testset "boundary_identifiers" begin | |
| 61 g = EquidistantGrid((2,5,3), (0.0,0.0,0.0), (2.0,1.0,3.0)) | |
| 62 bids = (CartesianBoundary{1,Lower}(),CartesianBoundary{1,Upper}(), | |
| 63 CartesianBoundary{2,Lower}(),CartesianBoundary{2,Upper}(), | |
| 64 CartesianBoundary{3,Lower}(),CartesianBoundary{3,Upper}()) | |
| 65 @test boundary_identifiers(g) == bids | |
| 66 @inferred boundary_identifiers(g) | |
| 67 end | |
| 68 | |
| 69 @testset "boundary_grid" begin | |
| 70 @testset "1D" begin | |
| 71 g = EquidistantGrid(5,0.0,2.0) | |
| 72 (id_l, id_r) = boundary_identifiers(g) | |
| 73 @test boundary_grid(g,id_l) == EquidistantGrid{Float64}() | |
| 74 @test boundary_grid(g,id_r) == EquidistantGrid{Float64}() | |
| 75 @test_throws DomainError boundary_grid(g,CartesianBoundary{2,Lower}()) | |
| 76 @test_throws DomainError boundary_grid(g,CartesianBoundary{0,Lower}()) | |
| 77 end | |
| 78 @testset "2D" begin | |
| 79 g = EquidistantGrid((5,3),(0.0,0.0),(1.0,3.0)) | |
| 80 (id_w, id_e, id_s, id_n) = boundary_identifiers(g) | |
| 81 @test boundary_grid(g,id_w) == restrict(g,2) | |
| 82 @test boundary_grid(g,id_e) == restrict(g,2) | |
| 83 @test boundary_grid(g,id_s) == restrict(g,1) | |
| 84 @test boundary_grid(g,id_n) == restrict(g,1) | |
| 85 @test_throws DomainError boundary_grid(g,CartesianBoundary{4,Lower}()) | |
| 86 end | |
| 87 @testset "3D" begin | |
| 88 g = EquidistantGrid((2,5,3), (0.0,0.0,0.0), (2.0,1.0,3.0)) | |
| 89 (id_w, id_e, | |
| 90 id_s, id_n, | |
| 91 id_t, id_b) = boundary_identifiers(g) | |
| 92 @test boundary_grid(g,id_w) == restrict(g,[2,3]) | |
| 93 @test boundary_grid(g,id_e) == restrict(g,[2,3]) | |
| 94 @test boundary_grid(g,id_s) == restrict(g,[1,3]) | |
| 95 @test boundary_grid(g,id_n) == restrict(g,[1,3]) | |
| 96 @test boundary_grid(g,id_t) == restrict(g,[1,2]) | |
| 97 @test boundary_grid(g,id_b) == restrict(g,[1,2]) | |
| 98 @test_throws DomainError boundary_grid(g,CartesianBoundary{4,Lower}()) | |
| 99 end | |
| 100 end | |
| 101 end |
