Beispiel #1
0
 def test_trivial(self):
     """
     This tests the rendering of trivial trees, like this:
     head
     """
     q = Qtree("head")
     self.assertEqual(q.render(), r"[.{head}  ]")
Beispiel #2
0
 def test_oneBranch(self):
     """
     head
      |
     tail
     """
     q = Qtree("head", [Qtree("tail")])
     self.assertEqual(q.renderTree(), r"[.{head} [.{tail}  ] ]")
Beispiel #3
0
 def test_twoBranches(self):
     r"""
     head
      |  \
     tail tail2
     """
     q = Qtree("head", [Qtree("tail"), Qtree("tail2")])
     self.assertEqual(q.renderTree(), r"[.{head} [.{tail}  ] [.{tail2}  ] ]")
Beispiel #4
0
 def test_newlines(self):
     r"""
     head
      |
     tailpartA
     tailpartB
     """
     q = Qtree("head", [Qtree("tailpartA\ntailpartB")])
     self.assertEqual(q.render(), r"[.{head} [.{tailpartA\\tailpartB}  ] ]")
Beispiel #5
0
 def test_twoBranchesDeep(self):
     r"""
     head
      |
     tail
      |
     tail2
     """
     q = Qtree("head", [
             Qtree("tail", [
                 Qtree("tail2")])])
     self.assertEqual(q.renderTree(), r"[.{head} [.{tail} [.{tail2}  ] ] ]")
Beispiel #6
0
    def test_or(self):
        r"""
        Rendering an Or renders the Or expression in the root and branches on
        each of the subexpressions.

        Or(p, q)
          /  \
         p    q
        """
        p = Or(PropVar('p'), PropVar('q'))
        expectedOutput = Qtree("Or(p, q)", [Qtree("p"), Qtree("q")])
        self.assertEqual(p.getSubTree().render(), expectedOutput.render())
Beispiel #7
0
    def test_or(self):
        r"""
        Rendering an Or renders the Or expression in the root and branches on
        each of the subexpressions.

        Or(p, q)
          /  \
         p    q
        """
        p = Or(PropVar('p'), PropVar('q'))
        expectedOutput = Qtree("Or(p, q)", [Qtree("p"), Qtree("q")])
        self.assertEqual(p.getSubTree().render(), expectedOutput.render())
Beispiel #8
0
    def test_and(self):
        r"""
        Rendering an And renders the And expression in the root and both of the
        conjuncts newline-separated in a single subtree.

        And(p, q)
           |
           p
           q
        """
        p = And(PropVar('p'), PropVar('q'))
        expectedOutput = Qtree("And(p, q)", [Qtree("p\nq")])
        self.assertEqual(p.getSubTree().render(), expectedOutput.render())
Beispiel #9
0
 def test_complexOr(self):
     r"""
        Or(p, Or(z, q))
       /  \
      p  Or(z, q)
           /  \
          z    q
     """
     p = Or(PropVar('p'), (Or(PropVar('z'), PropVar('q'))))
     expectedOutput = Qtree("Or(p, Or(z, q))",
                            [Qtree("p"), Qtree("Or(z, q)",
                                               [Qtree("z"), Qtree("q")])])
     self.assertEqual(p.getSubTree().render(), expectedOutput.render())
Beispiel #10
0
    def test_and(self):
        r"""
        Rendering an And renders the And expression in the root and both of the
        conjuncts newline-separated in a single subtree.

        And(p, q)
           |
           p
           q
        """
        p = And(PropVar('p'), PropVar('q'))
        expectedOutput = Qtree("And(p, q)", [Qtree("p\nq")])
        self.assertEqual(p.getSubTree().render(), expectedOutput.render())
Beispiel #11
0
 def test_complexAnd(self):
     r"""
     And(And(p, q), r)
      |
     And(p, q)
      r
      |
      p
      q
     """
     p = And(And(PropVar('p'), PropVar('q')), PropVar('r'))
     expectedOutput = Qtree("And(And(p, q), r)",
                            [Qtree("And(p, q)\nr", [Qtree("p\nq")])])
     actual = p.getSubTree().render()
     expected = expectedOutput.render()
     self.assertEqual(actual, expected)
Beispiel #12
0
 def test_propvar(self):
     """
     Rendering a PropVar trivially renders just that PropVar in a tree on
     its own.
     """
     p = PropVar('p')
     self.assertEqual(p.getSubTree().render(), Qtree('p').render())
