#auteur: Théo import unittest import table_de_jeu as t import pieces as p from joueur import * ''' ''' class TestElephant(unittest.TestCase): def test_var(self): plateau = t.Plateau(xmax=5, ymax=5, nb_montagne=3, joueur1=Theo, joueur2=Pauline) elephant1 = p.Elephant(1, 0, 'g', plateau) elephant2 = p.Elephant(4,3, 'b', plateau) self.assertEqual(elephant1.orientation, 'g') self.assertEqual(elephant1.coords, [1, 0]) self.assertEqual(elephant2.orientation, 'b') self.assertEqual(elephant2.coords, [4, 3]) def test_type(self): plateau = t.Plateau(xmax=5, ymax=5, nb_montagne=3, joueur1=Theo, joueur2=Pauline) elephant1 = p.Elephant(1, 0, 'g', plateau) self.assertIsInstance(elephant1, p.Elephant) self.assertIsInstance(elephant1, p.Animal) an = p.Rhinoceros(4,4,'g',plateau) self.assertNotIsInstance(an, p.Elephant) def test_coords(self): plateau = t.Plateau(xmax=5, ymax=5, nb_montagne=3, joueur1=Theo, joueur2=Pauline) elephant = p.Elephant(4, 3, 'h', plateau) rhinoceros=p.Rhinoceros(4,3,'h',plateau) self.assertEqual(elephant.coords, rhinoceros.coords) self.assertIsNot(elephant.coords, rhinoceros.coords) self.assertIs(elephant.coords, elephant.coords) class TestPlateau(unittest.TestCase): def test_init(self): table_jeu1 = t.Plateau(5, 5, 3, Theo, Pauline) table_jeu2 = t.Plateau(9, 6, 5, Theo, Pauline) self.assertEqual(table_jeu1.xmax, 5) self.assertEqual(table_jeu1.ymax, 5) self.assertEqual(table_jeu1.nb_montagne, 3) self.assertEqual(table_jeu2.xmax, 9) self.assertEqual(table_jeu2.ymax, 6) self.assertEqual(table_jeu2.nb_montagne, 5) class TestAnimal(unittest.TestCase): def test_sortir(self): plateau = t.Plateau(xmax=5, ymax=5, nb_montagne=3, joueur1=Theo, joueur2=Pauline) elephant = p.Elephant(4, 3, 'h', plateau) rhinoceros=p.Rhinoceros(4, 3, 'h', plateau) elephant.sortir() rhinoceros.sortir() self.assertEqual(elephant.coords[0], 6) self.assertEqual(rhinoceros.coords[0], -2) def test_pousser(self): plateau = t.Plateau(xmax=5, ymax=5, nb_montagne=3, joueur1=Theo, joueur2=Pauline) elephant1 = p.Elephant(4, 3, 'h', plateau) elephant2 = p.Elephant(4, 2, 'g', plateau) elephant1.pousser() elephant2.pousser() self.assertEqual(elephant2.coords, (3, 2)) self.assertEqual(elephant1.coords, (4, 2)) def test_changement_orientation(self): plateau = t.Plateau(xmax=5, ymax=5, nb_montagne=3, joueur1=Theo, joueur2=Pauline) elephant1 = p.Elephant(4, 3, 'g', plateau) elephant2 = p.Elephant(4, 2, 'g', plateau) elephant1.changement_orientation('gauche') elephant2.changement_orientation('demi-tour') self.assertEqual(elephant1.orientation, ('b')) self.assertEqual(elephant2.orientation, ('d')) def test_changement_position(self): plateau = t.Plateau(xmax=5, ymax=5, nb_montagne=3, joueur1=Theo, joueur2=Pauline) elephant1 = p.Elephant(4, 3, 'g', plateau) elephant2 = p.Elephant(4, 2, 'h', plateau) elephant1.changement_position(4,4,'rien') elephant2.changement_position(4,2,'rien') self.assertEqual(elephant1.coords, [4,4]) self.assertEqual(elephant2.coords, [4,2]) if __name__ == '__main__': unittest.main()