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())
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))
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_interface_allow_service(self): view_est_mod = ViewEstablishmentModule(0, self.resolver, 6, 1) pred_module = PredicatesAndAction(view_est_mod, 0, self.resolver, 6, 1) # Allow service settings view_est_mod.get_phs = MagicMock(return_value=0) pred_module.views = [{CURRENT: 0, NEXT: 0}] pred_module.same_v_set = MagicMock(return_value={0, 1, 2, 3, 4, 5}) self.assertTrue(pred_module.allow_service()) #Deny service settings, creating a false statement for each condition view_est_mod.get_phs = MagicMock(return_value=1) self.assertFalse(pred_module.allow_service()) view_est_mod.get_phs = MagicMock(return_value=0) pred_module.views = [{CURRENT: 0, NEXT: 1}] self.assertFalse(pred_module.allow_service()) pred_module.views = [{CURRENT: 0, NEXT: 0}] pred_module.same_v_set = MagicMock(return_value={}) self.assertFalse(pred_module.allow_service())