コード例 #1
0
 def test_setup_support_edges_multiple(self):
     """
     Tests that support edges are created between every Participant and
     Proposal if no node index is specified.
     """
     network = setup_support_edges(self.network)
     self.assertEqual(len(network.edges), 25)
コード例 #2
0
 def test_calc_total_affinity(self):
     """
     Ensure that the affinities in the support edges add up to >0 (since they
     are randomly generated, they won't be 0)
     """
     self.network = setup_support_edges(self.network)
     ans = calc_total_affinity(self.network)
     self.assertNotEqual(ans, 0)
コード例 #3
0
    def test_get_edges_by_participant_and_type(self):
        self.network = setup_support_edges(self.network)
        res = get_edges_by_participant_and_type(self.network, 0, "support")

        # Assert that Participant 0 has support edges to all other Proposals
        # (1,3,5,7,9)
        for i in [1, 3, 5, 7, 9]:
            self.assertIn(i, res)
            self.assertEqual(res[i]["type"], "support")
コード例 #4
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
コード例 #5
0
 def test_setup_support_edges_single_proposal(self):
     """
     Tests that a support edge is created to other Participants when the
     function is fed a node that contains a Proposal
     """
     network = setup_support_edges(self.network, 1)
     for i, j in network.edges:
         self.assertEqual(j, 1)
         self.assertIsInstance(network.nodes[i]["item"], Participant)
         self.assertIsInstance(network.nodes[j]["item"], Proposal)
コード例 #6
0
 def test_setup_support_edges_single_participant(self):
     """
     Tests that a support edge is created to other Proposals when the
     function is fed a node that contains a Participant
     """
     network = setup_support_edges(self.network,
                                   self.params["random_number_func"], 0)
     for i, j in network.edges:
         self.assertEqual(i, 0)
         self.assertIsInstance(network.nodes[i]["item"], Participant)
         self.assertIsInstance(network.nodes[j]["item"], Proposal)
コード例 #7
0
 def test_get_proposals_conviction_list(self):
     """
     Test that the returning list of proposals' convictions is correct.
     """
     self.network = setup_support_edges(self.network,
                                        self.params["random_number_func"])
     conviction_list = get_proposals_conviction_list(self.network)
     expected_list = [
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0
     ]
     self.assertEqual(conviction_list, expected_list)
コード例 #8
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
コード例 #9
0
    def test_find_in_edges_of_type_for_proposal(self):
        """
        Ensure that only edges of the specified type are included in the answer
        """
        self.network = setup_support_edges(self.network)
        self.network = setup_conflict_edges(self.network, rate=1)

        s_edges = find_in_edges_of_type_for_proposal(self.network, 9,
                                                     "support")
        s_edges_expected = [(0, 9, 'support'), (2, 9, 'support'),
                            (4, 9, 'support'), (6, 9, 'support'),
                            (8, 9, 'support')]
        self.assertEqual(s_edges, s_edges_expected)

        c_edges = find_in_edges_of_type_for_proposal(self.network, 9,
                                                     "conflict")
        c_edges_expected = [(1, 9, 'conflict'), (3, 9, 'conflict'),
                            (5, 9, 'conflict'), (7, 9, 'conflict')]
        self.assertEqual(c_edges, c_edges_expected)
コード例 #10
0
    def test_calc_total_conviction(self):
        """
        Ensure that the function reports the correct sum of conviction from all
        support edges.
        """
        self.network = setup_support_edges(self.network)
        ans = calc_total_conviction(self.network, 1)
        self.assertEqual(ans, 0)

        support_edges = get_edges_by_type(self.network, "support")

        # Every support edge gets a conviction value. Since there are 5
        # Participants and 5 Proposals, this should result in a sum of 5
        # conviction for each Proposal.
        for u, v in support_edges:
            self.network.edges[u, v]["conviction"] = 1

        for i in [1, 3, 5, 7, 9]:
            ans = calc_total_conviction(self.network, i)
            self.assertEqual(ans, 5)