comparison test/testGrids.jl @ 405:16dc5b19843d test/equidistantgrid

Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Sat, 10 Oct 2020 20:05:39 +0200
parents 64ad8ec0eae0
children c377fc37c04b
comparison
equal deleted inserted replaced
402:1936e38fe51e 405:16dc5b19843d
4 @testset "Grids" begin 4 @testset "Grids" begin
5 5
6 @testset "EquidistantGrid" begin 6 @testset "EquidistantGrid" begin
7 @test EquidistantGrid(4,0.0,1.0) isa EquidistantGrid 7 @test EquidistantGrid(4,0.0,1.0) isa EquidistantGrid
8 @test EquidistantGrid(4,0.0,8.0) isa EquidistantGrid 8 @test EquidistantGrid(4,0.0,8.0) isa EquidistantGrid
9 @test dimension(EquidistantGrid(4,0.0,1.0)) == 1 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) # TODO: Remove if we allow side lengths to be negative.
10 @test EquidistantGrid(4,0.0,1.0) == EquidistantGrid((4,),(0.0,),(1.0,)) 13 @test EquidistantGrid(4,0.0,1.0) == EquidistantGrid((4,),(0.0,),(1.0,))
11 14
15 # size
16 @test size(EquidistantGrid(4,0.0,1.0)) == (4,)
17 @test size(EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))) == (5,3)
18
19 # dimension
20 @test dimension(EquidistantGrid(4,0.0,1.0)) == 1
21 @test dimension(EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))) == 2
22
23 # spacing
24 @test [spacing(EquidistantGrid(4,0.0,1.0))...] ≈ [(1. /3,)...] atol=5e-13
25 @test [spacing(EquidistantGrid((5,3), (0.0,-1.0), (2.0,1.0)))...] ≈ [(0.5, 1.)...] atol=5e-13
26 # TODO: Include below if we allow side lengths to be negative.
27 #@test [spacing(EquidistantGrid((5,3), (0.0,1.0), (-1.0,-2.0)))...] ≈ [(0.25, 1.5)...] atol=5e-13
28
29 # inverse_spacing
30 @test [inverse_spacing(EquidistantGrid(4,0.0,1.0))...] ≈ [(3.,)...] atol=5e-13
31 @test [inverse_spacing(EquidistantGrid((5,3), (0.0,-1.0), (2.0,1.0)))...] ≈ [(2, 1.)...] atol=5e-13
32 # TODO: Include below if we allow side lengths to be negative.
33 #@test [inverse_spacing(EquidistantGrid((5,3), (0.0,1.0), (-1.0,-2.0)))...] ≈ [(4., 2. /3)...] 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 approxequal = true;
44 for i ∈ eachindex(gp)
45 approxequal=approxequal*all(isapprox.(gp[i],p[i], atol=5e-13));
46 end
47 @test approxequal == true
48
49
50 # restrict
12 g = EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0)) 51 g = EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))
13 @test restrict(g, 1) == EquidistantGrid(5,0.0,2.0) 52 @test restrict(g, 1) == EquidistantGrid(5,0.0,2.0)
14 @test restrict(g, 2) == EquidistantGrid(3,0.0,1.0) 53 @test restrict(g, 2) == EquidistantGrid(3,0.0,1.0)
15 54
16 g = EquidistantGrid((2,5,3), (0.0,0.0,0.0), (2.0,1.0,3.0)) 55 g = EquidistantGrid((2,5,3), (0.0,0.0,0.0), (2.0,1.0,3.0))