Mercurial > repos > public > sbplib_julia
comparison test/Grids/grid_test.jl @ 1360:f59228534d3a tooling/benchmarks
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 20 May 2023 15:15:22 +0200 |
parents | fa3695f634de |
children | 86026367a9ff |
comparison
equal
deleted
inserted
replaced
1321:42738616422e | 1360:f59228534d3a |
---|---|
1 using Test | |
2 using Sbplib.Grids | |
3 using Sbplib.LazyTensors | |
4 using StaticArrays | |
5 | |
6 @testset "Grid" begin | |
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 | |
14 @test coordinate_size(DummyGrid{Int, 1}()) == 1 | |
15 @test coordinate_size(DummyGrid{SVector{3,Float64}, 2}()) == 3 | |
16 | |
17 @test coordinate_size(DummyGrid{SVector{3,Float64}, 2}) == 3 | |
18 | |
19 @testset "component_type" begin | |
20 @test component_type(DummyGrid{Int,1}()) == Int | |
21 @test component_type(DummyGrid{Float64,1}()) == Float64 | |
22 @test component_type(DummyGrid{Rational,1}()) == Rational | |
23 | |
24 @test component_type(DummyGrid{SVector{3,Int},2}()) == Int | |
25 @test component_type(DummyGrid{SVector{2,Float64},3}()) == Float64 | |
26 @test component_type(DummyGrid{SVector{4,Rational},4}()) == Rational | |
27 | |
28 @test component_type(DummyGrid{Float64,1}) == Float64 | |
29 @test component_type(DummyGrid{SVector{2,Float64},3}) == Float64 | |
30 end | |
31 end | |
32 | |
33 @testset "eval_on" begin | |
34 @test eval_on(ZeroDimGrid(@SVector[1.,2.]), x̄->x̄[1]+x̄[2]) isa LazyArray | |
35 @test eval_on(ZeroDimGrid(@SVector[1.,2.]), x̄->x̄[1]+x̄[2]) == fill(3.) | |
36 @test eval_on(ZeroDimGrid(@SVector[3.,2.]), x̄->x̄[1]+x̄[2]) == fill(5.) | |
37 | |
38 @test eval_on(ZeroDimGrid(1.), x̄->2x̄) isa LazyArray | |
39 @test eval_on(ZeroDimGrid(1.), x̄->2x̄) == fill(2.) | |
40 | |
41 @test eval_on(EquidistantGrid(range(0,1,length=4)), x->2x) isa LazyArray | |
42 @test eval_on(EquidistantGrid(range(0,1,length=4)), x->2x) == 2 .* range(0,1,length=4) | |
43 | |
44 | |
45 g = equidistant_grid((5,3), (0.0,0.0), (2.0,1.0)) | |
46 | |
47 @test eval_on(g, x̄ -> 0.) isa LazyArray | |
48 @test eval_on(g, x̄ -> 0.) == fill(0., (5,3)) | |
49 | |
50 @test eval_on(g, x̄ -> sin(x̄[1])*cos(x̄[2])) == map(x̄->sin(x̄[1])*cos(x̄[2]), g) | |
51 | |
52 # Vector valued function | |
53 @test eval_on(g, x̄ -> @SVector[x̄[2], x̄[1]]) isa LazyArray{SVector{2,Float64}} | |
54 @test eval_on(g, x̄ -> @SVector[x̄[2], x̄[1]]) == map(x̄ -> @SVector[x̄[2], x̄[1]], g) | |
55 | |
56 # Multi-argument functions | |
57 f(x,y) = sin(x)*cos(y) | |
58 @test eval_on(g, f) == map(x̄->f(x̄...), g) | |
59 end | |
60 | |
61 @testset "_ncomponents" begin | |
62 @test Grids._ncomponents(Int) == 1 | |
63 @test Grids._ncomponents(Float64) == 1 | |
64 @test Grids._ncomponents(Rational) == 1 | |
65 | |
66 @test Grids._ncomponents(SVector{3,Int}) == 3 | |
67 @test Grids._ncomponents(SVector{2,Float64}) == 2 | |
68 @test Grids._ncomponents(SVector{4,Rational}) == 4 | |
69 end |