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())
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))
def test_transit_adopble(self): view_est_mod = ViewEstablishmentModule(0, self.resolver, 6, 1) pred_module = PredicatesAndAction(view_est_mod, 0, self.resolver, 6, 1) view_est_mod.get_phs = MagicMock(return_value=0) # Mocks sets which union does not add up to 4, should return false pred_module.transit_set = MagicMock(return_value={1}) pred_module.same_v_set = MagicMock(return_value={1, 2, 3}) self.assertFalse( pred_module.transit_adopble(0, 0, ViewEstablishmentEnums.FOLLOW)) # Mocks sets which union adds up to 4, should return true pred_module.same_v_set = MagicMock(return_value={2, 3, 4}) self.assertTrue( pred_module.transit_adopble(0, 0, ViewEstablishmentEnums.REMAIN))