Beispiel #13
0
 def test_complexAndRightHand(self):
     r"""
     And(r, And(p, q))
      |
      r
     And(p, q)
      |
      p
      q
     """
     p = And(PropVar('r'), And(PropVar('p'), PropVar('q')))
     expectedOutput = Qtree("And(r, And(p, q))",
                            [Qtree("r\nAnd(p, q)", [Qtree("p\nq")])])
     actual = p.getSubTree().render()
     expected = expectedOutput.render()
     self.assertEqual(actual, expected)
Beispiel #14
0
 def test_complexAnd(self):
     r"""
     And(And(p, q), r)
      |
     And(p, q)
      r
      |
      p
      q
     """
     p = And(And(PropVar('p'), PropVar('q')), PropVar('r'))
     expectedOutput = Qtree("And(And(p, q), r)",
                            [Qtree("And(p, q)\nr",
                                [Qtree("p\nq")])])
     actual = p.getSubTree().render()
     expected = expectedOutput.render()
     self.assertEqual(actual, expected)
Beispiel #15
0
 def test_complexAndRightHand(self):
     r"""
     And(r, And(p, q))
      |
      r
     And(p, q)
      |
      p
      q
     """
     p = And(PropVar('r'), And(PropVar('p'), PropVar('q')))
     expectedOutput = Qtree("And(r, And(p, q))",
                            [Qtree("r\nAnd(p, q)",
                                [Qtree("p\nq")])])
     actual = p.getSubTree().render()
     expected = expectedOutput.render()
     self.assertEqual(actual, expected)
Beispiel #16
0
    def qtree(self, elideRoot=False):
        """
        For And expressions, render a subtree with each of the conjuncts
        separated by a newline as the head, and then proceed to recursively
        expand each conjunct in turn, one at a time.
        """
        if self.lhs.isComplex and self.rhs.isComplex:
            self.lhs.stack.append(self.rhs)

        subQtreeBranches = []
        if self.lhs.isComplex:
            subQtreeBranches.append(self.lhs.getSubTree(elideRoot=True))
        elif self.rhs.isComplex:
            subQtreeBranches.append(self.rhs.getSubTree(elideRoot=True))

        innerQtree = Qtree(self._newlineHead(), subQtreeBranches)
        if elideRoot:
            return innerQtree
        else:
            return Qtree(self.render(), [innerQtree])
Beispiel #17
0
 def test_complexDoubleAnd(self):
     r"""
     And(And(a, b), And(c, d))
      |
     And(a, b)
     And(c, d)
      |
      a
      b
      |
      c
      d
     """
     p = And(And(PropVar('a'), PropVar('b')),
             And(PropVar('c'), PropVar('d')))
     expectedOutput = Qtree("And(And(a, b), And(c, d))",
                            [Qtree("And(a, b)\nAnd(c, d)",
                                [Qtree("a\nb",
                                    [Qtree("c\nd")])])])
     actual = p.getSubTree().render()
     expected = expectedOutput.render()
     self.assertEqual(actual, expected)
Beispiel #18
0
 def test_complexOr(self):
     r"""
        Or(p, Or(z, q))
       /  \
      p  Or(z, q)
           /  \
          z    q
     """
     p = Or(PropVar('p'), (Or(PropVar('z'), PropVar('q'))))
     expectedOutput = Qtree(
         "Or(p, Or(z, q))",
         [Qtree("p"),
          Qtree("Or(z, q)", [Qtree("z"), Qtree("q")])])
     self.assertEqual(p.getSubTree().render(), expectedOutput.render())
Beispiel #19
0
 def test_complexDoubleAnd(self):
     r"""
     And(And(a, b), And(c, d))
      |
     And(a, b)
     And(c, d)
      |
      a
      b
      |
      c
      d
     """
     p = And(And(PropVar('a'), PropVar('b')), And(PropVar('c'),
                                                  PropVar('d')))
     expectedOutput = Qtree(
         "And(And(a, b), And(c, d))",
         [Qtree("And(a, b)\nAnd(c, d)", [Qtree("a\nb", [Qtree("c\nd")])])])
     actual = p.getSubTree().render()
     expected = expectedOutput.render()
     self.assertEqual(actual, expected)
Beispiel #20
0
 def test_trivial(self):
     """
     head
     """
     q = Qtree("head")
     self.assertEqual(q.renderTree(), r"[.{head}  ]")
Beispiel #21
0
 def qtree(self, elideRoot=False):
     """
     Given the expression that is self, return a Qtree which can be rendered
     into the LaTeX we want to output.
     """
     return Qtree(self.render())
Beispiel #22
0
 def qtree(self, elideRoot=False):
     if elideRoot:
         text = ""
     else:
         text = self.render()
     return Qtree(text, [self.lhs.getSubTree(), self.rhs.getSubTree()])