コード例 #1
0
    def test_transit_set(self):
        view_est_mod = ViewEstablishmentModule(0, self.resolver, 2, 0)
        pred_module = PredicatesAndAction(view_est_mod, 0, self.resolver, 2, 0)

        # All is well
        view_est_mod.get_phs = MagicMock(return_value=0)
        pred_module.stale_v = MagicMock(return_value=False)
        pred_module.transition_cases = MagicMock(return_value=True)
        self.assertEqual(
            pred_module.transit_set(0, 1, ViewEstablishmentEnums.FOLLOW),
            {0, 1})

        # Different phases, node 0 in phase 1 and node 1 in phase 0
        view_est_mod.get_phs = MagicMock(side_effect=lambda x: (x + 1) % 2)
        self.assertEqual(
            pred_module.transit_set(0, 1, ViewEstablishmentEnums.FOLLOW), {1})

        # Transition case returns false
        view_est_mod.get_phs = MagicMock(return_value=0)
        pred_module.transition_cases = MagicMock(return_value=False)
        self.assertEqual(
            pred_module.transit_set(0, 1, ViewEstablishmentEnums.FOLLOW),
            set())

        # Both processors are stale
        pred_module.stale_v = MagicMock(return_value=True)
        pred_module.transition_cases = MagicMock(return_value=True)
        self.assertEqual(
            pred_module.transit_set(0, 1, ViewEstablishmentEnums.FOLLOW),
            set())
コード例 #2
0
    def test_same_v_set(self):
        view_est_mod = ViewEstablishmentModule(0, self.resolver, 2, 0)
        pred_module = PredicatesAndAction(view_est_mod, 0, self.resolver, 2, 0)

        # Both processors are in the same view and phase
        view_est_mod.get_phs = MagicMock(return_value=0)
        pred_module.stale_v = MagicMock(return_value=False)
        pred_module.views = [{CURRENT: 0, NEXT: 0}, {CURRENT: 0, NEXT: 0}]
        self.assertEqual(pred_module.same_v_set(0, 0), {0, 1})

        # Processor 1 is not in the same view and but same phase
        pred_module.views = [{CURRENT: 0, NEXT: 0}, {CURRENT: 0, NEXT: 1}]
        self.assertEqual(pred_module.same_v_set(0, 0), {0})

        # Processor 1 is in the same view and but not in same phase
        view_est_mod.get_phs = MagicMock(
            side_effect=lambda x: x
        )  # Returns the input value (works for this specific case)
        pred_module.views = [{CURRENT: 0, NEXT: 0}, {CURRENT: 0, NEXT: 0}]
        self.assertEqual(pred_module.same_v_set(0, 0), {0})

        # Processors are stale, should return empty set
        view_est_mod.get_phs = MagicMock(return_value=0)
        pred_module.stale_v = MagicMock(return_value=True)
        pred_module.views = [{CURRENT: 0, NEXT: 0}, {CURRENT: 0, NEXT: 0}]
        self.assertEqual(pred_module.same_v_set(0, 0), set())
コード例 #3
0
    def test_need_reset(self):
        view_est_mod = ViewEstablishmentModule(0, self.resolver, 2, 0)
        pred_module = PredicatesAndAction(view_est_mod, 0, self.resolver, 2, 0)

        pred_module.stale_v = MagicMock(return_value=True)
        self.resolver.execute = MagicMock(return_value=True)
        self.assertTrue(pred_module.need_reset())

        pred_module.stale_v = MagicMock(return_value=False)
        self.assertTrue(pred_module.need_reset())

        self.resolver.execute = MagicMock(return_value=False)
        self.assertFalse(pred_module.need_reset())
コード例 #4
0
    def test_stale_v(self):
        view_est_mod = ViewEstablishmentModule(0, self.resolver, 2, 0)
        pred_module = PredicatesAndAction(view_est_mod, 0, self.resolver, 2, 0)

        # Stale and in phase 0
        view_est_mod.get_phs = MagicMock(return_value=0)
        pred_module.legit_phs_zero = MagicMock(return_value=False)
        pred_module.legit_phs_one = MagicMock(return_value=False)
        self.assertTrue(pred_module.stale_v(0))
        # Stale and in phase 1
        view_est_mod.get_phs = MagicMock(return_value=1)
        self.assertTrue(pred_module.stale_v(0))
        # Not stale
        pred_module.legit_phs_one = MagicMock(return_value=True)
        self.assertFalse(pred_module.stale_v(0))