Exemple #1
0
    def test_transmit_selector_all_of_type(self):
        net = models.Network()
        self.db.add(net)

        # Create a network of two biological nodes.
        agent1 = nodes.ReplicatorAgent(network=net)
        agent2 = nodes.ReplicatorAgent(network=net)

        agent1.connect(direction="to", whom=agent2)

        information.Meme(origin=agent1, contents="foo1")
        information.Meme(origin=agent1, contents="foo2")
        information.Meme(origin=agent1, contents="foo3")
        information.Gene(origin=agent1, contents="bar")

        assert len(agent1.infos(type=Meme)) == 3
        assert len(agent2.infos(type=Meme)) == 0
        assert len(agent1.infos(type=Gene)) == 1
        assert len(agent2.infos(type=Gene)) == 0

        # Transmit memes from agent 1 to 2.
        agent1.transmit(what=information.Meme, to_whom=agent2)

        # Receive the transmission.
        agent2.receive()

        # Make sure that Agent 2 has a blank memome and the right gene.
        assert not agent2.infos(type=Gene)
        assert len(agent2.infos(type=Meme)) == 3
    def test_create_genome(self, db_session):
        net = models.Network()
        db_session.add(net)
        node = models.Node(network=net)
        info = information.Gene(origin=node)
        db_session.commit()

        assert info.type == "gene"
        assert info.contents is None