class BlasterTest(unittest.TestCase): def setUp(self): self.b = Blaster(10, 10, 54) def test_constructor(self): self.assertEqual(self.b.gaz_level, 54) def test_recharge_method(self): self.assertEqual(self.b.gaz_level, 54) self.b.recharge() self.assertEqual(self.b.gaz_level, 100) def test_blaster_gaz_level_must_be_a_percent(self): with self.assertRaises(AssertionError): self.assertRaises(Blaster(1, 1, 1000)) self.assertRaises(Blaster(1, 1, -43))
def test_light_weight_war_ship_can_load_only_phasers(self): with self.assertRaises(AssertionError): p = Phaser(1, 1) b = Blaster(1, 1, 45) self.vcl.load(p) self.assertEqual(len(self.vcl.equipments), 1) self.assertRaises(AssertionError, self.vcl.load(b))
def test_location_setter_overriding(self): with self.assertRaises(AssertionError): w = Blaster(1,1,3) try: self.transport_ship.location = w except ValueError as e: self.assertEquals(e.args, ('A Ship can only be located in a TransportShip',)) raise
def test_must_raise_if_max_nb_weapons_equipped_exceeded(self): with self.assertRaises(AssertionError): b = Blaster(1, 1, 45) p = Phaser(1, 1) self.war_ship.load(b) self.war_ship.load(p) p2 = Phaser(2, 2) self.assertRaises(AssertionError, self.war_ship.load(p2))
def test_vch_can_load_any_weapons_and_only_weapons(self): with self.assertRaises(AssertionError): c = Container(1,1) self.assertRaises(AssertionError, self.vch.load(c)) p = Phaser(1,1) b = Blaster(1,1,56) self.vch.load(p) self.vch.load(b) self.assertEqual(self.vch.equipments.index(p), 0) self.assertEqual(self.vch.equipments.index(b), 1)
def setUp(self): self.b = Blaster(10, 10, 54)
def test_blaster_gaz_level_must_be_a_percent(self): with self.assertRaises(AssertionError): self.assertRaises(Blaster(1, 1, 1000)) self.assertRaises(Blaster(1, 1, -43))
def setUp(self): self.phasers = [] self.vc1 = LightWeightWarShip(10, 50, 2) print 'Soit un vaisseau de combat leger ' + self.vc1.name + '(volume=10, masse=50, 2 armes max)' print 'On equipe ' + self.vc1.name + ' avec deux phasers (volume=1, masse=1)' p = Phaser(1, 1) p1 = Phaser(1, 1) self.vc1.load(p) self.vc1.load(p1) self.phasers.append(p) self.phasers.append(p1) self.vt2 = TransportShip(100, 100, 90, 300) print 'Soit un vaisseau de transport ' + self.vt2.name + \ ' (volume=100, masse=100, cap_volume=90, cap_masse=300)' print 'On charge ' + self.vt2.name + ' avec 5 conteneurs (volume=1, masse= 1)' for i in range (0, 5): self.vt2.load(Container(1,1)) print 'On charge ' + self.vt2.name + ' avec ' + self.vc1.name + ' comme du fret' self.vt2.load(self.vc1) print 'On desequipe un des phasers de ' + self.vc1.name + ' et ' \ 'on le charge dans ' + self.vt2.name + ' comme du fret' self.vc1.unload(p) self.vt2.load(p) self.mr63 = HybridShip(200, 150, 180, 600, 5) print 'Soit ' + self.mr63.name + ' un vieux modele de vaisseau de transport lourd capable de se battre ' \ '(volume=200, masse=150, cap_volume=180, cap_masse=600, 5 armes max)' print 'On equipe ' + self.mr63.name + ' avec deux blasters (volume=2, masse=2, gaz=50%),' \ ' deux phasers (volume=1, masse=1),' \ ' le vaisseau ' + self.vt2.name + \ ' et 4 conteneurs (volume=10, masse=100)' b = Blaster(2, 2, 50) b2 = Blaster(2, 2, 50) self.mr63.load(b) self.mr63.load(b2) p2 = Phaser(1,1) p3 = Phaser(1,1) self.phasers.append(p2) self.phasers.append(p3) self.mr63.load(p2) self.mr63.load(p3) self.mr63.load(self.vt2) for i in range(0, 4): self.mr63.load(Container(10, 100)) print 'On veut connaitre le niveau de gaz des blasters equipes par ' + self.mr63.name + ', puis les recharger' for equipment in self.mr63.equipments: if isinstance(equipment, Blaster): print 'Niveau de gaz de ' + equipment.name + ': ' + str(equipment.gaz_level) equipment.recharge() print 'Niveau de gaz de ' + equipment.name + ' apres rechargement: ' + str(equipment.gaz_level)