module Data.Logic.ATP.ParserTests where
import Data.Logic.ATP.Equate ((.=.))
import Data.Logic.ATP.Pretty (assertEqual', Pretty(..), prettyShow, testEquals)
import Data.Logic.ATP.Prop ((.&.), (.=>.))
import Data.Logic.ATP.Parser (fof, parseFOL)
import Data.Logic.ATP.Skolem (Formula)
import Test.HUnit
t :: (Eq a, Pretty a) => String -> a -> a -> Test
t label expected actual = TestLabel label (TestCase (assertEqual' label expected actual))
parseFOL' :: String -> Either String Formula
parseFOL' = either (Left . show) Right . parseFOL
testParser :: Test
testParser =
TestLabel "ParserTests"
(TestList [ $(testEquals "precedence 1a") (Right [fof| (∃x. ⊤∧(∃y. ⊤)) |])
(parseFOL' " ∃x. (true & (∃y. true)) ")
, $(testEquals "precedence 1b") (Right [fof| ∃x. (true & (∃y. true)) |])
(parseFOL " ∃x. (true & (∃y. true)) ")
, $(testEquals "precedence 1c") (Right [fof|(∃x. ⊤∧(∃y. ⊤))|])
(parseFOL' " ∃x. true & ∃y. true ")
, $(testEquals "precedence 2") [fof| (true & false) | true |]
[fof| true & false | true |]
, $(testEquals "precedence 3") [fof| (true | false) <==> true |]
[fof| true | false <==> true |]
, $(testEquals "precedence 4") [fof| true <==> (false ==> true) |]
[fof| true <==> false ==> true |]
, $(testEquals "precedence 5") [fof| (~ true) & false |]
[fof| ~ true & false |]
, $(testEquals "precedence 6") (Right [fof|(∃x y. (x=y))|])
(parseFOL' " ∃x. ∃y. x=y ")
, $(testEquals "precedence 6b") [fof|(∃x. (∃y. (x=y)))|]
[fof| ∃x. (∃y. x=y) |]
, $(testEquals "precedence 7") [fof| ∃x. (∃y. (x=y)) |]
[fof| ∃x y. x=y |]
, $(testEquals "precedence 8") [fof| ∀x. (∃y. (x=y)) |]
[fof| ∀x. ∃y. x=y |]
, $(testEquals "precedence 9") [fof| ∃y. (∀x. (x=y)) |]
[fof| ∃y. (∀x. x=y) |]
, $(testEquals "precedence 10") [fof| (~P) & Q |]
[fof| ~P & Q |]
, $(testEquals "precedence 10a") (Left "(line 1, column 3):\nunexpected '~'\nexpecting prop")
(parseFOL' " ~~P ")
, $(testEquals "precedence 11") [fof| (P & Q) | R |]
[fof| P & Q | R |]
, $(testEquals "precedence 12") [fof| (P | Q) ==> R |]
[fof| P | Q ==> R |]
, $(testEquals "precedence 13") [fof| (P ==> Q) <==> R |]
[fof| P ==> Q <==> R |]
, $(testEquals "precedence 14a") [fof| ((x = y) ∧ (x = z)) ⇒ (y = z) |]
("x" .=. "y" .&. "x" .=. "z" .=>. "y" .=. "z")
, $(testEquals "pretty 1") "∃x y. (∀z. (F(x,y)⇒F(y,z)∧F(z,z))∧(F(x,y)∧G(x,y)⇒G(x,z)∧G(z,z)))"
(prettyShow [fof| ∃ x y. (∀ z. ((F(x,y)⇒F(y,z)∧F(z,z))∧(F(x,y)∧G(x,y)⇒G(x,z)∧G(z,z)))) |])
, $(testEquals "pretty 2") [fof| (∃x. (x=(f((g(x)))))∧(∀x'. x'=(f((g(x'))))⇒x=x'))⇔(∃y. y=(g((f(y))))∧(∀y'. y'=(g(f(y')))⇒y=y')) |]
[fof| (exists x. x = f(g(x)) /\ (forall x'. (x' = f(g(x'))) ==> (x = x'))) .<=>. (exists y. y = g(f(y)) /\ (forall y'. (y' = g(f(y'))) ==> (y = y'))) |]
, $(testEquals "parse 1") [fof| (forall x. i(x) * x = 1) ==> (forall x. i(x) * x = 1) |]
[fof| (forall x. i(x) * x = 1) ==> forall x. i(x) * x = 1 |]
, $(testEquals "parse 2") "(*(i(x), x))=(1)"
(prettyShow [fof| (i(x) * x = 1) |])
, $(testEquals "parse 3") [fof| ⊤⇒(∀x. ⊤) |]
[fof| true ==> forall x. true |]
, $(testEquals "parse 4") "⊤"
(prettyShow [fof| true |])
, $(testEquals "parse 5") "⊥"
(prettyShow [fof| false |])
])