def test_operation_chain_iterable_iterations(self):
        operationChain = operation_chain.parseRequest(self.getRequestSample())
        iterations = 0

        for operation in operationChain:
            iterations += 1

        self.assertEqual(3, iterations)
    def test_operation_chain_elements(self):
        operationChain = operation_chain.parseRequest(self.getRequestSample())

        self.compareParsedAgainstRequestSample(
            operationChain.getOperationAtIndex(0), 0, 1, 2)

        self.compareParsedAgainstRequestSample(
            operationChain.getOperationAtIndex(1), 2, 3, 4)

        self.compareParsedAgainstRequestSample(
            operationChain.getOperationAtIndex(2), 4, 5, 6)
    def test_operation_chain_iterable_elements(self):
        operationChain = operation_chain.parseRequest(self.getRequestSample())

        for index, operation in enumerate(operationChain):
            if (index == 0):
                self.compareParsedAgainstRequestSample(operation, 0, 1, 2)
            elif (index == 1):
                self.compareParsedAgainstRequestSample(operation, 2, 3, 4)
            elif (index == 2):
                self.compareParsedAgainstRequestSample(
                    operationChain.getOperationAtIndex(2), 4, 5, 6)
示例#4
0
    def test_operations_precedence(self):
        operations = operation_chain.parseRequest(self.getRequestSample())

        precedenceArray = calculator.createPrecedenceArray(operations)

        self.compareParsedAgainstRequestSample(
            heapq.heappop(precedenceArray)[2], 4, 5, 6)

        self.compareParsedAgainstRequestSample(
            heapq.heappop(precedenceArray)[2], 0, 1, 2)

        self.compareParsedAgainstRequestSample(
            heapq.heappop(precedenceArray)[2], 2, 3, 4)
示例#5
0
def consumeRequest(request):
    operationChain = operation_chain.parseRequest(request)

    #todo: validate chain

    operationsInPrecedence = createPrecedenceArray(operationChain)

    result = Matrix({})

    for i in range(len(operationsInPrecedence)):
        operation = heapq.heappop(operationsInPrecedence)[2]

        result = operations.delegateOperation(
            Matrix(operation.getLeftOperand()),
            Matrix(operation.getRightOperand()),
            operation.getOperator()['op']).matrix

        operation.setResult(result)

        operationChain.carryOut(operation)

    return result
 def test_operation_chain_size(self):
     operationChain = operation_chain.parseRequest(self.getRequestSample())
     self.assertEqual(operationChain.getSize(), 3)