From 38320f09b30ebd39568214251ddf14c21d9f0616 Mon Sep 17 00:00:00 2001 From: Elias Carvalho Date: Tue, 17 May 2022 08:54:41 -0300 Subject: [PATCH 1/3] Update helper functions --- src/macro.jl | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/macro.jl b/src/macro.jl index 1fcd150..50983a2 100644 --- a/src/macro.jl +++ b/src/macro.jl @@ -8,13 +8,8 @@ _propname(x::Symbol) = x _propname(x::Any) = throw(ArgumentError("$x is not a valid proposition name.")) function _propnames!(props::Vector{Symbol}, expr::Expr) - if expr.head == :call - args = expr.args[2:end] - else - args = expr.args - end - - for arg in args + b = expr.head == :call ? 2 : 1 + for arg in expr.args[b:end] if arg isa Expr _propnames!(props, arg) else @@ -56,9 +51,9 @@ else function exprname(expr::Expr) str = string(expr) str = replace(str, - "&&" => "∧", "&" => "∧", - "||" => "∨", "|" => "∨", - "!" => "¬", "~" => "¬" + r"&{2}|&" => "∧", + r"\|{2}|\|" => "∨", + r"!|~" => "¬" ) Symbol(str) end From ad2d9e7b7b06f2797d264ea0bc25e2fbff929b5b Mon Sep 17 00:00:00 2001 From: Elias Carvalho Date: Tue, 17 May 2022 09:06:23 -0300 Subject: [PATCH 2/3] Update _propname --- src/macro.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/macro.jl b/src/macro.jl index 50983a2..2b9494a 100644 --- a/src/macro.jl +++ b/src/macro.jl @@ -4,8 +4,8 @@ ∨(x::Bool, y::Bool) = x || y ¬(x::Bool) = !x +_propname(x) = throw(ArgumentError("$x is not a valid proposition name.")) _propname(x::Symbol) = x -_propname(x::Any) = throw(ArgumentError("$x is not a valid proposition name.")) function _propnames!(props::Vector{Symbol}, expr::Expr) b = expr.head == :call ? 2 : 1 From afe865ae1de902dca8dba58e3565383549f4ac43 Mon Sep 17 00:00:00 2001 From: Elias Carvalho Date: Tue, 17 May 2022 09:29:53 -0300 Subject: [PATCH 3/3] Add tests for helper functions --- test/runtests.jl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 03becab..5fad164 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -68,6 +68,15 @@ using TruthTables: TruthTable @test Tables.getcolumn(tt, Symbol("¬y")) == Bool[0, 1, 0, 1] @test Tables.getcolumn(tt, Symbol("¬x ∧ ¬y")) == Bool[0, 0, 0, 1] @test Tables.getcolumn(tt, Symbol("¬(x ∨ y) <--> ¬x ∧ ¬y")) == Bool[1, 1, 1, 1] + + # helper functions + expr = :(p && q --> r) + @test TruthTables.propnames(expr) == [:p, :q, :r] + @test TruthTables.getsubexprs(expr) == [:(p && q), :(p && q --> r)] + @test TruthTables.exprname(expr) == Symbol("p ∧ q --> r") + + @test_throws ArgumentError TruthTables._propname(1) + @test_throws ArgumentError TruthTables._kwarg(:(full => true)) end @testset "TruthTable show" begin