Ejemplo n.º 1
0
 def test_vertial_input_is_closing(self):
     data = EquationData(r"""\[\int_{a+1}^{b}{{x+1}^{2c}}{\delta x}\]""")
     mathNode = data.findMathNode()
     nextNode = data.getNodeAt(mathNode, 1)
     res, remaining = data.buildNode(nextNode, None, None, None)
     self.assertEqual(res.getTokenType(), TokenType.S_VERTICAL)
     self.assertFalse(res.isClosing())
Ejemplo n.º 2
0
 def test_integral_is_delimiter(self):
     data = EquationData(r"""\[\int_{a}^{b}{x^2}{\delta x}\]""")
     mathNode = data.findMathNode()
     nextNode = data.getNodeAt(mathNode, 0)
     res, remaining = data.buildNode(nextNode, None, None, None)
     self.assertFalse(res.isDelimiter(),
                      "an integral is not a delimiter in an empty stack")
Ejemplo n.º 3
0
 def test_GROUP_with_func(self):
     data = EquationData(r"""\[\int_{a}^{b}{x^2}{\delta x}\]""")
     mathNode = data.findMathNode()
     nextNode = data.getNodeAt(mathNode, 2)
     res, _ = data.buildNode(nextNode)
     self.assertIsNotNone(res, "Build node should return a node")
     self.assertEqual(res.getTokenType(), TokenType.T_VARIABLE)
Ejemplo n.º 4
0
 def test_a_plus_b_(self):
     data = EquationData(r"""\[a+b\]""")
     mathNode = data.findMathNode()
     res = data.buildTree(mathNode)
     self.assertEqual(res.getTokenType(), TokenType.T_PLUS)
     self.assertTrue(res.hasChild(LexicalRuleItem.K_LEFT))
     self.assertTrue(res.hasChild(LexicalRuleItem.K_RIGHT))
Ejemplo n.º 5
0
 def test_power_with_func(self):
     data = EquationData(r"""\[{a}^{b}\]""")
     mathNode = data.findMathNode()
     nextNode = data.getNodeAt(mathNode, 1)
     res, _ = data.buildNode(nextNode)
     self.assertIsNotNone(res, "Build node should return a node")
     self.assertEqual(res.getTokenType(), TokenType.T_POWER)
Ejemplo n.º 6
0
 def test_delta(self):
     data = EquationData(r"""\[\delta\]""")
     mathNode = data.findMathNode()
     nextNode = data.getNodeAt(mathNode, 0)
     res, _ = data.buildNode(nextNode)
     self.assertIsNotNone(res, "Build node should return a node")
     self.assertEqual(res.getTokenType(), TokenType.T_DELTA)
Ejemplo n.º 7
0
 def test_integral_is_not_closing_empty(self):
     data = EquationData(r"""\[\int_{a+1}^{b}{{x+1}^{2c}}{\delta x}\]""")
     # \int_{a+1}^{b}{{x+1}^{2c}+x^{2c}}{\delta x}
     mathNode = data.findMathNode()
     nextNode = data.getNodeAt(mathNode, 0)
     res, remaining = data.buildNode(nextNode, None, None, None)
     self.assertFalse(res.isClosing())
Ejemplo n.º 8
0
 def test_LeftParanMacro(self):
     data = EquationData(r"""\[\lparen\]""")
     mathNode = data.findMathNode()
     nextNode = data.getNodeAt(mathNode, 0)
     res, _ = data.buildNode(nextNode)
     self.assertIsNotNone(res, "Build node should return a node")
     self.assertEqual(res.getTokenType(), TokenType.T_LPAR)
Ejemplo n.º 9
0
 def test_if_integral_is_full(self):
     data = EquationData(r"""\[\int_{a}^{b}{x^2}{\delta x}\]""")
     mathNode = data.findMathNode()
     stack = []
     nextNode = data.getNodeAt(mathNode, 0)
     res, remaining = data.buildNode(nextNode, None, None, None)
     self.assertFalse(res.isClosing(),
                      "latex vertical is an opening delimeter")
Ejemplo n.º 10
0
 def test_delta_with_respect_times_y(self):
     data = EquationData(r"""\[{\delta x}y\]""")
     mathNode = data.findMathNode()
     res = data.buildTree(mathNode)
     self.assertIsNotNone(res, "Build node should return a node")
     self.assertEqual(res.getTokenType(), TokenType.T_MULT)
     left = res.hasChild(LexicalRuleItem.K_LEFT)
     self.assertTrue(left)
Ejemplo n.º 11
0
 def test_buildTree_with_sin_number(self):
     data = EquationData(r"""\[\sin4\]""")
     mathNode = data.findMathNode()
     res = data.buildTree(mathNode)
     self.assertIsNotNone(res, "Build node should return a node")
     self.assertEqual(res.getTokenType(), TokenType.T_SIN)
     left = res.hasChild(LexicalRuleItem.K_PARAM1)
     self.assertTrue(left)
Ejemplo n.º 12
0
 def test_buildTree_with_expression(self):
     data = EquationData(r"""\[\cos\lparen4\rparen\]""")
     mathNode = data.findMathNode()
     res = data.buildTree(mathNode)
     self.assertIsNotNone(res, "Build node should return a node")
     self.assertEqual(res.getTokenType(), TokenType.T_COS)
     left = res.hasChild(LexicalRuleItem.K_PARAM1)
     self.assertTrue(left)
