comparison test/Grids/Grids_test.jl @ 711:df88aee35bb9 feature/selectable_tests

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