示例#1
0
 def test_parse_a_single_number(self):
     eq_(1, calculate('1'))
示例#2
0
 def test_use_parens_to_override_associativity(self):
     eq_(32, calculate('( 5 + 3 ) * ( 8 - 4 )'))
示例#3
0
 def test_a_lot_of_whitespace(self):
     eq_(4, calculate('    8   /     2   '))
示例#4
0
 def test_operators_are_right_associative(self):
     eq_((23 - (10 - 5)), calculate('23 - 10 - 5'))
     eq_((24 / (16 / 2)), calculate('24 / 16 / 2'))
     eq_((8 + (5 * 3)), calculate('8 + 5 * 3'))
示例#5
0
 def test_a_single_number_in_parens(self):
     eq_(5, calculate('(5)'))
示例#6
0
 def test_subtract_two_numbers(self):
     eq_(8, calculate('13 - 5'))
示例#7
0
 def test_roll_the_dice(self, mock_randint):
     mock_randint.return_value = 4
     eq_(8, calculate('2 d 6'))
示例#8
0
 def test_multiply_two_numbers(self):
     eq_(48, calculate('6 * 8'))
示例#9
0
 def test_divide_two_numbers(self):
     eq_(2.5, calculate('5 / 2'))
示例#10
0
 def test_add_several_numbers(self):
     eq_(56, calculate('18 + 2 + 40 + -4'))
示例#11
0
 def test_add_two_numbers(self):
     eq_(35.2, calculate('5.2 + 30'))
示例#12
0
 def test_parse_a_negative_number(self):
     eq_(-1, calculate('-1'))
示例#13
0
 def test_numbers_can_have_at_most_one_decimal_point(self):
     calculate('2.7.2')
示例#14
0
 def test_parse_a_decimal_number(self):
     eq_(3.141, calculate('3.141'))