def test_make_vector_from_iterable(self): """Test make vector from any iterable type.""" vec = vector.from_iterable( ('*', 1, '&', 1, 1, '-', '0', '1', 1, 0, '|*1-'), onefillers='&|', zerofillers='*-') self.assertEqual(int(vec), 0b01111001101010)
def from_iterable(value, zerofillers=None, onefillers=None): """Make Matrix object from list of iterable `value`.""" if not value: return Matrix() matrix_rows = tuple( vector.from_iterable( row, onefillers=onefillers, zerofillers=zerofillers) for row in value) return Matrix((row.value for row in matrix_rows), max(len(row) for row in matrix_rows))
def __make_row_from_value(self, value): """Make row from value of various type.""" try: value = value.value new_row = vector.Vector(value, self._ncolumns) except AttributeError: if isinstance(value, int): new_row = vector.Vector(value, self._ncolumns) elif isinstance(value, str): new_row = vector.from_string(value) new_row.set_length(self._ncolumns) else: new_row = vector.from_iterable(value) new_row.set_length(self._ncolumns) return new_row