Esempio n. 1
0
    def test_remove_whenPassengerNonExistent_shouldRaise(self):
        train = Train('test name', 100)

        with self.assertRaises(ValueError) as context:
            train.remove('passenger test name')

        self.assertIsNotNone(context.exception)
Esempio n. 2
0
    def test_add_whenValid_shouldAddPassengerToPassengersList(self):
        train = Train('test name', 100)

        result = train.add('passenger test name')

        self.assertEqual(['passenger test name'], train.passengers)
        self.assertEqual('Added passenger passenger test name', result)
Esempio n. 3
0
    def test_train_add__when_passenger_already_added__expect_ValueError(self):
        train = Train("Test", 10)
        passenger = "Pesho"

        with self.assertRaises(ValueError) as context:
            train.add(passenger)
            train.add(passenger)
        self.assertEqual("Passenger Pesho Exists", str(context.exception))
Esempio n. 4
0
    def test_remove_whenValid_shouldRemovePassenger(self):
        train = Train('test name', 100)
        train.add('passenger test name')

        result = train.remove('passenger test name')

        self.assertEqual([], train.passengers)
        self.assertEqual('Removed passenger test name', result)
Esempio n. 5
0
class TrainTests(TestCase):
    name = "TestTrain"
    capacity = 10

    def setUp(self) -> None:
        self.train = Train(self.name, self.capacity)

    def test__init__when_all_valid__expect_be_set(self):
        self.assertEqual(self.name, self.train.name)
        self.assertEqual(self.capacity, self.train.capacity)
        self.assertEqual([], self.train.passengers)

    def test_train_add__when_passenger_added__expect_to_set(self):
        passenger = "Pesho"
        self.train.add(passenger)
        self.assertEqual(1, len(self.train.passengers))
        self.assertEqual("Added passenger Pesho",
                         self.train.PASSENGER_ADD.format(passenger))

    def test_train_add__when_passenger_added_if_not_enough_capacity__expect_ValueError(
            self):
        train = Train("Test", 1)
        passenger = "Pesho"
        passenger2 = "Peter"
        with self.assertRaises(ValueError) as context:
            train.add(passenger)
            train.add(passenger2)

        self.assertEqual("Train is full", str(context.exception))

    def test_train_add__when_passenger_already_added__expect_ValueError(self):
        train = Train("Test", 10)
        passenger = "Pesho"

        with self.assertRaises(ValueError) as context:
            train.add(passenger)
            train.add(passenger)
        self.assertEqual("Passenger Pesho Exists", str(context.exception))

    def test_remove__when_passenger_not_on_train__expect_ValueError(self):
        train = Train("Test", 10)
        passenger = "Pesho"
        with self.assertRaises(ValueError) as context:
            train.remove(passenger)
        self.assertEqual("Passenger Not Found", str(context.exception))

    def test_remove__when_passenger_on_train_expect_to_be_removed(self):
        train = Train("Test", 10)
        passenger = "Pesho"
        train.add(passenger)
        self.assertEqual("Removed Pesho", train.remove(passenger))
 def test_remove(self):
     test_train = Train('test', 3)
     test_train.add('test_person')
     test_train.add('test_person_two')
     expected = "Removed test_person"
     self.assertEqual(2, len(test_train.passengers))
     actual = test_train.remove('test_person')
     self.assertEqual(1, len(test_train.passengers))
     self.assertEqual(expected, actual)
    def test_add_when_full_capacity_should_raise(self):
        test_train = Train('test', 1)
        test_train.add('test_person')
        with self.assertRaises(ValueError) as ex:
            test_train.add('test_person_two')

        self.assertEqual("Train is full", str(ex.exception))
    def test_train_when_passenger_on_board_should_raise(self):
        test_train = Train('test', 3)
        test_train.add('test_person')
        with self.assertRaises(ValueError) as ex:
            test_train.add('test_person')

        self.assertEqual("Passenger test_person Exists", str(ex.exception))
    def test_remove_when_passenger_not_on_board_should_raise(self):
        test_train = Train('test', 3)
        test_train.add('test_person')
        with self.assertRaises(ValueError) as ex:
            test_train.remove('test_person_two')

        self.assertEqual("Passenger Not Found", str(ex.exception))
