예제 #1
0
 def test_will_return_correct_constants_from_equation_2(self):
     equation_parser = EquationParser(
         string_equation=self.equation_with_two_proper_operands())
     value = equation_parser.evaluate()
     self.assertEqual(
         value, "3.25 / 1.5",
         "Should convert sudo mixed numbers to decimal values in string equation"
     )
예제 #2
0
 def test_will_return_correct_constants_from_equation(self):
     equation_parser = EquationParser(
         string_equation=self.equation_with_singular_sudo_mixed_fraction())
     value = equation_parser.evaluate()
     self.assertEqual(
         value, "3.25",
         "Should convert sudo mixed numbers to decimal values in string equation"
     )
예제 #3
0
 def test_will_return_correct_constants_from_equation_7(self):
     equation_parser = EquationParser(
         string_equation=self.equation_with_improper_fraction_as_operand())
     value = equation_parser.evaluate()
     self.assertEqual(
         value, "2.75 + 7",
         "Should convert sudo mixed numbers to decimal values in string equation"
     )
예제 #4
0
 def test_will_return_correct_constants_from_equation_with_decimal_mixed_numbers(
         self):
     equation_parser = EquationParser(
         string_equation=self.equation_with_decimal_mixed_numbers())
     value = equation_parser.evaluate()
     self.assertEqual(
         value, "5.5 + 4.1",
         "Should convert sudo mixed numbers to decimal values in string equation"
     )
예제 #5
0
 def test_will_return_correct_constants_from_equation_with_more_than_two_operands_with_negative_values(
         self):
     equation_parser = EquationParser(
         string_equation=self.
         equation_with_more_than_two_operands_with_negative_values())
     value = equation_parser.evaluate()
     self.assertEqual(
         value, "-3.25 / -1.5 * -5.5",
         "Should convert sudo mixed numbers to decimal values in string equation"
     )
예제 #6
0
    def test_will_properly_evaluate_simple_equation(self):
        equation_parser = EquationParser(
            string_equation=self.equation_with_two_proper_positive_operands())
        string_equation = equation_parser.evaluate()

        evaluate = EvaluateEquation(equation=string_equation)
        mixed_number = evaluate.to_mixed_number()
        decimal_number = evaluate.to_decimal()

        self.assertEqual(decimal_number, 5.25)
        self.assertEqual(mixed_number, "5_1/4")
예제 #7
0
    def test_will_properly_evaluate_simple_operand(self):
        equation_parser = EquationParser(
            string_equation=self.equation_with_singular_sudo_mixed_fraction())
        string_equation = equation_parser.evaluate()

        evaluate = EvaluateEquation(equation=string_equation)
        mixed_number = evaluate.to_mixed_number()
        decimal_number = evaluate.to_decimal()

        self.assertEqual(decimal_number, 3.25)
        self.assertEqual(mixed_number, "3_1/4")
예제 #8
0
    def test_will_properly_evaluate_a_positive_mixed_number(self):
        equation_parser = EquationParser(
            string_equation=self.
            equation_with_singular_sudo_positive_improper_fraction())
        string_equation = equation_parser.evaluate()

        evaluate = EvaluateEquation(equation=string_equation)
        mixed_number = evaluate.to_mixed_number()
        decimal_number = evaluate.to_decimal()

        self.assertEqual(decimal_number, 2.75)
        self.assertEqual(mixed_number, "2_3/4")
예제 #9
0
 def test_will_split_equation_to_proper_array(self):
     equation_parser = EquationParser(
         string_equation=self.equation_with_two_proper_operands())
     split_equation = equation_parser.split_equation_to_array()
     self.assertEqual(split_equation, ["3_1/4", "/", "1_1/2"], "")
예제 #10
0
 def test_proper_operands(self):
     equation_parser = EquationParser()
     for operand in self.example_proper_operands():
         self.assertTrue(
             equation_parser._variable_is_a_proper_operand(operand))
예제 #11
0
 def test_illegal_operators(self):
     equation_parser = EquationParser()
     for illegal_operator in self.example_illegal_operators():
         self.assertRaises(ValueError,
                           equation_parser._variable_is_a_legal_operator,
                           illegal_operator)
예제 #12
0
 def test_legal_operators(self):
     equation_parser = EquationParser()
     for operator in self.legal_operators():
         self.assertTrue(
             equation_parser._variable_is_a_legal_operator(operator))
예제 #13
0
 def test_equation_parser_will_handle_integer_values(self):
     equation_parser = EquationParser()
     value = equation_parser.evaluate_equation_array(
         self.example_int_array())
     self.assertEqual(value, "3 + 5")
예제 #14
0
 def test_should_raise_exception_if_illegal_operator_in_equation(self):
     equation_parser = EquationParser(
         string_equation=self.equation_with_illegal_operator())
     self.assertRaises(ValueError, equation_parser.evaluate)
예제 #15
0
 def test_should_return_exception_if_no_spaces_in_equation(self):
     equation_parser = EquationParser(
         string_equation=self.equation_with_no_spaces())
     self.assertRaises(ValueError, equation_parser.evaluate)