def test_emotions_self_action(self): """Test emotions for an action by an agent with multiple entities.""" hit = Action() hit.name = "Hit" agent = Agent(0, 0, 0, 0, 0) agent_entity_id_1 = agent.entity_id agent_entity_id_2 = 'test_123' preferences = agent.get_preferences() preferences.set_goodness(hit, -1) preferences.set_praiseworthiness(hit, -1) preferences.set_love(agent_entity_id_1, 1) preferences.set_love(agent_entity_id_2, 1) timestamp = 0 truth_value = 1 agent.beliefs.register_entity(agent_entity_id_1) agent.beliefs.register_entity(agent_entity_id_2) agent.beliefs.set_entity_is_entity( timestamp, agent_entity_id_1, agent_entity_id_2, truth_value ) prob = 1 emotions = agent.emotions_for_action( hit, agent_entity_id_1, agent_entity_id_2, prob) self.assertEqual(len(emotions), 2) # Feeling bad for hitting someone agent loves (agent) self.assertIsInstance(emotions[0], Remorse) # Feeling bad for being hit (by agent) self.assertIsInstance(emotions[1], Distress)
def test_set_get_preferences(self): action = Action() action.name = "test_action" p = Preferences() p.set_goodness(action, 1) agent = Agent(0, 0, 0, 0, 0) agent.set_preferences(p) p_returned = agent.get_preferences() self.assertEqual(p_returned.get_goodness(action), 1)
def test_apply_action(self): subject_agent = Agent(0, 0, 0, 0, 0) object_agent = Agent(0, 0, 0, 0, 0) viewer_agent = Agent(0, 0, 0, 0, 0) viewer_preferences = viewer_agent.get_preferences() viewer_preferences.set_love(subject_agent.entity_id, 1) viewer_preferences.set_love(object_agent.entity_id, 1) viewer_preferences.set_praiseworthiness(Kill, -1) viewer_preferences.set_goodness(Kill, -1) apply_action( action=Kill, subject=subject_agent, obj=object_agent, viewers=[viewer_agent] ) self.assertEqual(len(viewer_agent.emotions), 2)
def test_emotions_for_action(self): subject = Agent(0, 0, 0, 0, 0) obj = Agent(0, 0, 0, 0, 0) observer = Agent(0, 0, 0, 0, 0) hit = Action() hit.name = "Hit" preferences = observer.get_preferences() preferences.set_goodness(hit, -1) preferences.set_praiseworthiness(hit, -1) preferences.set_love(subject.entity_id, 1) preferences.set_love(obj.entity_id, -1) prob = 1 emotions = observer.emotions_for_action( hit, subject.entity_id, obj.entity_id, prob) self.assertEqual(len(emotions), 2) self.assertIsInstance(emotions[0], Anger) self.assertIsInstance(emotions[1], Gloating)
def test_emotions_for_multiple_object_entities(self): """Test emotions for an object represented as multiple entities.""" hit = Action() hit.name = "Hit" object_entity_id_1 = '123a' object_entity_id_2 = '123b' subject_entity_id = '456' observer = Agent(0, 0, 0, 0, 0) preferences = observer.get_preferences() preferences.set_goodness(hit, -1) preferences.set_praiseworthiness(hit, -1) preferences.set_love(object_entity_id_1, 1) preferences.set_love(object_entity_id_2, -1) preferences.set_love(subject_entity_id, 1) timestamp = 0 truth_value = 1 observer.beliefs.register_entity(object_entity_id_1) observer.beliefs.register_entity(object_entity_id_2) observer.beliefs.set_entity_is_entity( timestamp, object_entity_id_1, object_entity_id_2, truth_value ) prob = 1 emotions = observer.emotions_for_action( hit, subject_entity_id, object_entity_id_1, prob) self.assertEqual(len(emotions), 3) # Anger towards the person who hit (a bad thing to do) self.assertIsInstance(emotions[0], Anger) # Sorry for the loved person being hit self.assertIsInstance(emotions[1], SorryFor) # Gloating over the hated person being hit self.assertIsInstance(emotions[2], Gloating)