annotate test/Grids/grid_test.jl @ 1276:75a65db29be1 refactor/grids

Minor clean up
author Jonatan Werpers <jonatan@werpers.com>
date Sun, 26 Feb 2023 17:09:35 +0100
parents dcd8654ca33b
children 1157f889bf50
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
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
13 @test dims(DummyGrid{Int, 2}()) == 1:2
1272
3637daad71e8 Add function target_manifold_dim for Grid
Jonatan Werpers <jonatan@werpers.com>
parents: 1270
diff changeset
14
3637daad71e8 Add function target_manifold_dim for Grid
Jonatan Werpers <jonatan@werpers.com>
parents: 1270
diff changeset
15 @test target_manifold_dim(DummyGrid{Int, 1}()) == 1
3637daad71e8 Add function target_manifold_dim for Grid
Jonatan Werpers <jonatan@werpers.com>
parents: 1270
diff changeset
16 @test target_manifold_dim(DummyGrid{SVector{3,Float64}, 2}()) == 3
1245
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
17 end
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
18
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
19 @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
20 @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
21 @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
22 @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
23
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
24 @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
25 @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
26
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
27
1252
c150eabaf656 Fix or mark tests broken where needed
Jonatan Werpers <jonatan@werpers.com>
parents: 1245
diff changeset
28 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
29
1269
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
30 @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
31 @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
32
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
33 @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
34
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
35 # 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
36 @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
37 @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
38
1273
7fab13c07412 Allow multi-argument functions in eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1272
diff changeset
39 # Multi-argument functions
1252
c150eabaf656 Fix or mark tests broken where needed
Jonatan Werpers <jonatan@werpers.com>
parents: 1245
diff changeset
40 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
41 @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
42 end
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
43
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
44 @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
45 @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
46 @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
47 @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
48
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
49 @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
50 @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
51 @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
52 end
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
53
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
54 @testset "_component_type" 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
55 @test Grids._component_type(Int) == Int
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
56 @test Grids._component_type(Float64) == Float64
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
57 @test Grids._component_type(Rational) == Rational
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
58
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
59 @test Grids._component_type(SVector{3,Int}) == Int
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
60 @test Grids._component_type(SVector{2,Float64}) == Float64
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
61 @test Grids._component_type(SVector{4,Rational}) == Rational
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
62 end