Mercurial > repos > public > sbplib_julia
comparison test/Grids/grid_test.jl @ 1269:20f42cf0800c refactor/grids
Add test for Grid and make them pass. Start implementing eval_on
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Sat, 25 Feb 2023 22:22:50 +0100 |
| parents | c150eabaf656 |
| children | dcbac783e4c1 |
comparison
equal
deleted
inserted
replaced
| 1268:dbddd0f61bde | 1269:20f42cf0800c |
|---|---|
| 1 using Test | |
| 1 using Sbplib.Grids | 2 using Sbplib.Grids |
| 2 using Test | 3 using Sbplib.LazyTensors |
| 4 using StaticArrays | |
| 3 | 5 |
| 4 @testset "Grid" begin | 6 @testset "Grid" begin |
| 5 @test_broken false | 7 struct DummyGrid{T,D} <: Grid{T,D} end |
| 8 | |
| 9 @test eltype(DummyGrid{Int, 2}) == Int | |
| 10 @test eltype(DummyGrid{Int, 2}()) == Int | |
| 11 | |
| 12 @test ndims(DummyGrid{Int, 2}()) == 2 | |
| 13 @test dims(DummyGrid{Int, 2}()) == 1:2 | |
| 6 end | 14 end |
| 7 | 15 |
| 8 @testset "eval_on" begin | 16 @testset "eval_on" begin |
| 17 @test eval_on(ZeroDimGrid(@SVector[1.,2.]), x̄->x̄[1]+x̄[2]) isa LazyArray | |
| 18 @test eval_on(ZeroDimGrid(@SVector[1.,2.]), x̄->x̄[1]+x̄[2]) == fill(3.) | |
| 19 @test eval_on(ZeroDimGrid(@SVector[3.,2.]), x̄->x̄[1]+x̄[2]) == fill(5.) | |
| 20 | |
| 21 @test eval_on(EquidistantGrid(range(0,1,length=4)), x->2x) isa LazyArray | |
| 22 @test eval_on(EquidistantGrid(range(0,1,length=4)), x->2x) == 2 .* range(0,1,length=4) | |
| 23 | |
| 24 | |
| 9 g = equidistant_grid((5,3), (0.0,0.0), (2.0,1.0)) | 25 g = equidistant_grid((5,3), (0.0,0.0), (2.0,1.0)) |
| 10 | 26 |
| 11 @test_broken eval_on(g, (x,y) -> 0.) isa LazyArray | 27 |
| 12 @test_broken eval_on(g, (x,y) -> 0.) == fill(0., (5,3)) | 28 # Splat for only one dim, controllef by type specification in function. |
| 29 | |
| 30 @test eval_on(g, x̄ -> 0.) isa LazyArray | |
| 31 @test eval_on(g, x̄ -> 0.) == fill(0., (5,3)) | |
| 32 | |
| 33 @test eval_on(g, x̄ -> sin(x̄[1])*cos(x̄[2])) == map(x̄->sin(x̄[1])*cos(x̄[2]), g) | |
| 34 | |
| 35 # Vector valued function | |
| 36 @test eval_on(g, x̄ -> @SVector[x̄[2], x̄[1]]) isa LazyArray{SVector{2,Float64}} | |
| 37 @test eval_on(g, x̄ -> @SVector[x̄[2], x̄[1]]) == map(x̄ -> @SVector[x̄[2], x̄[1]], g) | |
| 38 | |
| 39 | |
| 13 | 40 |
| 14 f(x,y) = sin(x)*cos(y) | 41 f(x,y) = sin(x)*cos(y) |
| 15 @test_broken eval_on(g, f) == map(p->f(p...), points(g)) | 42 @test_broken eval_on(g, f) == map(p->f(p...), points(g)) |
| 16 end | 43 end |
| 17 | 44 |
