Mercurial > repos > public > sbplib_julia
annotate test/testGrids.jl @ 499:7b550c714f3f feature/outer_product
Remove resolved TBD
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 05 Nov 2020 15:27:33 +0100 |
parents | b7734413003d |
children | b21fea54ca10 |
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 |
0bf761485f40
Add test stub to package Grids
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
3 |
338
2b0c9b30ea3b
Add test sets for each submodule to make the test output nicer
Jonatan Werpers <jonatan@werpers.com>
parents:
335
diff
changeset
|
4 @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
|
5 |
324
047dee8efaef
Grids.EquidistantGrid: Add constructor for 1d grid
Jonatan Werpers <jonatan@werpers.com>
parents:
217
diff
changeset
|
6 @testset "EquidistantGrid" begin |
353
8257cc75ea6b
Add doc string and allow picking several dimensions
Jonatan Werpers <jonatan@werpers.com>
parents:
352
diff
changeset
|
7 @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
|
8 @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
|
9 # 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
|
10 @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
|
11 @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
|
12 @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
|
13 @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
|
14 |
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
|
15 # 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
|
16 @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
|
17 @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
|
18 |
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 # 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
|
20 @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
|
21 @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
|
22 |
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 # 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
|
24 @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
|
25 @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
|
26 |
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 # 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
|
28 @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
|
29 @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
|
30 |
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 # 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
|
32 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
|
33 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
|
34 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
|
35 (-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
|
36 (-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
|
37 (-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
|
38 (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
|
39 for i ∈ eachindex(gp) |
407
b7734413003d
Simplify test
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
406
diff
changeset
|
40 @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
|
41 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
|
42 |
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 # restrict |
353
8257cc75ea6b
Add doc string and allow picking several dimensions
Jonatan Werpers <jonatan@werpers.com>
parents:
352
diff
changeset
|
44 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
|
45 @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
|
46 @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
|
47 |
353
8257cc75ea6b
Add doc string and allow picking several dimensions
Jonatan Werpers <jonatan@werpers.com>
parents:
352
diff
changeset
|
48 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
|
49 @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
|
50 @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
|
51 @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
|
52 @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
|
53 @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
|
54 @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
|
55 @test restrict(g, [2,1]) == EquidistantGrid((5,2),(0.0,0.0),(1.0,2.0)) |
324
047dee8efaef
Grids.EquidistantGrid: Add constructor for 1d grid
Jonatan Werpers <jonatan@werpers.com>
parents:
217
diff
changeset
|
56 end |
338
2b0c9b30ea3b
Add test sets for each submodule to make the test output nicer
Jonatan Werpers <jonatan@werpers.com>
parents:
335
diff
changeset
|
57 |
2b0c9b30ea3b
Add test sets for each submodule to make the test output nicer
Jonatan Werpers <jonatan@werpers.com>
parents:
335
diff
changeset
|
58 end |