Esempio n. 10
0
class TestTrain(unittest.TestCase):
    def setUp(self) -> None:
        self.train = Train('test_name', 30)

    def test_train_init_attributes(self):
        for attr in ['name', 'capacity', 'passengers']:
            self.assertTrue(hasattr(self.train, attr))

        self.assertEqual('test_name', self.train.name)
        self.assertEqual(30, self.train.capacity)
        self.assertEqual([], self.train.passengers)

    def test_add(self):
        actual = self.train.add('test_person')
        expected = f"Added passenger test_person"

        self.assertEqual(1, len(self.train.passengers))
        self.assertEqual(expected, actual)

    def test_add_when_full_capacity_should_raise(self):
        test_train = Train('test', 1)
        test_train.add('test_person')
        with self.assertRaises(ValueError) as ex:
            test_train.add('test_person_two')

        self.assertEqual("Train is full", str(ex.exception))

    def test_train_when_passenger_on_board_should_raise(self):
        test_train = Train('test', 3)
        test_train.add('test_person')
        with self.assertRaises(ValueError) as ex:
            test_train.add('test_person')

        self.assertEqual("Passenger test_person Exists", str(ex.exception))

    def test_remove(self):
        test_train = Train('test', 3)
        test_train.add('test_person')
        test_train.add('test_person_two')
        expected = "Removed test_person"
        self.assertEqual(2, len(test_train.passengers))
        actual = test_train.remove('test_person')
        self.assertEqual(1, len(test_train.passengers))
        self.assertEqual(expected, actual)

    def test_remove_when_passenger_not_on_board_should_raise(self):
        test_train = Train('test', 3)
        test_train.add('test_person')
        with self.assertRaises(ValueError) as ex:
            test_train.remove('test_person_two')

        self.assertEqual("Passenger Not Found", str(ex.exception))
Esempio n. 11
0
    def test_add_whenNotEnoughCapacity_shouldRaise(self):
        train = Train('test name', 1)
        train.add('passenger test name')

        with self.assertRaises(ValueError) as context:
            train.add('passenger test name2')

        self.assertIsNotNone(context.exception)
Esempio n. 12
0
    def test_add_whenPassengerNameAlreadyExists_shouldRaise(self):
        train = Train('test name', 100)
        train.add('passenger test name')

        with self.assertRaises(ValueError) as context:
            train.add('passenger test name')

        self.assertIsNotNone(context.exception)
Esempio n. 13
0
    def test_train_add__when_passenger_added_if_not_enough_capacity__expect_ValueError(
            self):
        train = Train("Test", 1)
        passenger = "Pesho"
        passenger2 = "Peter"
        with self.assertRaises(ValueError) as context:
            train.add(passenger)
            train.add(passenger2)

        self.assertEqual("Train is full", str(context.exception))
Esempio n. 14
0
class TestTrain(unittest.TestCase):
    def setUp(self) -> None:
        self.train = Train('BDJ', 50)

    def test_train_if_all_attributes_are_set_correctly(self):
        self.assertEqual(self.train.name, 'BDJ')
        self.assertEqual(self.train.capacity, 50)
        self.assertEqual(self.train.passengers, [])

    def test_train_add_passenger_if_no_capacity(self):
        self.train.capacity = 0
        with self.assertRaises(Exception) as ex:
            self.train.add('Gosho')
        self.assertEqual("Train is full", str(ex.exception))

    def test_train_add_passenger_if_passenger_is_already_on_train(self):
        self.train.passengers = ['Gosho']
        with self.assertRaises(Exception) as ex:
            self.train.add('Gosho')
        self.assertEqual("Passenger Gosho Exists", str(ex.exception))

    def test_train_add_passenger_if_everything_is_fine(self):
        self.assertEqual([], self.train.passengers)
        result = self.train.add('Gosho')
        self.assertEqual("Added passenger Gosho", result)
        self.assertIn('Gosho', self.train.passengers)

    def test_train_remove_passenger_if_he_is_not_in_train_exceptions(self):
        with self.assertRaises(Exception) as ex:
            self.train.remove('Gosho')
        self.assertEqual("Passenger Not Found", str(ex.exception))

    def test_train_remove_passenger_if_everything_is_fine(self):
        self.train.passengers = ['Gosho']
        self.assertEqual(['Gosho'], self.train.passengers)
        result = self.train.remove('Gosho')
        self.assertEqual("Removed Gosho", result)
        self.assertNotIn('Gosho', self.train.passengers)
Esempio n. 15
0
 def setUp(self):
     self.train = Train(self.name, self.capacity)
