Beispiel #1
0
    def test_initialization(self):
        test = Spaceship("ime", 300)
        self.assertEqual("ime", test.name)
        self.assertEqual(300, test.capacity)
        self.assertEqual([], test.astronauts)

        for attr in ['name', 'capacity', 'astronauts']:
            self.assertTrue(hasattr(test, attr))
class TestSpaceShip(unittest.TestCase):
    def setUp(self):
        self.spaceship = Spaceship('Apollo 13', 2)

    def test_init(self):
        self.assertEqual(self.spaceship.name, 'Apollo 13')
        self.assertEqual(self.spaceship.capacity, 2)
        self.assertEqual(self.spaceship.astronauts, [])

    def test_addRaisesValueError_whenShipIsFull(self):
        self.spaceship.astronauts.append('Yurii Gagarin')
        self.spaceship.astronauts.append('John Crichton')
        with self.assertRaises(ValueError) as ex:
            self.spaceship.add('Batman')
        self.assertEqual(str(ex.exception), 'Spaceship is full')

    def test_addRaisesValueError_whenAstronautAlreadyInSpaceship(self):
        self.spaceship.astronauts.append('Yurii Gagarin')
        with self.assertRaises(ValueError) as ex:
            self.spaceship.add('Yurii Gagarin')
        self.assertEqual(str(ex.exception), 'Astronaut Yurii Gagarin Exists')

    def test_add_append(self):
        self.spaceship.add('Yurii Gagarin')
        self.assertEqual(self.spaceship.astronauts, ['Yurii Gagarin'])

    def test_remove_removesAstronaut_whenAstronautIn(self):
        self.spaceship.astronauts.append('Yurii Gagarin')
        self.spaceship.astronauts.append('John Crichton')
        self.spaceship.remove('Yurii Gagarin')
        self.assertEqual(self.spaceship.astronauts, ['John Crichton'])

    def test_remove_raisesValueError_whenAstronautNotIn(self):
        with self.assertRaises(ValueError) as ex:
            self.spaceship.remove('Yurii Gagarin')
        self.assertEqual(str(ex.exception), 'Astronaut Not Found')
 def setUp(self):
     self.spaceship = Spaceship('Apollo 13', 2)
Beispiel #4
0
 def test_should_remove_astronaut(self):
     test = Spaceship("ime", 2)
     test.add('zdr')
     self.assertEqual('zdr', test.astronauts[0])
     test.remove('zdr')
     self.assertEqual([], test.astronauts)
Beispiel #5
0
 def test_should_add_new_astronaut(self):
     test = Spaceship("ime", 2)
     test.add('zdr')
     self.assertEqual('zdr', test.astronauts[0])
     self.assertEqual("Added astronaut ime", test.add('ime'))
Beispiel #6
0
 def test_remove_should_raise_exception_if_astronaut_doesnt_exist(self):
     test = Spaceship("ime", 1)
     with self.assertRaises(ValueError) as context:
         test.remove('zdr')
         self.assertEqual(context, "Astronaut Not Found")
Beispiel #7
0
 def test_add_should_raise_exception_when_not_enough_capacity(self):
     test = Spaceship("ime", 0)
     with self.assertRaises(ValueError) as context:
         test.add('nqkakvo ime')
         self.assertEqual("Spaceship is full", context)
Beispiel #8
0
 def test_add_should_raise_exception_when_astronaut_already_exist(self):
     test = Spaceship("ime", 2)
     test.astronauts.append('zdr')
     with self.assertRaises(ValueError) as context:
         test.add('zdr')
         self.assertEqual("Astronaut zdr Exists", context)
 def setUp(self) -> None:
     self.ship = Spaceship('Apollo', 3)
