annotate test/Grids/grid_test.jl @ 1273:7fab13c07412 refactor/grids

Allow multi-argument functions in eval_on
author Jonatan Werpers <jonatan@werpers.com>
date Sat, 25 Feb 2023 22:57:00 +0100
parents 3637daad71e8
children dcd8654ca33b
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
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
31 # Splat for only one dim, controllef by type specification in function.
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̄ -> 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
34 @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
35
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̄ -> 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
37
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
38 # 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
39 @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
40 @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
41
1273
7fab13c07412 Allow multi-argument functions in eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1272
diff changeset
42 # Multi-argument functions
1252
c150eabaf656 Fix or mark tests broken where needed
Jonatan Werpers <jonatan@werpers.com>
parents: 1245
diff changeset
43 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
44 @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
45 end
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
46
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
47 @testset "getcomponent" begin
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
48 @test_broken false
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
49 end
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
50
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 @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
52 @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
53 @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
54 @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
55
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._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
57 @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
58 @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
59 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
60
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 @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
62 @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
63 @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
64 @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
65
dcbac783e4c1 Factor out functions for getting the type and number of components in a type
Jonatan Werpers <jonatan@werpers.com>
parents: 1269
diff changeset
66 @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
67 @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
68 @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
69 end