Esempio n. 16
0
class TestTrain(unittest.TestCase):
    def setUp(self):
        self.train = Train("Train", 2)

    def test__init(self):
        self.assertEqual(self.train.name, "Train")
        self.assertEqual(self.train.capacity, 2)
        self.assertEqual(self.train.passengers, [])

    def test__add__no_cap__raise_error(self):
        with self.assertRaises(ValueError) as ex:
            self.train.add("Pesho")
            self.train.add("Gosho")
            self.train.add("Maria")
        expected_msg = str(ex.exception)
        actual_msg = "Train is full"
        self.assertEqual(expected_msg, actual_msg)

    def test__add__same_name__raise_error(self):
        with self.assertRaises(ValueError) as ex:
            self.train.add("Pesho")
            self.train.add("Pesho")
        expected_msg = str(ex.exception)
        actual_msg = "Passenger Pesho Exists"
        self.assertEqual(expected_msg, actual_msg)

    def test__add__add_passenger(self):
        self.train.add("Pesho")
        self.assertEqual(len(self.train.passengers), 1)
        self.assertEqual(self.train.add("Maria"), "Added passenger Maria")
        self.assertEqual(len(self.train.passengers), 2)

    def test__remove_not_passenger_raise_error(self):
        with self.assertRaises(ValueError) as ex:
            self.train.remove("Pesho")
        expected_msg = str(ex.exception)
        actual_msg = "Passenger Not Found"
        self.assertEqual(expected_msg, actual_msg)

    def test__remove__remove_passenger(self):
        self.train.add("Pesho")
        self.assertEqual(len(self.train.passengers), 1)
        self.train.remove("Pesho")
        self.assertEqual(len(self.train.passengers), 0)
        self.train.add("Pesho")
        self.assertEqual(self.train.remove("Pesho"), "Removed Pesho")
Esempio n. 17
0
class TrainTest(unittest.TestCase):
    name = 'Train1'
    capacity = 5
    TRAIN_FULL = "Train is full"
    PASSENGER_EXISTS = "Passenger {} Exists"
    PASSENGER_NOT_FOUND = "Passenger Not Found"
    PASSENGER_ADD = "Added passenger {}"
    PASSENGER_REMOVED = "Removed {}"
    ZERO_CAPACITY = 0

    def setUp(self):
        self.train = Train(self.name, self.capacity)

    def test_init_attr(self):
        self.assertEqual('Train1', self.train.name)
        self.assertEqual(5, self.train.capacity)
        self.assertListEqual([], self.train.passengers)
        self.assertEqual("Train is full", self.train.TRAIN_FULL)
        self.assertEqual("Passenger {} Exists", self.train.PASSENGER_EXISTS)
        self.assertEqual("Passenger Not Found", self.train.PASSENGER_NOT_FOUND)
        self.assertEqual("Added passenger {}", self.train.PASSENGER_ADD)
        self.assertEqual("Removed {}", self.train.PASSENGER_REMOVED)
        self.assertEqual(0, self.train.ZERO_CAPACITY)

    def test_add__expect_to_add_passenger(self):
        self.train.add('Pesho')

        actual = self.PASSENGER_ADD.format('Pesho')
        expect = "Added passenger Pesho"
        self.assertEqual(expect, actual)

        self.assertEqual(1, len(self.train.passengers))

    def test_add__when_train_is_full__expect_to_raise_exception(self):
        self.train.add('Pesho')
        self.train.add('Pesho1')
        self.train.add('Pesho2')
        self.train.add('Pesho3')
        self.train.add('Pesho4')
        with self.assertRaises(ValueError) as ex:
            self.train.add('Pesho5')

        actual = self.TRAIN_FULL
        expect = "Train is full"
        self.assertEqual(expect, actual)

        actual2 = str(ex.exception)
        self.assertEqual(expect, actual2)

        self.assertEqual(5, len(self.train.passengers))

    def test_add__when_passenger_exists__expect_to_raise_exception(self):
        self.train.add('Pesho')
        with self.assertRaises(ValueError) as ex:
            self.train.add('Pesho')

        actual = self.PASSENGER_EXISTS.format('Pesho')
        expect = "Passenger Pesho Exists"
        self.assertEqual(expect, actual)

        actual2 = str(ex.exception)
        self.assertEqual(expect, actual2)

        self.assertEqual(1, len(self.train.passengers))

    def test_remove__expect_to_remove_passenger(self):
        self.train.add('Pesho')
        self.assertEqual(1, len(self.train.passengers))
        self.train.remove('Pesho')

        actual = self.PASSENGER_REMOVED.format('Pesho')
        expect = "Removed Pesho"
        self.assertEqual(expect, actual)
        self.assertEqual(0, len(self.train.passengers))

    def test_remove__when_passenger_not_exists__expect_to_raise_exception(
            self):
        with self.assertRaises(ValueError) as ex:
            self.train.remove('Pesho')

        actual = self.PASSENGER_NOT_FOUND.format('Pesho')
        expect = "Passenger Not Found"
        self.assertEqual(expect, actual)

        actual2 = str(ex.exception)
        self.assertEqual(expect, actual2)
        self.assertEqual(0, len(self.train.passengers))