class TestSpaceship(unittest.TestCase):
    def setUp(self) -> None:
        self.ship = Spaceship('Apollo', 3)

    def test_init(self):
        self.assertEqual('Apollo', self.ship.name)
        self.assertEqual(3, self.ship.capacity)
        self.assertListEqual([], self.ship.astronauts)

    def test_add_when_full_should_raises_error(self):
        self.ship.add('Neil')
        self.ship.add('Buzz')
        self.ship.add('Momchil')
        with self.assertRaises(ValueError) as error:
            self.ship.add('test')
        # expected = "Spaceship is full"
        # self.assertEqual(expected, str(error))

    def test_add_when_name_same_should_raise_error(self):
        self.ship.add('Neil')
        self.ship.add('Buzz')
        self.ship.add('Momchil')
        with self.assertRaises(ValueError) as error:
            self.ship.add('Buzz')

    def test_successful_add_should_return_string(self):
        self.ship.add('Neil')
        self.ship.add('Buzz')
        self.assertEqual("Added astronaut test", self.ship.add('test'))
        self.assertEqual(3, len(self.ship.astronauts))

    def test_remove_non_existing_astronaut_should_raise_error(self):
        with self.assertRaises(ValueError):
            self.ship.remove('test')

    def test_remove_successfully(self):
        self.ship.add('Neil')
        self.ship.add('Buzz')
        self.assertEqual("Removed Buzz", self.ship.remove('Buzz'))
Beispiel #11
0
 def setUp(self) -> None:
     self.spaceship = Spaceship("Voyager", 1)
Beispiel #12
0
class TestSpaceship(unittest.TestCase):

    def setUp(self) -> None:
        self.spaceship = Spaceship("Voyager", 1)

    def test_init(self):
        self.assertEqual(self.spaceship.name, "Voyager")
        self.assertEqual(self.spaceship.capacity, 1)
        self.assertEqual(self.spaceship.astronauts, [])

    def test_if_spaceship_full(self):
        with self.assertRaises(ValueError):
            self.spaceship.add("Gagarin")
            self.spaceship.add("Ivanov")

    def test_if_astronaut_is_already_in(self):
        with self.assertRaises(ValueError):
            self.spaceship.add("Gagarin")
            self.spaceship.add("Gagarin")

    def test_return_added_astronaut(self):
        result = self.spaceship.add("Gagarin")
        self.assertEqual(result, "Added astronaut Gagarin")

    def test_if_name_not_in_astronauts(self):
        with self.assertRaises(ValueError):
            self.spaceship.remove("Gagarin")

    def test_return_remove(self):
        result = self.spaceship.add("Gagarin")
        result = self.spaceship.remove("Gagarin")
        self.assertEqual(result, "Removed Gagarin")
Beispiel #13
0
class TestSpaceship(unittest.TestCase):
    def setUp(self) -> None:
        self.spaceship = Spaceship('Apollo', 2)

    def test_proper_init_name_capacity_astronauts(self):
        self.assertEqual('Apollo', self.spaceship.name)
        self.assertEqual(2, self.spaceship.capacity)
        self.assertEqual([], self.spaceship.astronauts)

    def test_add_astronauts_ok_plus_existing(self):
        self.assertEqual("Added astronaut Pesho", self.spaceship.add('Pesho'))
        with self.assertRaises(ValueError) as exc:
            self.spaceship.add('Pesho')
        self.assertEqual("Astronaut Pesho Exists", str(exc.exception))

    def test_add_astronauts_too_crowded(self):
        self.spaceship.add('Pesho')
        self.spaceship.add('Gosho')
        with self.assertRaises(ValueError) as exc:
            self.spaceship.add('Tretiq')
        self.assertEqual("Spaceship is full", str(exc.exception))

    def test_remove_astronauts_ok(self):
        self.spaceship.add('Pesho')
        self.assertEqual('Removed Pesho', self.spaceship.remove('Pesho'))
        self.assertEqual([], self.spaceship.astronauts)

    def test_remove_astronauts_not_in_names(self):
        self.spaceship.add('Pesho')
        with self.assertRaises(ValueError) as exc:
            self.spaceship.remove('Gosho')
        self.assertEqual("Astronaut Not Found", str(exc.exception))