def test_render(self): cell_1 = Cell("B4") cell_2 = Cell("C3") cruiser = Ship("Cruiser", 3) self.assertEqual(cell_1.render(), ".") cell_1.fire_upon() self.assertEqual(cell_1.render(), "M") cell_2.place_ship(cruiser) self.assertEqual(cell_2.render(), ".") self.assertEqual(cell_2.render(reveal=True), "S") cell_2.fire_upon() self.assertEqual(cruiser.health, 2) self.assertEqual(cell_2.render(), "H") self.assertEqual(cruiser.is_sunk(), False) cruiser.hit() self.assertEqual(cruiser.health, 1) cruiser.hit() self.assertEqual(cruiser.health, 0) self.assertEqual(cruiser.is_sunk(), True) self.assertEqual(cell_2.render(), "X")
def test_cell_rendering(self): cell1 = Cell("B4") cell2 = Cell("C5") cell3 = Cell("D6") cruiser1 = Ship("cruiser", 1) cruiser2 = Ship("cruiser", 2) cell1.place_ship(cruiser1) cell2.place_ship(cruiser2) self.assertEqual(".", cell1.render()) self.assertEqual(".", cell2.render()) self.assertEqual(".", cell3.render()) cell1.fire_upon() cell2.fire_upon() cell3.fire_upon() self.assertEqual("X", cell1.render()) self.assertEqual("H", cell2.render()) self.assertEqual("M", cell3.render())