Esempio n. 18
0
 def setUp(self):
     self.train = Train("Train", 2)
Esempio n. 19
0
    def test_init_shouldInitialize(self):
        train = Train('test name', 100)

        self.assertEqual('test name', train.name)
        self.assertEqual(100, train.capacity)
        self.assertEqual([], train.passengers)
Esempio n. 20
0
class TrainTests(unittest.TestCase):
    def setUp(self):
        self.train = Train("Orient", 50)

    def test_init__expect_attributes_to_be_set(self):
        self.assertEqual("Orient", self.train.name)
        self.assertEqual(50, self.train.capacity)
        self.assertEqual([], self.train.passengers)

    def test_class_attributes__expect_to_be_set(self):
        self.assertEqual("Train is full", self.train.TRAIN_FULL)
        self.assertEqual("Passenger {} Exists", self.train.PASSENGER_EXISTS)
        self.assertEqual("Passenger Not Found", self.train.PASSENGER_NOT_FOUND)
        self.assertEqual("Added passenger {}", self.train.PASSENGER_ADD)
        self.assertEqual("Removed {}", self.train.PASSENGER_REMOVED)
        self.assertEqual(0, self.train.ZERO_CAPACITY)

    def test_add__expect_to_add_passenger_and_return_msg(self):
        expected_message = "Added passenger john"
        actual_message = self.train.add("john")
        self.assertEqual(expected_message, actual_message)
        self.assertEqual(["john"], self.train.passengers)

    def test_add__when_capacity_is_full_expect_value_error(self):
        self.train.capacity = 0
        with self.assertRaises(ValueError) as err:
            self.train.add("john")
        self.assertEqual("Train is full", str(err.exception))

    def test_add__when_passenger_already_in_passengers_expect_value_error(self):
        self.train.add("john")
        with self.assertRaises(ValueError) as err:
            self.train.add("john")
        self.assertEqual("Passenger john Exists", str(err.exception))

    def test_remove__expect_to_remove_passenger_and_return_msg(self):
        self.train.add("john")
        expected_message = "Removed john"
        actual_message = self.train.remove("john")
        self.assertEqual(expected_message, actual_message)
        self.assertEqual([], self.train.passengers)

    def test_remove__when_passenger_not_in_passengers__expect_value_error(self):
        with self.assertRaises(ValueError) as err:
            self.train.remove("john")
        self.assertEqual("Passenger Not Found", str(err.exception))
Esempio n. 21
0
class TestTrain(unittest.TestCase):
    def setUp(self):
        self.train = Train("TestTrain", 10)

    def test_init(self):
        self.assertEqual("TestTrain", self.train.name)
        self.assertEqual(10, self.train.capacity)
        self.assertEqual([], self.train.passengers)

    def test_train_add__when_there_is_no_capacity__expect_value_error(self):
        self.train.capacity = 0
        with self.assertRaises(ValueError) as context:
            self.train.add("test_passenger")

        self.assertEqual("Train is full", str(context.exception))

    def test_train_add__when_passenger_name_is_in_passenger_list__expect_value_error(
            self):
        self.train.add("test")
        with self.assertRaises(ValueError) as context:
            self.train.add("test")

        self.assertEqual("Passenger test Exists", str(context.exception))

    def test_train_add__expect_to_add_it_and_return_message(self):
        self.assertEqual("Added passenger test", self.train.add("test"))
        self.assertEqual(["test"], self.train.passengers)

    def test_train_remove__when_passenger_not_in_passengers__expect_value_error(
            self):
        with self.assertRaises(ValueError) as context:
            self.train.remove("test")

        self.assertEqual("Passenger Not Found", str(context.exception))

    def test_train_remove__expect_to_remove_it_and_return_message(self):
        self.train.add("test")
        self.assertEqual("Removed test", self.train.remove("test"))
        self.assertEqual([], self.train.passengers)
