annotate test/Grids/grid_test.jl @ 1270:dcbac783e4c1 refactor/grids

Factor out functions for getting the type and number of components in a type
author Jonatan Werpers <jonatan@werpers.com>
date Sat, 25 Feb 2023 22:42:16 +0100
parents 20f42cf0800c
children 3637daad71e8
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
1245
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
14 end
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
15
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
16 @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
17 @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
18 @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
19 @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
20
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(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
22 @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
23
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
24
1252
c150eabaf656 Fix or mark tests broken where needed
Jonatan Werpers <jonatan@werpers.com>
parents: 1245
diff changeset
25 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
26
1269
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
27
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
28 # 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
29
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
20f42cf0800c Add test for Grid and make them pass. Start implementing eval_on
Jonatan Werpers <jonatan@werpers.com>
parents: 1252
diff changeset
39
1252
c150eabaf656 Fix or mark tests broken where needed
Jonatan Werpers <jonatan@werpers.com>
parents: 1245
diff changeset
40
c150eabaf656 Fix or mark tests broken where needed
Jonatan Werpers <jonatan@werpers.com>
parents: 1245
diff changeset
41 f(x,y) = sin(x)*cos(y)
c150eabaf656 Fix or mark tests broken where needed
Jonatan Werpers <jonatan@werpers.com>
parents: 1245
diff changeset
42 @test_broken eval_on(g, f) == map(p->f(p...), points(g))
1245
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
43 end
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
44
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
45 @testset "getcomponent" begin
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
46 @test_broken false
6323d2fe3b4f Add stub files for tests
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
47 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
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 @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
50 @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
51 @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
52 @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
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 @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
55 @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
56 @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
57 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
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 @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
60 @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
61 @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
62 @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
63
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(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
65 @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
66 @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
67 end