def test_fire_upon(self): cell = Cell("B4") cruiser = Ship("Cruiser", 3) cell.place_ship(cruiser) self.assertEqual(cell.isFiredUpon, False) cell.fire_upon() self.assertEqual(cell.isFiredUpon, True) self.assertEqual(cell.ship.health, 2)
def test_cell_can_place_a_ship(self): cell = Cell("B4") cruiser = Ship("cruiser", 1) self.assertTrue(cell.empty) self.assertEqual(None, cell.ship) cell.place_ship(cruiser) self.assertFalse(cell.empty) self.assertEqual(cruiser, cell.ship)
def test_cell_can_be_fired_upon(self): cell = Cell("B4") cruiser = Ship("cruiser", 1) cell.place_ship(cruiser) self.assertFalse(cell.fired_upon) self.assertEqual(1, cruiser.health) cell.fire_upon() self.assertTrue(cell.fired_upon) self.assertEqual(0, cruiser.health)
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())
def test_place_ship(self): cell = Cell("B4") cruiser = Ship("Cruiser", 3) cell.place_ship(cruiser) self.assertEqual(cell.ship, cruiser) self.assertEqual(cell.isEmpty(), False)