def should_fill_rectangle(self): m = Matrix((10, 5), '.') m.fill(Point(3, 1), Point(8, 3), 'X') expected = textwrap.dedent("""\ .......... ...XXXXXX. ...XXXXXX. ...XXXXXX. .......... """) actual = m.tostring() self.assertEqual(actual, expected)
def should_convert_matrix_to_string(self): m = Matrix((5, 2)) m.data = [ '.', 'X', '.', 'X', '.', 'X', 'X', 'X', 'X', 'X', ] expected = textwrap.dedent("""\ .X.X. XXXXX """) self.assertEqual(m.tostring(), expected) m = Matrix((5, 2)) m.data = [ -1, 0, -1, 1, -1, 2, 0, 1, 2, 3, ] expected = textwrap.dedent("""\ .a.b. cabcd """) self.assertEqual(m.tostring(transformer=lambda c: '.' if c < 0 else chr(c + ord('a'))), expected)