Beispiel #1
0
 def test_generate_items(self):
     simulation = Simulation(users_count=3,
                             max_books_per_user=3,
                             exchange_points_count=5)
     simulation.generate_items()
     self.assertTrue(len(simulation.all_books) > 0)
     self.assertTrue(len(simulation.all_users) > 0)
     self.assertTrue(len(simulation.all_exchange_points) > 0)
Beispiel #2
0
    def test_points_chaining(self):
        sim = Simulation(users_count=2, max_books_per_user=2, exchange_points_count=3)
        sim.exchange_point_capacity = 5
        sim.generate_items()
        test_point = sim.get_last_exchange_point()

        for _ in range(0,15):
            test_point.put_book(simulation_item_factory.create_simulation_book())

        for point in sim.all_exchange_points:
            self.assertTrue(len(point.stored_books)>0)
Beispiel #3
0
    def test_otp_execution(self):
        simulation = Simulation(users_count=2, max_books_per_user=2, exchange_points_count=1)
        simulation.generate_items()

        TransactionsLogic.move_books_from_owners_to_points(simulation)
        point = simulation.get_last_exchange_point()
        self.assertTrue(len(point.stored_books) > 0)  # point received some books as result of transaction

        moved_book = point.stored_books[0]
        one_user = simulation.all_users[0]
        self.assertTrue(moved_book not in one_user.own_books)  # user has no book which is moved to exchange point
Beispiel #4
0
    def test_points_chaining(self):
        sim = Simulation(users_count=2,
                         max_books_per_user=2,
                         exchange_points_count=3)
        sim.exchange_point_capacity = 5
        sim.generate_items()
        test_point = sim.get_last_exchange_point()

        for _ in range(0, 15):
            test_point.put_book(
                simulation_item_factory.create_simulation_book())

        for point in sim.all_exchange_points:
            self.assertTrue(len(point.stored_books) > 0)
Beispiel #5
0
    def test_otp_execution(self):
        simulation = Simulation(users_count=2,
                                max_books_per_user=2,
                                exchange_points_count=1)
        simulation.generate_items()

        TransactionsLogic.move_books_from_owners_to_points(simulation)
        point = simulation.get_last_exchange_point()
        self.assertTrue(
            len(point.stored_books) >
            0)  # point received some books as result of transaction

        moved_book = point.stored_books[0]
        one_user = simulation.all_users[0]
        self.assertTrue(moved_book not in one_user.own_books
                        )  # user has no book which is moved to exchange point
Beispiel #6
0
    def test_users_mediation(self):

        # simulation inherit MediatorMixin
        simulation = Simulation(users_count=2, max_books_per_user=2, exchange_points_count=1)
        simulation.generate_items()

        # each user inherit ColleagueMixin
        for user in simulation.all_users:
            user.set_mediator(simulation)

        simulation.broadcast_message_to_colleagues('Broadcasted message')
        user_colleague = simulation.all_users[0]
        user_colleague.send_message_to_mediator('new message')

        self.assertEqual(user_colleague.mediator, simulation)
        self.assertTrue(user_colleague in simulation.colleagues)
Beispiel #7
0
    def test_users_mediation(self):

        # simulation inherit MediatorMixin
        simulation = Simulation(users_count=2,
                                max_books_per_user=2,
                                exchange_points_count=1)
        simulation.generate_items()

        # each user inherit ColleagueMixin
        for user in simulation.all_users:
            user.set_mediator(simulation)

        simulation.broadcast_message_to_colleagues('Broadcasted message')
        user_colleague = simulation.all_users[0]
        user_colleague.send_message_to_mediator('new message')

        self.assertEqual(user_colleague.mediator, simulation)
        self.assertTrue(user_colleague in simulation.colleagues)
Beispiel #8
0
 def test_generate_items(self):
     simulation = Simulation(users_count=3, max_books_per_user=3, exchange_points_count=5)
     simulation.generate_items()
     self.assertTrue(len(simulation.all_books) > 0)
     self.assertTrue(len(simulation.all_users) > 0)
     self.assertTrue(len(simulation.all_exchange_points) > 0)