예제 #1
0
    def test_to_dict(self):
        """Test that conversion into dict works as expected."""
        version_id = "1"
        nb_agents = 3
        nb_goods = 3
        tx_fee = 1.0
        agent_pbk_to_name = {
            "tac_agent_0_pbk": "tac_agent_0",
            "tac_agent_1_pbk": "tac_agent_1",
            "tac_agent_2_pbk": "tac_agent_2",
        }
        good_pbk_to_name = {
            "tac_good_0_pbk": "tac_good_0",
            "tac_good_1_pbk": "tac_good_1",
            "tac_good_2_pbk": "tac_good_2",
        }
        money_amounts = [20, 20, 20]
        endowments = [[1, 1, 1], [2, 1, 1], [1, 1, 2]]
        utility_params = [[20.0, 40.0, 40.0], [10.0, 50.0, 40.0],
                          [40.0, 30.0, 30.0]]
        eq_prices = [1.0, 1.0, 4.0]
        eq_good_holdings = [[1.0, 1.0, 4.0], [1.0, 5.0, 1.0], [6.0, 1.0, 2.0]]
        eq_money_holdings = [20.0, 20.0, 20.0]

        game_configuration = GameConfiguration(version_id, nb_agents, nb_goods,
                                               tx_fee, agent_pbk_to_name,
                                               good_pbk_to_name)
        game_initialization = GameInitialization(
            money_amounts,
            endowments,
            utility_params,
            eq_prices,
            eq_good_holdings,
            eq_money_holdings,
        )

        game = Game(game_configuration, game_initialization)

        tx_id = "some_tx_id"
        sender_pbk = "tac_agent_0_pbk"
        counterparty_pbk = "tac_agent_1_pbk"
        transaction_1 = Transaction(tx_id, True, counterparty_pbk, 10,
                                    {"tac_good_0_pbk": 1}, sender_pbk)
        transaction_2 = Transaction(tx_id, False, counterparty_pbk, 10,
                                    {"tac_good_0_pbk": 1}, sender_pbk)
        game.settle_transaction(transaction_1)
        game.settle_transaction(transaction_2)

        actual_game_dict = game.to_dict()
        expected_game_dict = {
            "configuration": game_configuration.to_dict(),
            "initialization": game_initialization.to_dict(),
            "transactions": [transaction_1.to_dict(),
                             transaction_2.to_dict()],
        }

        assert actual_game_dict == expected_game_dict
예제 #2
0
    def test_to_dict(self):
        """Test that conversion into dict works as expected."""
        version_id = "1"
        nb_agents = 10
        nb_goods = 10
        tx_fee = 2.5
        agent_pbk_to_name = {
            "tac_agent_0_pbk": "tac_agent_0",
            "tac_agent_1_pbk": "tac_agent_1",
            "tac_agent_2_pbk": "tac_agent_2",
            "tac_agent_3_pbk": "tac_agent_3",
            "tac_agent_4_pbk": "tac_agent_4",
            "tac_agent_5_pbk": "tac_agent_5",
            "tac_agent_6_pbk": "tac_agent_6",
            "tac_agent_7_pbk": "tac_agent_7",
            "tac_agent_8_pbk": "tac_agent_8",
            "tac_agent_9_pbk": "tac_agent_9",
        }
        good_pbk_to_name = {
            "tac_good_0_pbk": "tac_good_0",
            "tac_good_1_pbk": "tac_good_1",
            "tac_good_2_pbk": "tac_good_2",
            "tac_good_3_pbk": "tac_good_3",
            "tac_good_4_pbk": "tac_good_4",
            "tac_good_5_pbk": "tac_good_5",
            "tac_good_6_pbk": "tac_good_6",
            "tac_good_7_pbk": "tac_good_7",
            "tac_good_8_pbk": "tac_good_8",
            "tac_good_9_pbk": "tac_good_9",
        }

        game_configuration = GameConfiguration(version_id, nb_agents, nb_goods,
                                               tx_fee, agent_pbk_to_name,
                                               good_pbk_to_name)

        actual_game_configuration_dict = game_configuration.to_dict()
        expected_game_configuration_dict = {
            "version_id": version_id,
            "nb_agents": nb_agents,
            "nb_goods": nb_goods,
            "tx_fee": tx_fee,
            "agent_pbk_to_name": agent_pbk_to_name,
            "good_pbk_to_name": good_pbk_to_name,
        }

        assert actual_game_configuration_dict == expected_game_configuration_dict
예제 #3
0
    def test_from_dict(self):
        """Test that conversion from dict works as expected."""
        version_id = "1"
        nb_agents = 10
        nb_goods = 10
        tx_fee = 2.5
        agent_pbk_to_name = {
            "tac_agent_0_pbk": "tac_agent_0",
            "tac_agent_1_pbk": "tac_agent_1",
            "tac_agent_2_pbk": "tac_agent_2",
            "tac_agent_3_pbk": "tac_agent_3",
            "tac_agent_4_pbk": "tac_agent_4",
            "tac_agent_5_pbk": "tac_agent_5",
            "tac_agent_6_pbk": "tac_agent_6",
            "tac_agent_7_pbk": "tac_agent_7",
            "tac_agent_8_pbk": "tac_agent_8",
            "tac_agent_9_pbk": "tac_agent_9",
        }
        good_pbk_to_name = {
            "tac_good_0_pbk": "tac_good_0",
            "tac_good_1_pbk": "tac_good_1",
            "tac_good_2_pbk": "tac_good_2",
            "tac_good_3_pbk": "tac_good_3",
            "tac_good_4_pbk": "tac_good_4",
            "tac_good_5_pbk": "tac_good_5",
            "tac_good_6_pbk": "tac_good_6",
            "tac_good_7_pbk": "tac_good_7",
            "tac_good_8_pbk": "tac_good_8",
            "tac_good_9_pbk": "tac_good_9",
        }

        expected_game_configuration = GameConfiguration(
            version_id, nb_agents, nb_goods, tx_fee, agent_pbk_to_name,
            good_pbk_to_name)
        actual_game_configuration = GameConfiguration.from_dict(
            expected_game_configuration.to_dict())

        assert actual_game_configuration == expected_game_configuration