From 688f645cec5735fcfaa7c27bf734e408770f9510 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Sun, 20 Sep 2020 09:46:17 +0200 Subject: [PATCH] solves #89 --- Project.toml | 2 +- src/particles.jl | 14 ++++++++++++-- test/runtests.jl | 6 ++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 8c4372c1..19df1970 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MonteCarloMeasurements" uuid = "0987c9cc-fe09-11e8-30f0-b96dd679fdca" authors = ["baggepinnen "] -version = "0.9.5" +version = "0.9.6" [deps] Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" diff --git a/src/particles.jl b/src/particles.jl index 2755aa5f..6f1ba7ec 100644 --- a/src/particles.jl +++ b/src/particles.jl @@ -473,8 +473,18 @@ end Determine if two particles are not significantly different """ Base.:≈(p::AbstractParticles, a::AbstractParticles, lim=2) = abs(mean(p)-mean(a))/(2sqrt(std(p)^2 + std(a)^2)) < lim -Base.:≈(a::Real,p::AbstractParticles, lim=2) = abs(mean(p)-a)/std(p) < lim -Base.:≈(p::AbstractParticles, a::Real, lim=2) = abs(mean(p)-a)/std(p) < lim +function Base.:≈(a::Real,p::AbstractParticles, lim=2) + m = mean(p) + s = std(p, mean=m) + s == 0 && (return m == a) + abs(mean(p)-a)/std(p) < lim +end +function Base.:≈(p::AbstractParticles, a::Real, lim=2) + m = mean(p) + s = std(p, mean=m) + s == 0 && (return m == a) + abs(mean(p)-a)/std(p) < lim +end Base.:≈(p::MvParticles, a::AbstractVector) = all(a ≈ b for (a,b) in zip(a,p)) Base.:≈(a::AbstractVector, p::MvParticles) = all(a ≈ b for (a,b) in zip(a,p)) Base.:≈(a::MvParticles, p::MvParticles) = all(a ≈ b for (a,b) in zip(a,p)) diff --git a/test/runtests.jl b/test/runtests.jl index 61af85e1..c34db200 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -86,6 +86,12 @@ Random.seed!(0) @test (5 ± 0.1) ≳ (1 ± 0.1) @test (1 ± 0.1) ≲ (5 ± 0.1) + a = rand() + pa = Particles([a]) + @test a == pa + @test a ≈ pa + @test pa ≈ a + v = randn(5) @test Vector(PT(v)) == v @test Array(PT(v)) == v