Пример #1
0
    def test_notify(self):
        """Tests the notify method.

        :return: None
        """
        observable = base.Observable()
        observer1 = base.Observer()
        observer2 = base.Observer()

        observable.add_observer(observer1)
        observable.add_observer(observer2)

        observable.notify()
Пример #2
0
    def test_add_observer(self):
        """Tests the add observer method.

        :return: None
        """
        observable = base.Observable()
        observer1 = base.Observer()
        observer2 = base.Observer()
        test_observers = [observer1, observer2]

        observable.add_observer(observer1)
        observable.add_observer(observer2)

        for test_obs, ret_obs in zip(test_observers, observable.observers):
            self.assertIs(test_obs, ret_obs)
Пример #3
0
    def test_update(self):
        """Tests the observer update method.

        :return: None
        """
        observer = base.Observer()
        observer.update()
Пример #4
0
    def test_run(self):
        """Tests the run method.

        :return: None
        """
        observer = base.Observer()
        sim = simulation.Simulation()
        sim.add_observer(observer)
        sim.run(10)

        self.assertEqual(sim.current_time, 10)
Пример #5
0
    def test_remove_observer(self):
        """Tests the remove observer method.

        :return: None
        """
        observable = base.Observable()
        observer = base.Observer()

        observable.add_observer(observer)
        self.assertTrue(observable.observers)
        self.assertIs(observable.observers[0], observer)

        observable.remove_observer(observer)
        self.assertFalse(observable.observers)