def test_setup_influence_edges_single_wont_overwrite_existing_influences(
            self):
        """
        Test that setup_influence_edges_single will not overwrite existing
        influence edges.
        """
        with patch('network_utils.influence') as mock:
            mock.return_value = 0.5
            self.network = setup_influence_edges_single(self.network, 0)
            edges = list(get_edges_by_type(self.network, "influence"))
            self.assertEqual(len(edges), 8)

            # First, check that the influence edges all have the original
            # influence value of 0.5
            for e in edges:
                self.assertEqual(
                    self.network.get_edge_data(e[0], e[1])["influence"], 0.5)

            # Now, ensure that the original influence value of 0.5 was not
            # overwritten with 0.8
            mock.return_value = 0.8
            self.network = setup_influence_edges_single(self.network, 0)
            edges = list(get_edges_by_type(self.network, "influence"))
            self.assertEqual(len(edges), 8)
            for e in edges:
                self.assertEqual(
                    self.network.get_edge_data(e[0], e[1])["influence"], 0.5)
    def test_setup_influence_edges_single(self):
        """
        Test that the code works, and that if I set up influence edges for a
        Participant in a network where he has 4 peers, 8 edges will be created,
        4 from the new Participant to the existing Participants + 4 from
        the existing Participants to the new Participant
        """
        with patch('network_utils.influence') as mock:
            mock.return_value = 0.5
            self.network = setup_influence_edges_single(self.network, 0)
            edges = list(get_edges_by_type(self.network, "influence"))
            self.assertEqual(len(edges), 8)
            for e in edges:
                self.assertIsInstance(e[0], int)
                self.assertIsInstance(e[1], int)
                self.assertNotEqual(e[0], e[1])

            # Test that Participant 0 has 4 edges to other Participants, and
            # that other Participants (like Participant 2) only have 1 edge to
            # Participant 0.
            a = tuple(zip(*edges))
            self.assertEqual(a[0].count(0), 4)
            self.assertEqual(a[0].count(2), 1)
            self.assertEqual(a[1].count(0), 4)
            self.assertEqual(a[1].count(2), 1)
示例#3
0
 def su_add_to_network(params, step, sL, s, _input):
     network = s["network"]
     if _input["new_participant"]:
         i = len(network.nodes)
         network.add_node(i, item=Participant(
             holdings_vesting=None, holdings_nonvesting=TokenBatch(_input["new_participant_tokens"])))
         network = setup_influence_edges_single(network, i)
         network = setup_support_edges(network, i)
     return "network", network
示例#4
0
 def su_add_to_network(params, step, sL, s, _input, **kwargs):
     network = s["network"]
     if _input["new_participant"]:
         i = len(network.nodes)
         network.add_node(i,
                          item=Participant(
                              TokenBatch(0,
                                         _input["new_participant_tokens"])))
         network = setup_influence_edges_single(network, i)
         network = setup_support_edges(network, i)
         if params[0].get("debug"):
             print(
                 "GenerateNewParticipant: A new Participant {} invested {}DAI for {} tokens"
                 .format(i, _input['new_participant_investment'],
                         _input['new_participant_tokens']))
     return "network", network