def test_main(): # Not fully implemented assert 1==2 battery = Resource('battery power', ('potential',)) battery.set_values(0.401) suck_power = ResourceMap('suck power', 'delta', 'potential', ('reduction',)) b1 = Buzz('sound stimulation', ('band_1', 'band_2', 'band_3')) s1 = Sensor('sound in surrounding', listen, b1, suck_power) belief_1 = Belief('The word was spoken', ('probability',)) int1 = Interpreter('Was the word spoken?', word_estimator, b1, belief_1) dir_1 = Direction('follow up request', ('word_section_1', 'word_section_2', 'word_section_3', 'word_section_4')) moul1 = Moulder('What response to give', responder, belief_1, dir_1) a1 = Actuator('loudspeaker vibrations', loudspeaker_api, dir_1, suck_power) moul2 = Moulder('Select warn statement', warn_statement, None, dir_1, resource_op_input=battery) bc = AutoBeliefCondition('Sufficiently confident of word spoken', lambda p: p > 0.75, 'The word was spoken') rc = AutoResourceCondition('Sufficient power left', lambda pot: pot > 0.2, 'potential') clausul_1 = Clause('listen for the word', [('sense', 'sound in surrounding'), ('interpret', 'Was the word spoken?')], condition=bc) clausul_2 = Clause('say something to the user', [('mould', 'What response to give'), ('act', 'loudspeaker vibrations')]) clausul_3 = Clause('power check', condition=rc) clausul_4 = Clause('power warn', [('mould', 'Select warn statement'), ('act', 'loudspeaker vibrations')]) plan = Plan('Clever stuff') plan.add_cargo('pronounce', 'listen for the word') plan.add_cargo('pronounce', 'say something to the user') plan.add_cargo('pronounce', 'power check') plan.add_cargo('pronounce', 'power warn') plan.add_dependency(2, 0, 3) plan.add_dependency(0, 1) plan.stamp_and_approve() agent = Agent('smart loudspeaker') agent.set_organs(s1, int1, moul1, moul2, a1) agent.set_messages(b1, belief_1, dir_1) agent.set_scaffold(battery) agent.set_policies(clausul_1, clausul_2, clausul_3, clausul_4, plan) agent.enact('Clever stuff') agent.enact('Clever stuff') agent.enact('Clever stuff') agent.enact('Clever stuff')
def test_main(): belief = Belief('dummy', ('a1', )) resource = Resource('internal energy', ('level', )) mapper = ResourceMap('eat energy', 'delta', 'level', ('shift', )) interpreter1 = Interpreter('thinker', lambda x: (x + 1, -1), belief, belief, resource_map_output=mapper) interpreter2 = Interpreter('thinker X', lambda x: (x + 1, -3), belief, belief, resource_map_output=mapper) battery = AutoResourceCondition('battery left', lambda x: x > 0) heart_1 = Heartbeat('big heart', battery, ticker_arithmetic=lambda: 2, max_ticker=4) heart_2 = Heartbeat('small heart', battery, ticker_arithmetic=lambda: 1, max_ticker=4) agent_1 = Agent('A1') agent_1.set_organs(interpreter1, interpreter2) belief.set_values([1]) resource.set_values([10]) agent_1.set_message(belief) agent_1.set_scaffold(resource) agent_1.set_policies(heart_1, heart_2) assert (agent_1.belief['dummy'].values()[0] == REF_B1[0]) assert (agent_1.inert == REF_I1[0]) agent_1.pump('big heart') agent_1.interpret('thinker') assert (agent_1.belief['dummy'].values()[0] == REF_B1[1]) assert (agent_1.inert == REF_I1[1]) agent_1.pump('big heart') agent_1.interpret('thinker') assert (agent_1.belief['dummy'].values()[0] == REF_B1[2]) assert (agent_1.inert == REF_I1[2]) agent_1.pump('big heart') agent_1.interpret('thinker') assert (agent_1.belief['dummy'].values()[0] == REF_B1[3]) assert (agent_1.inert == REF_I1[3]) agent_1.revive() assert (agent_1.inert == False) agent_1.pump('small heart') agent_1.interpret('thinker X') assert (agent_1.belief['dummy'].values()[0] == REF_B2[0]) assert (agent_1.inert == REF_I2[0]) agent_1.pump('small heart') agent_1.interpret('thinker X') assert (agent_1.belief['dummy'].values()[0] == REF_B2[1]) assert (agent_1.inert == REF_I2[1]) agent_1.pump('small heart') agent_1.interpret('thinker X') assert (agent_1.belief['dummy'].values()[0] == REF_B2[2]) assert (agent_1.inert == REF_I2[2]) agent_1.pump('small heart') agent_1.interpret('thinker X') assert (agent_1.belief['dummy'].values()[0] == REF_B2[3]) assert (agent_1.inert == REF_I2[3]) agent_1.pump('small heart') agent_1.interpret('thinker X') assert (agent_1.belief['dummy'].values()[0] == REF_B2[4]) assert (agent_1.inert == REF_I2[4])