Ejemplo n.º 1
0
    def test_establishable(self):
        view_est_mod = ViewEstablishmentModule(0, self.resolver, 2, 0)
        pred_module = PredicatesAndAction(view_est_mod, 0, self.resolver, 2, 0)

        # Mocks sets that does not add up to , should return false
        view_est_mod.get_phs = MagicMock(return_value=0)
        pred_module.transit_set = MagicMock(return_value=set())
        pred_module.same_v_set = MagicMock(return_value=set())
        self.assertFalse(
            pred_module.establishable(0, ViewEstablishmentEnums.FOLLOW))

        # Mocks sets that adds up to over 1 , should return true
        pred_module.transit_set = MagicMock(return_value={1})
        pred_module.same_v_set = MagicMock(return_value={1})
        self.assertTrue(
            pred_module.establishable(0, ViewEstablishmentEnums.REMAIN))
Ejemplo n.º 2
0
    def test_automaton_phase_1_predicates(self):
        view_est_mod = ViewEstablishmentModule(0, self.resolver, 2, 0)
        pred_module = PredicatesAndAction(view_est_mod, 0, self.resolver, 2, 0)

        # Case 0
        pred_module.views = [{CURRENT: 0, NEXT: 4}, {CURRENT: 1, NEXT: 1}]
        pred_module.transit_adopble = MagicMock(return_value=True)
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 1, 0))

        # Not a adoptable view in transit
        pred_module.transit_adopble = MagicMock(return_value=False)
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 1, 0))
        # The adoptable view is the same as processor i
        pred_module.views = [{CURRENT: 0, NEXT: 0}, {CURRENT: 0, NEXT: 0}]
        pred_module.transit_adopble = MagicMock(return_value=True)
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 1, 0))

        # Case 1
        pred_module.establishable = MagicMock(return_value=True)
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 1, 1))
        # The threshold to move to a view change is not fulfilled
        pred_module.establishable = MagicMock(return_value=False)
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 1, 1))

        # Case 2
        # There is not an adoptable view in transit
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 1, 2))
        # There is not an adoptable view in transit
        pred_module.transit_adopble = MagicMock(return_value=False)
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 1, 2))

        # Case 3 should return True
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 1, 3))
Ejemplo n.º 3
0
    def test_automaton_phase_0_predicates(self):
        view_est_mod = ViewEstablishmentModule(0, self.resolver, 2, 0)
        pred_module = PredicatesAndAction(view_est_mod, 0, self.resolver, 2, 0)

        # Case 0
        pred_module.views = [{CURRENT: 0, NEXT: 0}, {CURRENT: 1, NEXT: 1}]
        pred_module.transit_adopble = MagicMock(return_value=True)
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 0))
        # Not a adoptable view in transit
        pred_module.transit_adopble = MagicMock(return_value=False)
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 0))
        # The adoptable view is the same as processor i
        pred_module.views = [{CURRENT: 0, NEXT: 0}, {CURRENT: 0, NEXT: 0}]
        pred_module.transit_adopble = MagicMock(return_value=True)
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 0))

        # Case 1b
        pred_module.vChange = [False for i in range(2)]
        pred_module.establishable = MagicMock(return_value=True)
        pred_module.views[pred_module.id] = pred_module.RST_PAIR
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 1))

        # Case 1a
        pred_module.views[pred_module.id] = {
            "current": 1,
            "next": 1
        }  # NOT the RST_PAIR
        pred_module.establishable = MagicMock(return_value=True)
        pred_module.vChange = [True for i in range(2)]
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 1))
        # View change is not required
        pred_module.vChange = [False for i in range(2)]
        pred_module.views[1] = {"current": 1, "next": 1}
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 1))
        # The threshold to move to a view change is not fulfilled
        pred_module.establishable = MagicMock(return_value=False)
        pred_module.vChange = [True for i in range(2)]
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 1))

        # Case 2
        # There is a adoptable view in transit
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 2))
        # None of the condition is fulfilled
        pred_module.transit_adopble = MagicMock(return_value=False)
        self.assertFalse(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 2))
        # Processor i view_pair is the default pair
        pred_module.views[pred_module.id] = pred_module.RST_PAIR
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 2))

        # Case 3 should return True
        self.assertTrue(
            pred_module.automation(ViewEstablishmentEnums.PREDICATE, 0, 3))