Ejemplo n.º 1
0
    def test_su_add_to_network(self):
        """
        Test that the state update function did add the Participant to the
        network, and that the network maintained its integrity (i.e. all edges
        were properly setup)
        """
        with patch("network_utils.influence") as p:
            p.return_value = 0.8

            n_old_len = len(self.network.nodes)

            _input = {
                "new_participant": True,
                "new_participant_investment": 16.872149388283283,
                "new_participant_tokens": 1.0545093367677052
            }
            _, network = GenerateNewParticipant.su_add_to_network(
                self.params, 0, 0, {"network": self.network.copy()}, _input)
            network_len = len(network.nodes)

            self.assertEqual(n_old_len, 5)
            self.assertEqual(network_len, 6)
            self.assertEqual(
                network.nodes(data="item")[5].holdings.total,
                1.0545093367677052)

            # There are 4 Participants in the network, all of them should have
            # influence edges to the newly added Participant.
            self.assertEqual(len(network.in_edges(5)), 4)
            # Check that all of these edges are support type edges.
            for u, v in network.in_edges(5):
                self.assertEqual(network.edges[u, v]["type"], "influence")
Ejemplo n.º 2
0
 def test_p_randomly(self):
     """
     Simply test that the code runs.
     """
     state = {"commons": self.commons, "sentiment": self.sentiment}
     self.params["probability_func"] = always
     ans = GenerateNewParticipant.p_randomly(self.params, 0, 0, state)
     self.assertEqual(ans["new_participant"], True)
     self.assertIsNotNone(ans["new_participant_investment"])
     self.assertIsNotNone(ans["new_participant_tokens"])
Ejemplo n.º 3
0
 def test_p_randomly(self):
     """
     Simply test that the code runs.
     """
     state = {"commons": self.commons, "sentiment": self.sentiment}
     with patch("policies.probability") as p:
         p.return_value = True
         ans = GenerateNewParticipant.p_randomly(self.params, 0, 0, state)
         self.assertEqual(ans["new_participant"], True)
         self.assertIsNotNone(ans["new_participant_investment"])
         self.assertIsNotNone(ans["new_participant_tokens"])
Ejemplo n.º 4
0
 def test_su_update_participants_token_batch_age(self):
     """
     Test that after running the state update function the participants'
     token batch age in days are incremented by one
     """
     _input = {}
     _, network = GenerateNewParticipant.su_update_participants_token_batch_age(
         self.params, 0, 0, {"network": self.network.copy()}, _input)
     participants = get_participants(network)
     for i, participant in participants:
         self.assertEqual(participant.holdings.age_days, 1)
Ejemplo n.º 5
0
    def test_su_add_investment_to_commons(self):
        old_token_supply = self.commons._token_supply
        old_collateral_pool = self.commons._collateral_pool
        commons = GenerateNewParticipant.su_add_investment_to_commons(
            self.params, 0, 0, {"commons": self.commons}, {})

        # Check if case there is no new participant, the token supply and
        # the collateral pool do not change.
        self.assertEqual(self.commons._token_supply, old_token_supply)
        self.assertEqual(self.commons._collateral_pool, old_collateral_pool)
        _input = {
            0: {
                "new_participant_investment": 16.872149388283283,
                "new_participant_tokens": 1.0545093367677052
            }
        }
        GenerateNewParticipant.su_add_investment_to_commons(
            self.params, 0, 0, {"commons": self.commons}, _input)

        self.assertEqual(self.commons._token_supply, 1001.0539539273273)
        self.assertEqual(self.commons._collateral_pool, 8016.872149388283)