Ejemplo n.º 13
0
 def test_vertial_input_is_delimiter_(self):
     data = EquationData(r"""\[\int_{a}^{b}{x^2}{\delta x}\]""")
     mathNode = data.findMathNode()
     stack = []
     nextNode = data.getNodeAt(mathNode, 0)
     res, remaining = data.buildNode(nextNode, None, None, None)
     node = Node(TokenType.S_VERTICAL)
     data.addToStack(stack, res, node)
     self.assertFalse(node.isDelimiter(), "latex vertical is a delimeter")
Ejemplo n.º 14
0
 def test_avaraible_returns(self):
     data = EquationData(r"""\[a\]""")
     mathNode = data.findMathNode()
     nextNode = data.getNodeAt(mathNode, 0)
     res, _ = data.buildNode(nextNode, None, None, None)
     self.assertEqual(res.getTokenType(), TokenType.T_VARIABLE)
     self.assertTrue(res.isClosing())
     self.assertFalse(res.lookAhead())
     self.assertFalse(res.lookBehind())
Ejemplo n.º 15
0
 def test_ab_multiply(self):
     data = EquationData(r"""\[ab\]""")
     mathNode = data.findMathNode()
     res = data.buildTree(mathNode)
     self.assertIsNotNone(res, "Build node should return a node")
     self.assertEqual(res.getTokenType(), TokenType.T_MULT)
     left = res.hasChild(LexicalRuleItem.K_LEFT)
     right = res.hasChild(LexicalRuleItem.K_RIGHT)
     self.assertTrue(left)
     self.assertTrue(right)
Ejemplo n.º 16
0
 def test_buildTree_with_double_parens_reversed_no_mutiply(self):
     data = EquationData(r"""\[{{4}}3\]""")
     mathNode = data.findMathNode()
     res = data.buildTree(mathNode)
     self.assertIsNotNone(res, "Build node should return a node")
     self.assertEqual(res.getTokenType(), TokenType.T_MULT)
     left = res.hasChild(LexicalRuleItem.K_LEFT)
     right = res.hasChild(LexicalRuleItem.K_RIGHT)
     self.assertTrue(left)
     self.assertTrue(right)
Ejemplo n.º 17
0
 def test_P_y_P_times_delta_x(self):
     data = EquationData(r"""\[{\lparen y\rparen}{\delta x}\]""")
     mathNode = data.findMathNode()
     res = data.buildTree(mathNode)
     self.assertIsNotNone(res, "Build node should return a node")
     self.assertEqual(res.getTokenType(), TokenType.T_MULT)
     left = res.hasChild(LexicalRuleItem.K_LEFT)
     self.assertTrue(left)
     left = res.getChild(LexicalRuleItem.K_LEFT)
     self.assertEqual(left.getTokenType(), TokenType.T_VARIABLE)
     right = res.getChild(LexicalRuleItem.K_RIGHT)
     self.assertEqual(right.getTokenType(), TokenType.T_DELTA)
Ejemplo n.º 18
0
 def test_integral_with_func_2(self):
     data = EquationData(r"""\[\int_{a}^{b} {x^2}{\delta x}\]""")
     mathNode = data.findMathNode()
     res = data.buildTree(mathNode)
     self.assertIsNotNone(res, "Build node should return a node")
     self.assertEqual(res.getTokenType(), TokenType.T_INTEGRAL)
     self.assertEqual(
         res.getChild(LexicalRuleItem.K_MIDDLE).getTokenType(),
         TokenType.T_POWER)
     self.assertEqual(
         res.getChild(LexicalRuleItem.K_RANGE).getTokenType(),
         TokenType.S_VERTICAL)
Ejemplo n.º 19
0
 def test_getMathNode(self):
     data = EquationData(r"""\[3\times4\]""")
     mathNode = data.findMathNode()
     self.assertNotEqual(mathNode, None, "Should find a math node")
Ejemplo n.º 20
0
 def test_tan(self):
     data = EquationData(r"""\[\tan\]""")
     mathNode = data.findMathNode()
     nextNode = data.getNextNode(mathNode, -1)
     res, _ = data.buildNode(nextNode)
     self.assertIsNotNone(res, "Build node should return a node")
Ejemplo n.º 21
0
 def test_consumeMathNode(self):
     data = EquationData(r"""\[3\times4\]""")
     mathNode = data.findMathNode()
     nextNode = data.getNextNode(mathNode, -1)
     self.assertEqual(True, isinstance(nextNode, LatexCharsNode))
Ejemplo n.º 22
0
 def test_negative(self):
     data = EquationData(r"""\[-4\]""")
     mathNode = data.findMathNode()
     res = data.buildTree(mathNode)
     self.assertEqual(res.getTokenType(), TokenType.T_NUM)
     self.assertEqual(res.value, '-4')
Ejemplo n.º 23
0
 def test_decimal0134(self):
     data = EquationData(r"""\[0.134\]""")
     mathNode = data.findMathNode()
     res = data.buildTree(mathNode)
     self.assertEqual(res.getTokenType(), TokenType.T_NUM)
     self.assertEqual(res.value, '0.134')