Exemplo n.º 1
0
 def test_print_high_precedence(self):
     root = EvalTreeNode(OPERATORS['m'], None,
                         EvalTreeNode(OPERATORS['!'], EvalTreeNode(5)))
     tree = EvalTree(None)
     tree.root = root
     # it evaluates ! before display because of its high precedence
     self.assertEqual(tree.verbose_result(), '-120 = -120')
Exemplo n.º 2
0
 def test_print_parentheses(self):
     root = EvalTreeNode(
         OPERATORS['*'], EvalTreeNode(2),
         EvalTreeNode(OPERATORS['+'], EvalTreeNode(4), EvalTreeNode(8)))
     tree = EvalTree(None)
     tree.root = root
     self.assertEqual(tree.verbose_result(), '2*(4+8) = 24')
Exemplo n.º 3
0
 def test_print_roll(self):
     root = EvalTreeNode(
         OPERATORS['+'], EvalTreeNode(1),
         EvalTreeNode(OPERATORS['d'], EvalTreeNode(4), EvalTreeNode(20)))
     tree = EvalTree(None)
     tree.root = root
     self.assertEqual(tree.verbose_result(),
                      '1+' + str(Roll([1, 20, 1, 20], 20)) + ' = 43')
Exemplo n.º 4
0
 def populate(self, tree: EvalTree):
     """Display the result of a roll represented by the tree."""
     try:
         tree.evaluate()
         text = tree.verbose_result()
         color = 'black'
         if tree.is_critical():
             color = 'green'
         elif tree.is_fail():
             color = 'red'
         self.setText(text)
         self.setFont(self.defaultFont)
         self.setStyleSheet('color: {}'.format(color))
     except EvaluationError as e:
         self.show_error(e)
Exemplo n.º 5
0
 def test_print_unnecessary_parentheses(self):
     tree = EvalTree('1+(2*4)')
     self.assertEqual(tree.verbose_result(), '1+2*4 = 9')
Exemplo n.º 6
0
 def test_print_unary(self):
     root = EvalTreeNode(OPERATORS['m'], None, EvalTreeNode(4))
     tree = EvalTree(None)
     tree.root = root
     self.assertEqual(tree.verbose_result(), '-4 = -4')
Exemplo n.º 7
0
 def test_print_empty(self):
     tree = EvalTree(None)
     self.assertEqual(tree.verbose_result(), '')