|
| 1 | +using ConservationLawsParticles |
| 2 | +const PCF = PiecewiseConstantFunction |
| 3 | + |
| 4 | +@testset "map" begin |
| 5 | + pcf = PCF([0., 1.], [0., 1., 2.]) |
| 6 | + @test map(x -> x+1, pcf) == PCF([0., 1.], [1., 2., 3.]) |
| 7 | +end |
| 8 | + |
| 9 | +@testset "abs" begin |
| 10 | + pcf = PCF([0., 1.], [-1., 0., 1.]) |
| 11 | + @test abs(pcf) == PCF([0., 1.], [1., 0., 1.]) |
| 12 | +end |
| 13 | + |
| 14 | +@testset "ops" begin |
| 15 | + f = PCF([ 0., 1., 2., 3.], [0., 1., 2., -1., 4.]) |
| 16 | + g = PCF([-1., 0.5, 1., 2.5], [0., 1., -1., 0., 1.]) |
| 17 | + @test f + g == PCF([-1., 0., 0.5, 1., 2., 2.5, 3.], [0., 1., 2., 0., 2., -1., 0., 5.]) |
| 18 | + @test f - g == PCF([-1., 0., 0.5, 1., 2., 2.5, 3.], [0., -1., 0., 2., 2., -1., -2., 3.]) |
| 19 | + @test f * g == PCF([-1., 0., 0.5, 1., 2., 2.5, 3.], [0., 0., 1., -1., 0., 0., -1., 4.]) |
| 20 | + f_g = f / g # cannot use == directly because f_g.values contains NaN |
| 21 | + @test f_g.cuts == [-1., 0., 0.5, 1., 2., 2.5, 3.] |
| 22 | + @test isnan(f_g.values[1]) |
| 23 | + @test f_g.values[2:end] == [0., 1., -1., Inf, -Inf, -1., 4.] |
| 24 | +end |
| 25 | + |
| 26 | +@testset "lpnorm" begin |
| 27 | + pcf = PCF([0., 1., 11.], [0., 2., 3., 0.]) |
| 28 | + @test lpnorm(pcf, 1) == 2 + 30 |
| 29 | + @test lpnorm(pcf, 2) == sqrt(2^2 + 10*3^2) |
| 30 | + @test lpnorm(pcf, Inf) == 3 |
| 31 | + |
| 32 | + pcf = PCF([0., 1.], [1., 1., 1.]) |
| 33 | + # @test lpnorm(pcf, 1) == Inf |
| 34 | + @test lpnorm(pcf, Inf) == 1 |
| 35 | +end |
0 commit comments