Mercurial > repos > public > sbplib_julia
comparison test/SbpOperators/stencil_test.jl @ 1444:c779af4d02e5 bugfix/sbp_operators/stencil_return_type
Add tests for apply_stencil(::Stencil) and apply_stencil_backwards(::Stencil)
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 24 Nov 2023 21:04:22 +0100 |
parents | 14cb97284373 |
children | 76a121ee7b80 |
comparison
equal
deleted
inserted
replaced
1443:f217c6167952 | 1444:c779af4d02e5 |
---|---|
1 using Test | 1 using Test |
2 using Sbplib.SbpOperators | 2 using Sbplib.SbpOperators |
3 import Sbplib.SbpOperators.Stencil | 3 import Sbplib.SbpOperators.Stencil |
4 import Sbplib.SbpOperators.NestedStencil | 4 import Sbplib.SbpOperators.NestedStencil |
5 import Sbplib.SbpOperators.scale | 5 import Sbplib.SbpOperators.scale |
6 import Sbplib.SbpOperators: apply_stencil, apply_stencil_backwards | |
6 | 7 |
7 @testset "Stencil" begin | 8 @testset "Stencil" begin |
8 s = Stencil(-2:2, (1.,2.,2.,3.,4.)) | 9 s = Stencil(-2:2, (1.,2.,2.,3.,4.)) |
9 @test s isa Stencil{Float64, 5} | 10 @test s isa Stencil{Float64, 5} |
10 | 11 |
40 @test Stencil(1,2//2; center = 1) isa Stencil{Rational{Int64}, 2} | 41 @test Stencil(1,2//2; center = 1) isa Stencil{Rational{Int64}, 2} |
41 end | 42 end |
42 | 43 |
43 @testset "promotion" begin | 44 @testset "promotion" begin |
44 @test promote(Stencil(1,1;center=1), Stencil(2.,2.;center=2)) == (Stencil(1.,1.;center=1), Stencil(2.,2.;center=2)) | 45 @test promote(Stencil(1,1;center=1), Stencil(2.,2.;center=2)) == (Stencil(1.,1.;center=1), Stencil(2.,2.;center=2)) |
46 end | |
47 | |
48 @testset "apply_stencil" begin | |
49 v = [1, 2, 4, 8, 16, 32, 64, 128] | |
50 s = Stencil(1,2,3,4, center = 2) | |
51 @test apply_stencil(s,v, 2) == v[1] + 2*v[2] + 3*v[3] + 4*v[4] | |
52 @test apply_stencil(s,v, 4) == v[3] + 2*v[4] + 3*v[5] + 4*v[6] | |
53 @test apply_stencil_backwards(s,v, 3) == 4*v[1] + 3*v[2] + 2*v[3] + 1*v[4] | |
54 @test apply_stencil_backwards(s,v, 7) == 4*v[5] + 3*v[6] + 2*v[7] + 1*v[8] | |
55 @test apply_stencil(s,v, 2) isa Int | |
56 @test apply_stencil_backwards(s,v, 7) isa Int | |
57 | |
58 v = [1, 2, 4, 8, 16, 32, 64, 128] | |
59 s = Stencil(1.,2.,3.,4., center = 2) | |
60 @test apply_stencil(s,v, 4) == v[3] + 2. *v[4] + 3. *v[5] + 4. *v[6] | |
61 @test apply_stencil_backwards(s,v, 7) == 4. *v[5] + 3. *v[6] + 2. *v[7] + v[8] | |
62 @test apply_stencil(s,v, 2) isa Float64 | |
63 @test apply_stencil_backwards(s,v, 7) isa Float64 | |
64 | |
65 v = [1., 2., 4., 8., 16., 32., 64., 128.] | |
66 s = Stencil(1,2,3,4, center = 2) | |
67 @test apply_stencil(s,v, 2) == v[1] + 2*v[2] + 3*v[3] + 4*v[4] | |
68 @test apply_stencil_backwards(s,v, 3) == 4*v[1] + 3*v[2] + 2*v[3] + 1*v[4] | |
69 @test apply_stencil(s,v, 2) isa Float64 | |
70 @test apply_stencil_backwards(s,v, 3) isa Float64 | |
45 end | 71 end |
46 | 72 |
47 @testset "type stability" begin | 73 @testset "type stability" begin |
48 s_int = CenteredStencil(1,2,3) | 74 s_int = CenteredStencil(1,2,3) |
49 s_float = CenteredStencil(1.,2.,3.) | 75 s_float = CenteredStencil(1.,2.,3.) |