Example #1
0
 def test_Input_1_Returns_1(self):
     # Arrange
     num1 = 1
     unaryExpression = SingleNumberExpression(num1)
     # Act
     actual = unaryExpression.evaluate()
     expected = 1
     # Assert
     self.assertEqual(actual, expected)
Example #2
0
 def test_Input_Neg2Point5_Returns_Neg2Point5(self):
     # Arrange
     num1 = -2.5
     unaryExpression = SingleNumberExpression(num1)
     # Act
     actual = unaryExpression.evaluate()
     expected = -2.5
     # Assert
     self.assertEqual(actual, expected)
 def test_Multiply_Input_Neg3_4_Returns_12(self):
     # Arrange
     leftNum = SingleNumberExpression(-3)
     rightNum = SingleNumberExpression(4)
     binaryExpression = MultiplicationExpression(leftNum, rightNum)
     # Act
     actual = binaryExpression.evaluate()
     expected = -12
     # Assert
     self.assertEqual(actual, expected)
 def test_Add_Input_1_1_Returns_2(self):
     # Arrange
     leftNum = SingleNumberExpression(1)
     rightNum = SingleNumberExpression(1)
     binaryExpression = AdditionExpression(leftNum, rightNum)
     # Act
     actual = binaryExpression.evaluate()
     expected = 2
     # Assert
     self.assertEqual(actual, expected)
 def test_Subtract_Input_1_Neg2_Returns_3(self):
     # Arrange
     leftNum = SingleNumberExpression(1)
     rightNum = SingleNumberExpression(-2)
     binaryExpression = SubtractionExpression(leftNum, rightNum)
     # Act
     actual = binaryExpression.evaluate()
     expected = 3
     # Assert
     self.assertEqual(actual, expected)
 def test_Divide_Input_2_4_Returns_Point5(self):
     # Arrange
     leftNum = SingleNumberExpression(2)
     rightNum = SingleNumberExpression(4)
     binaryExpression = DivisionExpression(leftNum, rightNum)
     # Act
     actual = binaryExpression.evaluate()
     expected = 0.5
     # Assert
     self.assertEqual(actual, expected)
class IBinaryExpression(IExpression):
  leftExpression = SingleNumberExpression(0)
  rightExpression = SingleNumberExpression(0)

  @dispatch(IExpression, IExpression)
  def __init__(self, inputLeftExpression, inputRightExpression):
    self.leftExpression = inputLeftExpression
    self.rightExpression = inputRightExpression
  
  def evaluate(self):
    pass
Example #8
0
 def test_Create_6_Times_2_Evaluates_12(self):
   # Arrange
   leftNum = SingleNumberExpression(6)
   operatorSign = "*"
   rightNum = SingleNumberExpression(2)
   binaryExpression = ExpressionFactory().CreateExpression(leftNum, operatorSign, rightNum)
   # Act
   actual = binaryExpression.evaluate()
   expected = 12
   # Assert
   self.assertEqual(actual, expected)
Example #9
0
 def test_Create_1_Plus_1_Is_AdditionExpression(self):
   # Arrange
   leftNum = SingleNumberExpression(1)
   operatorSign = "+"
   rightNum = SingleNumberExpression(1)
   binaryExpression = ExpressionFactory().CreateExpression(leftNum, operatorSign, rightNum)
   # Act
   actual = isinstance(binaryExpression, AdditionExpression)
   expected = True
   # Assert
   self.assertEqual(actual, expected)
Example #10
0
 def test_Create_2_Minus_1_Evaluates_1(self):
   # Arrange
   leftNum = SingleNumberExpression(2)
   operatorSign = "-"
   rightNum = SingleNumberExpression(1)
   binaryExpression = ExpressionFactory().CreateExpression(leftNum, operatorSign, rightNum)
   # Act
   actual = binaryExpression.evaluate()
   expected = 1
   # Assert
   self.assertEqual(actual, expected)
 def test_Divide_Difference_11_1_And_Product_2_5_Returns_1(self):
     # Arrange
     leftExpression = SubtractionExpression(SingleNumberExpression(11),
                                            SingleNumberExpression(1))
     rightExpression = MultiplicationExpression(SingleNumberExpression(2),
                                                SingleNumberExpression(5))
     entireExpression = DivisionExpression(leftExpression, rightExpression)
     # Act
     actual = entireExpression.evaluate()
     expected = 1
     # Assert
     self.assertEqual(actual, expected)
 def test_Add_Product_3_2_And_Sum_1_3_Returns_10(self):
     # Arrange
     leftExpression = MultiplicationExpression(SingleNumberExpression(3),
                                               SingleNumberExpression(2))
     rightExpression = AdditionExpression(SingleNumberExpression(1),
                                          SingleNumberExpression(3))
     entireExpression = AdditionExpression(leftExpression, rightExpression)
     # Act
     actual = entireExpression.evaluate()
     expected = 10
     # Assert
     self.assertEqual(actual, expected)
 def CreateExpression(self, inputNum):
     if inputNum.isnumeric():
         return SingleNumberExpression(float(inputNum))
     return SingleNumberExpression(0)
 def CreateExpression(self, inputNum):
     return SingleNumberExpression(inputNum)