diff --git a/Project.toml b/Project.toml index 0569f10..6779fcf 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "QBase" uuid = "e52e8ede-12bf-4731-8af7-b01f6064cb11" authors = ["Brian Doolittle and contributors"] -version = "0.1.1" +version = "0.1.2" [deps] Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa" diff --git a/src/QMath/probability.jl b/src/QMath/probability.jl index e127dba..40a5730 100644 --- a/src/QMath/probability.jl +++ b/src/QMath/probability.jl @@ -9,8 +9,8 @@ Returns `true` if the provided vector is a valid probability distribution: * `p[i] ≥ 0 ∀ i` """ function is_probability_distribution(probabilities::Vector)::Bool - is_positive = all(p -> (p > 0) || isapprox(p,0, atol=10e-7), probabilities) - is_normalized = (sum(probabilities) ≈ 1) + is_positive = all(p -> (p > 0) || isapprox(p, 0, atol=10e-7), probabilities) + is_normalized = isapprox(sum(probabilities), 1, atol=10e-6) (is_positive & is_normalized) end diff --git a/test/unit/QMath/probability.jl b/test/unit/QMath/probability.jl index e14b205..e2490fb 100644 --- a/test/unit/QMath/probability.jl +++ b/test/unit/QMath/probability.jl @@ -54,6 +54,11 @@ end @test conditionals isa QMath.Conditionals end + @testset "inexact edge case" begin + conditionals = QMath.Conditionals([0.666667 0.166667 0.166667; 0.166667 0.666667 0.166667; 0.166667 0.166667 0.666667]) + @test conditionals == [0.666667 0.166667 0.166667; 0.166667 0.666667 0.166667; 0.166667 0.166667 0.666667] + end + @testset "invalid cases" begin @test_throws DomainError QMath.Conditionals([0.5 -0.5;0.5 1.5]) end