コード例 #1
0
 def test_initialization(self):
     width = 5
     height = 5
     b = LegoBrick(width, height)
     self.assertEqual(b.getHeight(), height)
     self.assertEqual(b.getWidth(), width)
     self.assertEqual(b.getArea(), width * height)
     self.assertEqual(b.getId(), LegoBrick.NONE_ID)
     id = 13
     b = LegoBrick(width, height, id)
     self.assertEqual(b.getHeight(), height)
     self.assertEqual(b.getWidth(), width)
     self.assertEqual(b.getArea(), width * height)
     self.assertEqual(b.getId(), id)
コード例 #2
0
 def test_copy(self):
     b = LegoBrick(5, 5)
     copy = b.copy()
     self.assertEqual(b.getHeight(), copy.getHeight())
     self.assertEqual(b.getWidth(), copy.getWidth())
     self.assertEqual(b.getArea(), copy.getArea())
     self.assertEqual(b.getId(), copy.getId())
コード例 #3
0
 def test_setAttributes(self):
     height = 5
     b = LegoBrick(height, height)
     width = 10
     b.setWidth(width)
     self.assertEqual(b.getHeight(), height)
     self.assertEqual(b.getWidth(), width)
     self.assertEqual(b.getArea(), width * height)
     id = 13
     b.setId(id)
     self.assertEqual(b.getId(), id)
コード例 #4
0
    def __tryAddVertical(self, row: int, column: int,
                         brick: LegoBrick) -> bool:
        if column + brick.getHeight() > self.__height or row + brick.getWidth(
        ) > self.__width:
            return False

        for i in range(row, row + brick.getWidth()):
            for j in range(column, column + brick.getHeight()):
                if self.__area[i][j] != 0:
                    return False

        self.__layout.append(
            (row, column, brick, LegoBrickLayout.Orientation.VERTICAL))

        for i in range(row, row + brick.getWidth()):
            self.__area[i][column:column + brick.getHeight()] = brick.getId()

        self.__coveredArea += brick.getArea()
        return True