Mercurial > repos > public > sbplib_julia
annotate test/testGrids.jl @ 660:b21fea54ca10 feature/get_boundary_identifiers
Add tests for Grids.boundary_identifiers
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Sat, 30 Jan 2021 20:30:55 +0100 |
parents | b7734413003d |
children | f0ceddeae993 |
rev | line source |
---|---|
335
f4e3e71a4ff4
Fix `using` commands to refer to local modules within the Sbplib package/module
Jonatan Werpers <jonatan@werpers.com>
parents:
333
diff
changeset
|
1 using Sbplib.Grids |
213
0bf761485f40
Add test stub to package Grids
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
2 using Test |
660
b21fea54ca10
Add tests for Grids.boundary_identifiers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
407
diff
changeset
|
3 using Sbplib.RegionIndices |
213
0bf761485f40
Add test stub to package Grids
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
4 |
338
2b0c9b30ea3b
Add test sets for each submodule to make the test output nicer
Jonatan Werpers <jonatan@werpers.com>
parents:
335
diff
changeset
|
5 @testset "Grids" begin |
2b0c9b30ea3b
Add test sets for each submodule to make the test output nicer
Jonatan Werpers <jonatan@werpers.com>
parents:
335
diff
changeset
|
6 |
324
047dee8efaef
Grids.EquidistantGrid: Add constructor for 1d grid
Jonatan Werpers <jonatan@werpers.com>
parents:
217
diff
changeset
|
7 @testset "EquidistantGrid" begin |
353
8257cc75ea6b
Add doc string and allow picking several dimensions
Jonatan Werpers <jonatan@werpers.com>
parents:
352
diff
changeset
|
8 @test EquidistantGrid(4,0.0,1.0) isa EquidistantGrid |
8257cc75ea6b
Add doc string and allow picking several dimensions
Jonatan Werpers <jonatan@werpers.com>
parents:
352
diff
changeset
|
9 @test EquidistantGrid(4,0.0,8.0) isa EquidistantGrid |
405
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
10 # constuctor |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
11 @test_throws DomainError EquidistantGrid(0,0.0,1.0) |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
12 @test_throws DomainError EquidistantGrid(1,1.0,1.0) |
406
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
13 @test_throws DomainError EquidistantGrid(1,1.0,-1.0) |
353
8257cc75ea6b
Add doc string and allow picking several dimensions
Jonatan Werpers <jonatan@werpers.com>
parents:
352
diff
changeset
|
14 @test EquidistantGrid(4,0.0,1.0) == EquidistantGrid((4,),(0.0,),(1.0,)) |
8257cc75ea6b
Add doc string and allow picking several dimensions
Jonatan Werpers <jonatan@werpers.com>
parents:
352
diff
changeset
|
15 |
405
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
16 # size |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
17 @test size(EquidistantGrid(4,0.0,1.0)) == (4,) |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
18 @test size(EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))) == (5,3) |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
19 |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
20 # dimension |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
21 @test dimension(EquidistantGrid(4,0.0,1.0)) == 1 |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
22 @test dimension(EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))) == 2 |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
23 |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
24 # spacing |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
25 @test [spacing(EquidistantGrid(4,0.0,1.0))...] ≈ [(1. /3,)...] atol=5e-13 |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
26 @test [spacing(EquidistantGrid((5,3), (0.0,-1.0), (2.0,1.0)))...] ≈ [(0.5, 1.)...] atol=5e-13 |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
27 |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
28 # inverse_spacing |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
29 @test [inverse_spacing(EquidistantGrid(4,0.0,1.0))...] ≈ [(3.,)...] atol=5e-13 |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
30 @test [inverse_spacing(EquidistantGrid((5,3), (0.0,-1.0), (2.0,1.0)))...] ≈ [(2, 1.)...] atol=5e-13 |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
31 |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
32 # points |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
33 g = EquidistantGrid((5,3), (-1.0,0.0), (0.0,7.11)) |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
34 gp = points(g); |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
35 p = [(-1.,0.) (-1.,7.11/2) (-1.,7.11); |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
36 (-0.75,0.) (-0.75,7.11/2) (-0.75,7.11); |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
37 (-0.5,0.) (-0.5,7.11/2) (-0.5,7.11); |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
38 (-0.25,0.) (-0.25,7.11/2) (-0.25,7.11); |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
39 (0.,0.) (0.,7.11/2) (0.,7.11)] |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
40 for i ∈ eachindex(gp) |
407
b7734413003d
Simplify test
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
406
diff
changeset
|
41 @test [gp[i]...] ≈ [p[i]...] atol=5e-13 |
405
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
42 end |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
43 |
16dc5b19843d
Fix exception handling in constructor of EquidistantGrid and add a bunch of tests
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
358
diff
changeset
|
44 # restrict |
353
8257cc75ea6b
Add doc string and allow picking several dimensions
Jonatan Werpers <jonatan@werpers.com>
parents:
352
diff
changeset
|
45 g = EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0)) |
358
64ad8ec0eae0
Change name from subgrid to restrict
Jonatan Werpers <jonatan@werpers.com>
parents:
353
diff
changeset
|
46 @test restrict(g, 1) == EquidistantGrid(5,0.0,2.0) |
64ad8ec0eae0
Change name from subgrid to restrict
Jonatan Werpers <jonatan@werpers.com>
parents:
353
diff
changeset
|
47 @test restrict(g, 2) == EquidistantGrid(3,0.0,1.0) |
352
a18bd337a280
Add function for getting a one dimensional grid for a given dimension from a equidistant grid
Jonatan Werpers <jonatan@werpers.com>
parents:
338
diff
changeset
|
48 |
353
8257cc75ea6b
Add doc string and allow picking several dimensions
Jonatan Werpers <jonatan@werpers.com>
parents:
352
diff
changeset
|
49 g = EquidistantGrid((2,5,3), (0.0,0.0,0.0), (2.0,1.0,3.0)) |
358
64ad8ec0eae0
Change name from subgrid to restrict
Jonatan Werpers <jonatan@werpers.com>
parents:
353
diff
changeset
|
50 @test restrict(g, 1) == EquidistantGrid(2,0.0,2.0) |
64ad8ec0eae0
Change name from subgrid to restrict
Jonatan Werpers <jonatan@werpers.com>
parents:
353
diff
changeset
|
51 @test restrict(g, 2) == EquidistantGrid(5,0.0,1.0) |
64ad8ec0eae0
Change name from subgrid to restrict
Jonatan Werpers <jonatan@werpers.com>
parents:
353
diff
changeset
|
52 @test restrict(g, 3) == EquidistantGrid(3,0.0,3.0) |
64ad8ec0eae0
Change name from subgrid to restrict
Jonatan Werpers <jonatan@werpers.com>
parents:
353
diff
changeset
|
53 @test restrict(g, 1:2) == EquidistantGrid((2,5),(0.0,0.0),(2.0,1.0)) |
64ad8ec0eae0
Change name from subgrid to restrict
Jonatan Werpers <jonatan@werpers.com>
parents:
353
diff
changeset
|
54 @test restrict(g, 2:3) == EquidistantGrid((5,3),(0.0,0.0),(1.0,3.0)) |
64ad8ec0eae0
Change name from subgrid to restrict
Jonatan Werpers <jonatan@werpers.com>
parents:
353
diff
changeset
|
55 @test restrict(g, [1,3]) == EquidistantGrid((2,3),(0.0,0.0),(2.0,3.0)) |
64ad8ec0eae0
Change name from subgrid to restrict
Jonatan Werpers <jonatan@werpers.com>
parents:
353
diff
changeset
|
56 @test restrict(g, [2,1]) == EquidistantGrid((5,2),(0.0,0.0),(1.0,2.0)) |
660
b21fea54ca10
Add tests for Grids.boundary_identifiers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
407
diff
changeset
|
57 |
b21fea54ca10
Add tests for Grids.boundary_identifiers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
407
diff
changeset
|
58 @testset "boundary_identifiers" begin |
b21fea54ca10
Add tests for Grids.boundary_identifiers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
407
diff
changeset
|
59 g = EquidistantGrid((2,5,3), (0.0,0.0,0.0), (2.0,1.0,3.0)) |
b21fea54ca10
Add tests for Grids.boundary_identifiers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
407
diff
changeset
|
60 @test boundary_identifiers(g) == (CartesianBoundary{1,Lower}(),CartesianBoundary{1,Upper}(), |
b21fea54ca10
Add tests for Grids.boundary_identifiers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
407
diff
changeset
|
61 CartesianBoundary{2,Lower}(),CartesianBoundary{2,Upper}(), |
b21fea54ca10
Add tests for Grids.boundary_identifiers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
407
diff
changeset
|
62 CartesianBoundary{3,Lower}(),CartesianBoundary{3,Upper}()) |
b21fea54ca10
Add tests for Grids.boundary_identifiers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
407
diff
changeset
|
63 end |
324
047dee8efaef
Grids.EquidistantGrid: Add constructor for 1d grid
Jonatan Werpers <jonatan@werpers.com>
parents:
217
diff
changeset
|
64 end |
338
2b0c9b30ea3b
Add test sets for each submodule to make the test output nicer
Jonatan Werpers <jonatan@werpers.com>
parents:
335
diff
changeset
|
65 |
2b0c9b30ea3b
Add test sets for each submodule to make the test output nicer
Jonatan Werpers <jonatan@werpers.com>
parents:
335
diff
changeset
|
66 end |