Esempio n. 22
0
class TestTrain(TestCase):
    def setUp(self):
        self.train = Train("Test", 10)

    def test_initializing_all_attributes(self):
        self.assertEqual("Test", self.train.name)
        self.assertEqual(10, self.train.capacity)
        self.assertListEqual([], self.train.passengers)

    def test_add_passenger_when_train_full_raises(self):
        self.train.capacity = 0
        with self.assertRaises(ValueError) as ex:
            self.train.add("TestPassenger")

        self.assertListEqual([], self.train.passengers)
        self.assertEqual("Train is full", str(ex.exception))

    def test_add_exist_passenger_raises(self):
        self.train.add("TestPassenger")

        with self.assertRaises(ValueError) as ex:
            self.train.add("TestPassenger")

        self.assertListEqual(["TestPassenger"], self.train.passengers)
        self.assertEqual("Passenger TestPassenger Exists", str(ex.exception))

    def test_add_passenger(self):
        self.assertListEqual([], self.train.passengers)
        self.train.add("TestPassenger")
        self.assertListEqual(["TestPassenger"], self.train.passengers)

    def test_remove_not_exist_passenger_raises(self):
        with self.assertRaises(ValueError) as ex:
            self.train.remove("TestPassenger")

        self.assertEqual("Passenger Not Found", str(ex.exception))

    def test_remove_passenger(self):
        self.train.add("TestPassenger")
        self.assertListEqual(["TestPassenger"], self.train.passengers)
        self.train.remove("TestPassenger")
        self.assertListEqual([], self.train.passengers)
Esempio n. 23
0
 def setUp(self):
     self.train = Train("Orient", 50)
Esempio n. 24
0
 def setUp(self):
     self.train = Train('a', 1)
Esempio n. 25
0
class TestTrain(unittest.TestCase):
    def setUp(self):
        self.train = Train('a', 1)

    def test_constructor(self):
        self.assertEqual('a', self.train.name)
        self.assertEqual(1, self.train.capacity)
        self.assertEqual([], self.train.passengers)

    def test_add_passenger_train_full(self):
        self.train.passengers = ['bridget']
        with self.assertRaises(ValueError):
            self.train.add('tony')

    def test_add_passenger_passenger_exists_already(self):
        self.train.passengers = ['bridget']
        with self.assertRaises(ValueError):
            self.train.add('bridget')

    def test_add_passenger_correctly(self):
        self.train.add('bridget')
        self.assertEqual(['bridget'], self.train.passengers)

    def test_remove_passenger_error_not_in_list(self):
        with self.assertRaises(ValueError):
            self.train.remove('Bridget')

    def test_remove_passenger_correctly(self):
        self.train.add('bridget')
        self.train.remove('bridget')
        self.assertEqual([], self.train.passengers)
Esempio n. 26
0
 def setUp(self):
     self.train = Train("Test", 10)
Esempio n. 27
0
class TestTrain(TestCase):
    def setUp(self):
        self.train = Train('Test name', 2)

    def test_init__expect_to_set_attributes_correctly(self):
        self.assertEqual('Test name', self.train.name)
        self.assertEqual(2, self.train.capacity)
        self.assertEqual([], self.train.passengers)

    def test_add__when_enough_space__expect_to_add_passenger_to_the_list(self):
        self.train.add('Passenger name')

        self.assertEqual(1, len(self.train.passengers))
        self.assertEqual("Added passenger Passenger name",
                         self.train.PASSENGER_ADD.format('Passenger name'))

    def test_add__when_not_enough_space__expect_exception(self):
        self.train.add('Passenger name')
        self.train.add('Passenger name2')

        with self.assertRaises(ValueError) as ex:
            self.train.add('Passenger name3')

        self.assertEqual("Train is full", str(ex.exception))

    def test_add__when_passenger_name_exist__expect_exception(self):
        self.train.add('Passenger name')
        self.assertListEqual(['Passenger name'], self.train.passengers)

        with self.assertRaises(ValueError) as ex:
            self.train.add('Passenger name')

        self.assertEqual("Passenger Passenger name Exists", str(ex.exception))

    def test_remove__when_passenger_exist__expect_to_remove_from_the_list(
            self):
        self.train.add('Passenger name')
        self.assertListEqual(['Passenger name'], self.train.passengers)

        self.train.remove('Passenger name')
        self.assertEqual([], self.train.passengers)
        self.assertEqual("Removed Passenger name",
                         self.train.PASSENGER_REMOVED.format('Passenger name'))

    def test_remove__when_passenger_not_exist__expect_exception(self):
        with self.assertRaises(ValueError) as ex:
            self.train.remove('Passenger name')

        self.assertEqual("Passenger Not Found", str(ex.exception))
Esempio n. 28
0
 def setUp(self):
     self.train = Train('Test name', 2)
Esempio n. 29
0
 def setUp(self) -> None:
     self.train = Train('test_name', 30)
Esempio n. 30
0
 def setUp(self) -> None:
     self.train = Train('BDJ', 50)