annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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)
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) # TODO: Remove if we allow side lengths to be negative.
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 # TODO: Include below if we allow side lengths to be negative.
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 #@test [spacing(EquidistantGrid((5,3), (0.0,1.0), (-1.0,-2.0)))...] ≈ [(0.25, 1.5)...] 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
28
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 # 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
30 @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
31 @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
32 # TODO: Include below if we allow side lengths to be negative.
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 #@test [inverse_spacing(EquidistantGrid((5,3), (0.0,1.0), (-1.0,-2.0)))...] ≈ [(4., 2. /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
34
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 # 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
36 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
37 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
38 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
39 (-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
40 (-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
41 (-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
42 (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
43 approxequal = true;
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 for i ∈ eachindex(gp)
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
45 approxequal=approxequal*all(isapprox.(gp[i],p[i], 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
46 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
47 @test approxequal == true
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
48
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
49
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
50 # restrict
353
8257cc75ea6b Add doc string and allow picking several dimensions
Jonatan Werpers <jonatan@werpers.com>
parents: 352
diff changeset
51 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
52 @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
53 @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
54
353
8257cc75ea6b Add doc string and allow picking several dimensions
Jonatan Werpers <jonatan@werpers.com>
parents: 352
diff changeset
55 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
56 @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
57 @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
58 @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
59 @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
60 @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
61 @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
62 @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
63 end
338
2b0c9b30ea3b Add test sets for each submodule to make the test output nicer
Jonatan Werpers <jonatan@werpers.com>
parents: 335
diff changeset
64
2b0c9b30ea3b Add test sets for each submodule to make the test output nicer
Jonatan Werpers <jonatan@werpers.com>
parents: 335
diff changeset
65 end