annotate test/Grids/curvilinear_grid_test.jl @ 1430:9fc3c1af33e5 feature/grids/curvilinear

Add testsets and a few tests
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 26 Jul 2023 21:00:44 +0200
parents 9c689a627244
children 6adf31ba6cfd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1426
9c689a627244 Add src and test file for curvilinear grid type
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
1 using Sbplib.Grids
9c689a627244 Add src and test file for curvilinear grid type
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
2 using Test
1430
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
3 using StaticArrays
1426
9c689a627244 Add src and test file for curvilinear grid type
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
4
9c689a627244 Add src and test file for curvilinear grid type
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
5 @testset "CurvilinearGrid" begin
1430
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
6 g = equidistant_grid((10,10), (0,0), (1,1))
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
7 x̄ = map(ξ̄ -> 2ξ̄, g)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
8 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), g)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
9
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
10 @test CurvilinearGrid(g, x̄, J) isa Grid{SVector{2, Float64},2}
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
11
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
12
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
13 @test_broken jacobian(cg) isa Array{<:AbstractVector}
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
14 @test_broken logicalgrid(cg) isa Grid
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
15
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
16
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
17
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
18 @testset "Indexing Interface" begin
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
19 # cg = CurvilinearGrid(g, x̄, J)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
20 # @test cg[1,1] == [0.0, 0.0]
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
21 # @test cg[4,2] == [3/9,1/9]
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
22 # @test cg[6,10] == [5/9, 1]
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
23
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
24 # @test cg[begin, begin] == [0.0, 0.0]
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
25 # @test cg[end,end] == [1.0, 1.0]
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
26 # @test cg[begin,end] == [0., 1.]
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
27
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
28 # @test eachindex(cg) == 1:101
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
29 end
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
30
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
31 @testset "Iterator interface" begin
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
32 # @test eltype(EquidistantGrid(0:10)) == Int
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
33 # @test eltype(EquidistantGrid(0:2:10)) == Int
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
34 # @test eltype(EquidistantGrid(0:0.1:10)) == Float64
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
35
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
36 # @test size(EquidistantGrid(0:10)) == (11,)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
37 # @test size(EquidistantGrid(0:0.1:10)) == (101,)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
38
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
39 # @test collect(EquidistantGrid(0:0.1:0.5)) == [0.0, 0.1, 0.2, 0.3, 0.4, 0.5]
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
40
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
41 # @test Base.IteratorSize(EquidistantGrid{Float64, StepRange{Float64}}) == Base.HasShape{1}()
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
42 end
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
43
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
44 @testset "Base" begin
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
45 # @test ndims(EquidistantGrid(0:10)) == 1
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
46 end
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
47
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
48 @testset "boundary_identifiers" begin
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
49 # g = EquidistantGrid(0:0.1:10)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
50 # @test boundary_identifiers(g) == (Lower(), Upper())
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
51 # @inferred boundary_identifiers(g)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
52 end
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
53
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
54 @testset "boundary_grid" begin
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
55 # g = EquidistantGrid(0:0.1:1)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
56 # @test boundary_grid(g, Lower()) == ZeroDimGrid(0.0)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
57 # @test boundary_grid(g, Upper()) == ZeroDimGrid(1.0)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
58 end
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
59
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
60 @testset "refine" begin
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
61 # g = EquidistantGrid(0:0.1:1)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
62 # @test refine(g, 1) == g
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
63 # @test refine(g, 2) == EquidistantGrid(0:0.05:1)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
64 # @test refine(g, 3) == EquidistantGrid(0:(0.1/3):1)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
65 end
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
66
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
67 @testset "coarsen" begin
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
68 # g = EquidistantGrid(0:1:10)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
69 # @test coarsen(g, 1) == g
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
70 # @test coarsen(g, 2) == EquidistantGrid(0:2:10)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
71
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
72 # g = EquidistantGrid(0:0.1:1)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
73 # @test coarsen(g, 1) == g
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
74 # @test coarsen(g, 2) == EquidistantGrid(0:0.2:1)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
75
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
76 # g = EquidistantGrid(0:10)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
77 # @test coarsen(g, 1) == EquidistantGrid(0:1:10)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
78 # @test coarsen(g, 2) == EquidistantGrid(0:2:10)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
79
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
80 # @test_throws DomainError(3, "Size minus 1 must be divisible by the ratio.") coarsen(g, 3)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
81 end
1426
9c689a627244 Add src and test file for curvilinear grid type
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
82 end