Exemple #1
0
    def testLeftArcIsNotValidWithRoot(self):
        """invalid left when second item on the stack is root"""

        state = tdatatypes.State(5)
        system = ArcStandard()
        system.applyTransition(state, ArcStandard.SHIFT)
        self.assertFalse(system.isValidTransition(state, ArcStandard.LEFTARC))
Exemple #2
0
    def testRightArcHead(self):
        """RightArcStandard introduces an arc from the top-most token on the stack to the second one"""

        state = tdatatypes.State(5)
        system = ArcStandard()
        system.applyTransition(state, ArcStandard.SHIFT)
        system.applyTransition(state, ArcStandard.RIGHTARC)
        self.assertEqual(state.arcs.getHead(0), -1)
Exemple #3
0
    def testLeftArcHead(self):
        """LeftArc introduces an arc from the second to the first item on the stack"""

        state = tdatatypes.State(5)
        system = ArcStandard()
        system.applyTransition(state, ArcStandard.SHIFT)
        system.applyTransition(state, ArcStandard.SHIFT)
        system.applyTransition(state, ArcStandard.LEFTARC)
        self.assertEqual(state.arcs.getHead(0), 1)
Exemple #4
0
    def testShift(self):
        """Shift takes the first token from the front of the buffer and pushes it onto the stack"""

        state = tdatatypes.State(5)
        system = ArcStandard()

        system.applyTransition(state, ArcStandard.SHIFT)

        self.assertEqual(state.buffer.toList(), [1, 2, 3, 4])
        self.assertEqual(state.stack.toList(), [-1, 0])
Exemple #5
0
    def testLeftArcRemove(self):
        """LeftArc removes the second token on the stack"""

        state = tdatatypes.State(5)
        system = ArcStandard()
        system.applyTransition(state, ArcStandard.SHIFT)

        self.assertEqual(state.stack.toList(), [-1, 0])
        system.applyTransition(state, ArcStandard.LEFTARC)
        self.assertEqual(state.stack.toList(), [0])
Exemple #6
0
    def testRightArcRemove(self):
        """RightArcStandard removes the top-most token from the stack"""

        state = tdatatypes.State(5)
        system = ArcStandard()
        system.applyTransition(state, ArcStandard.SHIFT)

        self.assertEqual(state.stack.toList(), [-1, 0])
        self.assertEqual(state.buffer.toList(), [1, 2, 3, 4])

        system.applyTransition(state, ArcStandard.RIGHTARC)

        self.assertEqual(state.stack.toList(), [-1])
        self.assertEqual(state.buffer.toList(), [1, 2, 3, 4])
Exemple #7
0
 def applyTransition(self, state, tId):
     self.transitions.append(tId)
     return ArcStandard.applyTransition(self, state, tId)