annotate test/Grids/grid_test.jl @ 1511:d50ea06813d5 refactor/component_type

Move and extend tests to reflect that component_type is more general than before
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 21 Mar 2024 07:59:53 +0100
parents 86026367a9ff
children 0cd6cf62af93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1269
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
1 using Test
1245
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
2 using Sbplib.Grids
1269
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
3 using Sbplib.LazyTensors
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
4 using StaticArrays
1245
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
5
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
6 @testset "Grid" begin
1269
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
7 struct DummyGrid{T,D} <: Grid{T,D} end
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
8
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
9 @test eltype(DummyGrid{Int, 2}) == Int
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
10 @test eltype(DummyGrid{Int, 2}()) == Int
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
11
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
12 @test ndims(DummyGrid{Int, 2}()) == 2
1272
3637daad71e8 Add function target_manifold_dim for Grid
Jonatan Werpers <jonatan@werpers.com>
parents: 1270
diff changeset
13
1332
ad31c1022e42 Rename function for coordinate size of a grid
Jonatan Werpers <jonatan@werpers.com>
parents: 1324
diff changeset
14 @test coordinate_size(DummyGrid{Int, 1}()) == 1
ad31c1022e42 Rename function for coordinate size of a grid
Jonatan Werpers <jonatan@werpers.com>
parents: 1324
diff changeset
15 @test coordinate_size(DummyGrid{SVector{3,Float64}, 2}()) == 3
1288
7de1df0aad6a Add component_type function to Grid
Jonatan Werpers <jonatan@werpers.com>
parents: 1279
diff changeset
16
1333
79a2193da5c1 Implement coordinate_size() and component_type() types
Jonatan Werpers <jonatan@werpers.com>
parents: 1332
diff changeset
17 @test coordinate_size(DummyGrid{SVector{3,Float64}, 2}) == 3
1511
d50ea06813d5 Move and extend tests to reflect that component_type is more general than before
Jonatan Werpers <jonatan@werpers.com>
parents: 1397
diff changeset
18 end
1333
79a2193da5c1 Implement coordinate_size() and component_type() types
Jonatan Werpers <jonatan@werpers.com>
parents: 1332
diff changeset
19
1511
d50ea06813d5 Move and extend tests to reflect that component_type is more general than before
Jonatan Werpers <jonatan@werpers.com>
parents: 1397
diff changeset
20 @testset "component_type" begin
d50ea06813d5 Move and extend tests to reflect that component_type is more general than before
Jonatan Werpers <jonatan@werpers.com>
parents: 1397
diff changeset
21 @test component_type(DummyGrid{Int,1}()) == Int
d50ea06813d5 Move and extend tests to reflect that component_type is more general than before
Jonatan Werpers <jonatan@werpers.com>
parents: 1397
diff changeset
22 @test component_type(DummyGrid{Float64,1}()) == Float64
d50ea06813d5 Move and extend tests to reflect that component_type is more general than before
Jonatan Werpers <jonatan@werpers.com>
parents: 1397
diff changeset
23 @test component_type(DummyGrid{Rational,1}()) == Rational
1288
7de1df0aad6a Add component_type function to Grid
Jonatan Werpers <jonatan@werpers.com>
parents: 1279
diff changeset
24
1511
d50ea06813d5 Move and extend tests to reflect that component_type is more general than before
Jonatan Werpers <jonatan@werpers.com>
parents: 1397
diff changeset
25 @test component_type(DummyGrid{SVector{3,Int},2}()) == Int
d50ea06813d5 Move and extend tests to reflect that component_type is more general than before
Jonatan Werpers <jonatan@werpers.com>
parents: 1397
diff changeset
26 @test component_type(DummyGrid{SVector{2,Float64},3}()) == Float64
d50ea06813d5 Move and extend tests to reflect that component_type is more general than before
Jonatan Werpers <jonatan@werpers.com>
parents: 1397
diff changeset
27 @test component_type(DummyGrid{SVector{4,Rational},4}()) == Rational
1333
79a2193da5c1 Implement coordinate_size() and component_type() types
Jonatan Werpers <jonatan@werpers.com>
parents: 1332
diff changeset
28
1511
d50ea06813d5 Move and extend tests to reflect that component_type is more general than before
Jonatan Werpers <jonatan@werpers.com>
parents: 1397
diff changeset
29 @test component_type(DummyGrid{Float64,1}) == Float64
d50ea06813d5 Move and extend tests to reflect that component_type is more general than before
Jonatan Werpers <jonatan@werpers.com>
parents: 1397
diff changeset
30 @test component_type(DummyGrid{SVector{2,Float64},3}) == Float64
d50ea06813d5 Move and extend tests to reflect that component_type is more general than before
Jonatan Werpers <jonatan@werpers.com>
parents: 1397
diff changeset
31
d50ea06813d5 Move and extend tests to reflect that component_type is more general than before
Jonatan Werpers <jonatan@werpers.com>
parents: 1397
diff changeset
32 @test component_type(fill(@SVector[1,2], 4,2)) == Int
1245
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
33 end
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
34
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
35 @testset "eval_on" begin
1269
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
36 @test eval_on(ZeroDimGrid(@SVector[1.,2.]), x̄->x̄[1]+x̄[2]) isa LazyArray
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
37 @test eval_on(ZeroDimGrid(@SVector[1.,2.]), x̄->x̄[1]+x̄[2]) == fill(3.)
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
38 @test eval_on(ZeroDimGrid(@SVector[3.,2.]), x̄->x̄[1]+x̄[2]) == fill(5.)
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
39
1279
1157f889bf50 Clear out some TBDs
Jonatan Werpers <jonatan@werpers.com>
parents: 1276
diff changeset
40 @test eval_on(ZeroDimGrid(1.), x̄->2x̄) isa LazyArray
1157f889bf50 Clear out some TBDs
Jonatan Werpers <jonatan@werpers.com>
parents: 1276
diff changeset
41 @test eval_on(ZeroDimGrid(1.), x̄->2x̄) == fill(2.)
1157f889bf50 Clear out some TBDs
Jonatan Werpers <jonatan@werpers.com>
parents: 1276
diff changeset
42
1397
86026367a9ff Support evaluating scalars on grids
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1343
diff changeset
43 @test eval_on(ZeroDimGrid(@SVector[1.,2.]), π) isa LazyArray
86026367a9ff Support evaluating scalars on grids
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1343
diff changeset
44 @test eval_on(ZeroDimGrid(@SVector[1.,2.]), π) == fill(π)
86026367a9ff Support evaluating scalars on grids
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1343
diff changeset
45
1269
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
46 @test eval_on(EquidistantGrid(range(0,1,length=4)), x->2x) isa LazyArray
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
47 @test eval_on(EquidistantGrid(range(0,1,length=4)), x->2x) == 2 .* range(0,1,length=4)
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
48
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
49
1252
c150eabaf656 Fix or mark tests broken where needed
Jonatan Werpers <jonatan@werpers.com>
parents: 1245
diff changeset
50 g = equidistant_grid((5,3), (0.0,0.0), (2.0,1.0))
c150eabaf656 Fix or mark tests broken where needed
Jonatan Werpers <jonatan@werpers.com>
parents: 1245
diff changeset
51
1269
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
52 @test eval_on(g, x̄ -> 0.) isa LazyArray
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
53 @test eval_on(g, x̄ -> 0.) == fill(0., (5,3))
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
54
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
55 @test eval_on(g, x̄ -> sin(x̄[1])*cos(x̄[2])) == map(x̄->sin(x̄[1])*cos(x̄[2]), g)
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
56
1397
86026367a9ff Support evaluating scalars on grids
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1343
diff changeset
57 @test eval_on(g, π) == fill(π, (5,3))
86026367a9ff Support evaluating scalars on grids
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1343
diff changeset
58
1269
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
59 # Vector valued function
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
60 @test eval_on(g, x̄ -> @SVector[x̄[2], x̄[1]]) isa LazyArray{SVector{2,Float64}}
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
61 @test eval_on(g, x̄ -> @SVector[x̄[2], x̄[1]]) == map(x̄ -> @SVector[x̄[2], x̄[1]], g)
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
62
1273
7fab13c07412 Allow multi-argument functions in eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1272
diff changeset
63 # Multi-argument functions
1252
c150eabaf656 Fix or mark tests broken where needed
Jonatan Werpers <jonatan@werpers.com>
parents: 1245
diff changeset
64 f(x,y) = sin(x)*cos(y)
1273
7fab13c07412 Allow multi-argument functions in eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1272
diff changeset
65 @test eval_on(g, f) == map(x̄->f(x̄...), g)
1245
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
66 end
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
67
1270
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
68 @testset "_ncomponents" begin
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
69 @test Grids._ncomponents(Int) == 1
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
70 @test Grids._ncomponents(Float64) == 1
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
71 @test Grids._ncomponents(Rational) == 1
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
72
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
73 @test Grids._ncomponents(SVector{3,Int}) == 3
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
74 @test Grids._ncomponents(SVector{2,Float64}) == 2
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
75 @test Grids._ncomponents(SVector{4,Rational}) == 4
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
76 end