From 1f6996d256e26dd14cc4b1dcfa100f7b055e062d Mon Sep 17 00:00:00 2001 From: Matthew Priddin Date: Tue, 25 Oct 2022 13:27:40 +0100 Subject: [PATCH 1/4] Add broken `==` tests for `KeyedDistribution` and `KeyedSampleable` --- test/runtests.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 14ff3d4..79ec12d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -364,4 +364,12 @@ using Test @test dimnames(rename(kd, (:name,))) == (:name, ) @test dimnames(rename(kd, :id => :name)) == (:name, ) end + + @testset "Equality comparison with wrapped type" begin + d = MvNormal([1.0, 2.0], [1.0, 1.0]); + kd = KeyedDistribution(d, 1:length(d)); + ks = KeyedSampleable(d, 1:length(d)); + @test kd == d + @test ks == d + end end From 6c53eefdcb6ae03a5995fc67b7df339b51e486ef Mon Sep 17 00:00:00 2001 From: Matthew Priddin Date: Tue, 25 Oct 2022 13:50:36 +0100 Subject: [PATCH 2/4] Overload `Base.:(==)` to compare `KeyedT` to underlying `T` --- src/KeyedDistributions.jl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/KeyedDistributions.jl b/src/KeyedDistributions.jl index 866b41a..584a5f9 100644 --- a/src/KeyedDistributions.jl +++ b/src/KeyedDistributions.jl @@ -265,4 +265,13 @@ function Distributions.insupport(d::KeyedDistribution{<:Univariate}, x::Real) return insupport(distribution(d), x) end +# Overload equality comparison between `KeyedT` and underlying `T` +for T in (:Distribution, :Sampleable) + KeyedT = Symbol(:Keyed, T) + @eval begin + Base.:(==)(kd::$KeyedT, d::$T) = distribution(kd) == d + Base.:(==)(d::$T, kd::$KeyedT) = kd == d + end +end + end From c2661d2b0e682656a6072d136febde106a5132bc Mon Sep 17 00:00:00 2001 From: Matthew Priddin Date: Tue, 25 Oct 2022 14:13:47 +0100 Subject: [PATCH 3/4] Add tests for alternative argument order --- test/runtests.jl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 79ec12d..084e0d4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -367,9 +367,15 @@ using Test @testset "Equality comparison with wrapped type" begin d = MvNormal([1.0, 2.0], [1.0, 1.0]); + kd = KeyedDistribution(d, 1:length(d)); - ks = KeyedSampleable(d, 1:length(d)); + @test kd == d + @test d == kd + + ks = KeyedSampleable(d, 1:length(d)); + @test ks == d + @test d == ks end end From dc4c4dfa521928fb2150e9d26d5a691da11f2325 Mon Sep 17 00:00:00 2001 From: Matthew Priddin Date: Wed, 26 Oct 2022 11:49:16 +0100 Subject: [PATCH 4/4] Bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 2cf2679..fa000fe 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "KeyedDistributions" uuid = "2576fb08-064d-4cab-b15d-8dda7fcb9a6d" authors = ["Invenia Technical Computing Corporation"] -version = "0.1.9" +version = "0.2.0" [deps] AutoHashEquals = "15f4f7f2-30c1-5605-9d31-71845cf9641f"