Example #1
0
    def test_mixed_number_literal(self):
        arr_mixed_numbers = [MixedNumber(x, x % 100, x) for x in range(1, 9999)]
        exp = ' '.join(
            ['{0}_{1}/{2}'.format(x.whole, x.fraction.numerator, x.fraction.denominator) for x in arr_mixed_numbers]
        )
        tokens = tokenize_expr(exp)

        self.assertEqual(tokens, arr_mixed_numbers)
Example #2
0
    def test_complex_expression(self):
        exp = ' 12 +34/56 * /7_8/9 -    '
        tokens = tokenize_expr(exp)

        self.assertEqual(tokens, [
            12,
            InfixOperator('+'),
            Fraction(34, 56),
            InfixOperator('*'),
            InfixOperator('/'),
            MixedNumber(7, 8, 9),
            InfixOperator('-'),
        ])
Example #3
0
 def test_mix_div_x(self):
     self.assertEqual(MixedNumber(1, 2, 3),
                      MixedNumber(2, 1, 2) / MixedNumber(1, 1, 2))
Example #4
0
 def test_simple_exp_out_mix(self):
     self.assertEqual(MixedNumber(1, 7, 8), expression_eval('1/2 * 3_3/4'))
     self.assertEqual(MixedNumber(3, 1, 2), expression_eval('2_3/8 + 9/8'))
Example #5
0
 def test_single_expressions_improper_frac(self):
     self.assertEqual(MixedNumber(2, 1, 3), expression_eval('7/3'))
Example #6
0
 def test_frac_mul_x_doub_neg(self):
     self.assertEqual(MixedNumber(4, 3, 4),
                      MixedNumber(9, -1, 2) * Fraction(-1, 2))
Example #7
0
 def test_frac_mul_identity(self):
     self.assertEqual(MixedNumber(1, 2, 3),
                      MixedNumber(1, 2, 3) * Fraction(1, 1))
Example #8
0
 def test_int_mul_commutive(self):
     self.assertEqual(MixedNumber(4, 1, 2) * 2, 2 * MixedNumber(4, 1, 2))
Example #9
0
 def test_frac_add_x_out_int(self):
     self.assertEqual(2, MixedNumber(1, 1, 2) + Fraction(1, 2))
Example #10
0
 def test_frac_add_x_doub_neg(self):
     self.assertEqual(MixedNumber(2, -1, 6),
                      MixedNumber(1, -1, 2) + Fraction(-2, 3))
Example #11
0
 def test_frac_add_x_neg(self):
     self.assertEqual(MixedNumber(1, 1, 10),
                      MixedNumber(1, 1, 2) + Fraction(-2, 5))
Example #12
0
 def test_frac_add_x(self):
     self.assertEqual(MixedNumber(2, 1, 6),
                      MixedNumber(1, 1, 2) + Fraction(2, 3))
Example #13
0
 def test_frac_add_zero(self):
     self.assertEqual(MixedNumber(1, 1, 2),
                      MixedNumber(1, 1, 2) + Fraction(0, 1))
Example #14
0
 def test_int_add_commutative(self):
     self.assertEqual(MixedNumber(1, 1, 2) + 5, 5 + MixedNumber(1, 1, 2))
Example #15
0
 def test_mix_div_x_doub_neg(self):
     self.assertEqual(MixedNumber(1, 2, 3),
                      MixedNumber(2, -1, 2) / MixedNumber(1, -1, 2))
Example #16
0
 def test_int_add_zero(self):
     self.assertEqual(MixedNumber(1, 1, 2), MixedNumber(1, 1, 2) + 0)
Example #17
0
 def test_int_mul_x_doub_neg(self):
     self.assertEqual(MixedNumber(17, 1, 2), MixedNumber(2, -1, 2) * -7)
Example #18
0
 def test_mix_add_x(self):
     self.assertEqual(MixedNumber(4, 2, 3),
                      MixedNumber(1, 1, 3) + MixedNumber(3, 1, 3))
Example #19
0
 def test_frac_mul_zero(self):
     self.assertEqual(0, MixedNumber(1, 2, 3) * Fraction(0, 1))
Example #20
0
 def test_mix_add_x_out_int(self):
     self.assertEqual(3, MixedNumber(1, 1, 2) + MixedNumber(1, 1, 2))
Example #21
0
 def test_frac_mul_x(self):
     self.assertEqual(MixedNumber(4, 3, 4),
                      MixedNumber(9, 1, 2) * Fraction(1, 2))
Example #22
0
 def test_mix_add_x_neg(self):
     self.assertEqual(Fraction(-1, 6),
                      MixedNumber(1, 1, 2) + MixedNumber(1, -2, 3))
Example #23
0
 def test_frac_mul_commutative(self):
     self.assertEqual(
         MixedNumber(1, 1, 2) * MixedNumber(1, 1, 3),
         MixedNumber(1, 1, 3) * MixedNumber(1, 1, 2))
Example #24
0
 def test_mix_add_x_doub_neg(self):
     self.assertEqual(MixedNumber(4, -2, 3),
                      MixedNumber(1, -1, 3) + MixedNumber(3, -1, 3))
Example #25
0
 def test_int_mul_zero(self):
     self.assertEqual(0, MixedNumber(1, 2, 3) * 0)
Example #26
0
 def test_int_mul_identity(self):
     self.assertEqual(MixedNumber(1, 2, 3), MixedNumber(1, 2, 3) * 1)
Example #27
0
 def test_single_expr_mix(self):
     self.assertEqual(MixedNumber(2, 3, 4), expression_eval('2_3/4'))
Example #28
0
 def test_int_mul_x(self):
     self.assertEqual(MixedNumber(17, 1, 2), MixedNumber(2, 1, 2) * 7)
Example #29
0
 def test_complex_exp_out_mix(self):
     self.assertEqual(MixedNumber(5, 5, 6),
                      expression_eval('1/3 + 1_1/2 * 2 + 1_2/3 / 2/3'))
Example #30
0
 def test_mix_div_out_identity(self):
     self.assertEqual(1, MixedNumber(1, 1, 2) / MixedNumber(1, 1, 2))