コード例 #1
0
    def __rsub__(self, other):
        # handling a number operand.
        if type(other) != CellModel:
            if self.type == enums.CellType.string.value and type(other) == str:
                raise TwoStringsException(
                    'Can not subtract two strings as a mathematical operation.'
                )

            if self.type == enums.CellType.numeric.value and type(
                    other) == str:
                raise DifferentTypesException(
                    'Can not subtract type: {} to type: {}.'.format(
                        self.type, type(other)))

            if self.type == enums.CellType.string.value and type(other) != str:
                raise DifferentTypesException(
                    'Can not subtract type: {} to type: {}.'.format(
                        self.type, type(other)))

            return CellModel(other - self.value, self.type)

        if self.type != other.type:
            raise DifferentTypesException(
                'Can not subtract type: {} to type: {}.'.format(
                    self.type, other.type))

        if (self.type and other.type) is enums.CellType.string.value:
            raise TwoStringsException(
                'Can not subtract two strings as a mathematical operation.')

        return CellModel(other.value - self.value, self.type)
コード例 #2
0
    def __rtruediv__(self, other):

        cells = list()
        cells.append(CellModel(self.name, enums.CellType.string.value))

        if type(other) != ColumnModel:
            for cell in self.cells[1:]:
                try:
                    newCell = other / cell

                except DifferentTypesException:
                    raise DifferentTypesException(
                        'can not divide column by a that is of a different type.'
                    )

                except TwoStringsException:
                    raise DifferentTypesException(
                        'can not divide column by a string value.')

                except ZeroDivisionError:
                    raise ZeroDivisionError(
                        'can not divide two columns that have cells produce zero division error.'
                    )

                cells.append(newCell)

            return ColumnModel(cells, self.name, self.id, self.isDeleted)

        for cell, i in zip(self.cells[1:], range(1, len(self.cells))):
            try:
                newCell = other.cells[i] / cell

            except DifferentTypesException:
                raise DifferentTypesException(
                    'can not divide two columns that have cells with different types.'
                )

            except TwoStringsException:
                raise DifferentTypesException(
                    'can not divide two columns that have cells that are of type string.'
                )

            except ZeroDivisionError:
                raise ZeroDivisionError(
                    'can not divide two columns that have cells produce zero division error.'
                )

            cells.append(newCell)

        return ColumnModel(cells, self.name, self.id, self.isDeleted)
コード例 #3
0
    def __mul__(self, other):
        cells = list()
        cells.append(CellModel(self.name, enums.CellType.string.value))

        if type(other) != ColumnModel:
            for cell in self.cells[1:]:
                try:
                    newCell = cell * other

                except DifferentTypesException:
                    raise DifferentTypesException(
                        'can not multiply a column that is of a different type by a value.'
                    )

                except TwoStringsException:
                    raise DifferentTypesException(
                        'can not multiply a string column with a string value.'
                    )

                cells.append(newCell)

            return ColumnModel(cells, self.name, self.id, self.isDeleted)

        for cell, i in zip(self.cells[1:], range(1, len(self.cells))):
            try:
                newCell = cell * other.cells[i]

            except DifferentTypesException:
                raise DifferentTypesException(
                    'can not multiply two columns that have cells with different types.'
                )

            except TwoStringsException:
                raise DifferentTypesException(
                    'can not multiply two columns that have cells that are of type string.'
                )

            cells.append(newCell)

        return ColumnModel(cells, self.name, self.id, self.isDeleted)
コード例 #4
0
    def __rtruediv__(self, other):
        # handling a number operand.
        if type(other) != CellModel:
            if self.type == enums.CellType.string.value and type(other) == str:
                raise TwoStringsException(
                    'Can not divide two strings as a mathematical operation.')

            if self.type == enums.CellType.numeric.value and type(
                    other) == str:
                raise DifferentTypesException(
                    'Can not divide type: {} to type: {}.'.format(
                        self.type, type(other)))

            if self.type == enums.CellType.string.value and type(other) != str:
                raise DifferentTypesException(
                    'Can not divide type: {} to type: {}.'.format(
                        self.type, type(other)))

            try:
                returnValue = other / self.value
            except ZeroDivisionError:
                raise ZeroDivisionError('Can not divide by zero')

            return CellModel(returnValue, self.type)

        if self.type != other.type:
            raise DifferentTypesException(
                'Can not divide type: {} to type: {}.'.format(
                    self.type, other.type))

        if (self.type and other.type) is enums.CellType.string.value:
            raise TwoStringsException(
                'Can not divide two strings as a mathematical operation.')

        try:
            returnValue = other.value / self.value
        except:
            raise ZeroDivisionError('Can not divide by zero')

        return CellModel(returnValue, self.type)
コード例 #5
0
    def __rsub__(self, other):
        cells = list()
        cells.append(CellModel(self.name, enums.CellType.string.value))

        if type(other) != ColumnModel:
            for cell in self.cells[1:]:
                try:
                    newCell = other - cell

                except DifferentTypesException:
                    raise DifferentTypesException(
                        'can not subtract value that is of a different type from a column.'
                    )

                except TwoStringsException:
                    raise DifferentTypesException(
                        'can not subtract string value from a column.')

                cells.append(newCell)

            return ColumnModel(cells, self.name, self.id, self.isDeleted)

        for cell, i in zip(self.cells[1:], range(1, len(self.cells))):
            try:
                newCell = other.cells[i] - cell

            except DifferentTypesException:
                raise DifferentTypesException(
                    'can not subtract two columns that have cells with different types.'
                )

            except TwoStringsException:
                raise DifferentTypesException(
                    'can not subtract two columns that have cells that are of type string.'
                )

            cells.append(newCell)

        return ColumnModel(cells, self.name, self.id, self.isDeleted)