comparison test/Grids/equidistant_grid_test.jl @ 1146:31041ef8092a refactor/grids

Specialize evalOn for EquidistantGrid to return a LazyArray
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 19 Oct 2022 23:23:36 +0200
parents cfe6a09974fb
children c150eabaf656
comparison
equal deleted inserted replaced
1145:4da66d6d7bed 1146:31041ef8092a
1 using Sbplib.Grids 1 using Sbplib.Grids
2 using Test 2 using Test
3 using Sbplib.RegionIndices 3 using Sbplib.RegionIndices
4 using Sbplib.LazyTensors
4 5
5 6
6 @testset "EquidistantGrid" begin 7 @testset "EquidistantGrid" begin
7 @test EquidistantGrid(4,0.0,1.0) isa EquidistantGrid 8 @test EquidistantGrid(4,0.0,1.0) isa EquidistantGrid
8 @test EquidistantGrid(4,0.0,8.0) isa EquidistantGrid 9 @test EquidistantGrid(4,0.0,8.0) isa EquidistantGrid
52 @test g[5,3] == (0.0,7.11) 53 @test g[5,3] == (0.0,7.11)
53 54
54 @test g[4,2] == (-0.25,7.11/2) 55 @test g[4,2] == (-0.25,7.11/2)
55 56
56 @test g[CartesianIndex(1,3)] == (-1.0,7.11) 57 @test g[CartesianIndex(1,3)] == (-1.0,7.11)
58 end
59
60 @testset "evalOn" begin
61 g = EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))
62
63 @test evalOn(g, (x,y) -> 0.) isa LazyArray
64 @test evalOn(g, (x,y) -> 0.) == fill(0., (5,3))
65
66 f(x,y) = sin(x)*cos(y)
67 @test evalOn(g, f) == map(p->f(p...), points(g))
57 end 68 end
58 69
59 @testset "restrict" begin 70 @testset "restrict" begin
60 g = EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0)) 71 g = EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))
61 @test restrict(g, 1) == EquidistantGrid(5,0.0,2.0) 72 @test restrict(g, 1) == EquidistantGrid(5,0.0,2.0)