Skip to content

Commit

Permalink
test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mauro-milella committed Nov 3, 2023
1 parent 363eddf commit f33171c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/SoleLogics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export value, token, children, formulas
export tree
export istop, isbot

export tokens, operators, connectives, leaves, atoms, natoms, height
export tokens, ntokens, atoms, natoms, truths, ntruths, leaves, nleaves,
connectives, nconnectives, operators, noperators, height

export interpret, check

Expand Down
10 changes: 6 additions & 4 deletions src/core.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#=
Syntactical Type Hierarchy
Expand Down Expand Up @@ -280,13 +279,16 @@ function tokens(φ::SyntaxTree) # ::AbstractVector{<:SyntaxToken}
return SyntaxToken[vcat(tokens.(children(φ))...)..., token(φ)]
end
function atoms::SyntaxTree) # ::AbstractVector{<:Atom}
return Atom[vcat(atoms.(children(φ))...)...] |> unique
a = token(φ) isa Atom ? [token(φ)] : []
return Atom[vcat(atoms.(children(φ))...)..., a...] |> unique
end
function truths::SyntaxTree) # ::AbstractVector{<:Truth}
return Truth[vcat(truths.(children(φ))...)...] |> unique
t = token(φ) isa Truth ? [token(φ)] : []
return Truth[vcat(truths.(children(φ))...)..., t...] |> unique
end
function leaves::SyntaxTree) # ::AbstractVector{<:SyntaxLeaf}
return SyntaxLeaf[vcat(leaves.(children(φ))...)...]
l = token(φ) isa SyntaxLeaf ? [token(φ)] : []
return SyntaxLeaf[vcat(leaves.(children(φ))...)..., l...]
end
function connectives::SyntaxTree) # ::AbstractVector{<:Connective}
c = token(φ) isa Connective ? [token(φ)] : []
Expand Down
6 changes: 6 additions & 0 deletions src/logics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,12 @@ function formulas(
return all_formulas
end

# This dispatches are needed, since ambiguities might arise when choosing between
# in(φ::SyntaxTree, g::SoleLogics.CompleteFlatGrammar) and
# in(p::Atom, g::SoleLogics.AbstractGrammar)
Base.in(p::Atom, g::CompleteFlatGrammar) = Base.in(p, alphabet(g))
Base.in(op::Truth, g::CompleteFlatGrammar) = (op <: operatorstype(g))

############################################################################################
#### AbstractAlgebra, semantics ############################################################
############################################################################################
Expand Down
6 changes: 3 additions & 3 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ grammar_int = SoleLogics.CompleteFlatGrammar(alphabet_int, SoleLogics.BASE_OPERA
@test ! (Atom(1.0) in grammar_int)
@test t1_int in grammar_int
@test ! (t100_int in grammar_int)
@test_throws ErrorException t1_int in alphabet(grammar_int)
@test t1_int in alphabet(grammar_int)

@test_nowarn formulas(grammar_int; maxdepth = 2, nformulas = 100)

Expand All @@ -112,8 +112,8 @@ f_int = @test_nowarn AnchoredFormula(logic_int, t1_int)
@test p1 in f_int
@test p1 in grammar(f_int)
@test ! (p1_number in f_int)
@test ! ( p100 in f_int )
@test ! ( Atom("1") in f_int )
@test ! (p100 in f_int)
@test ! (Atom("1") in f_int)


t2_int = @test_nowarn ¬(t1_int)
Expand Down

0 comments on commit f33171c

Please sign in to comment.