def test_reserveResource(energy_connection: Connection.Connection): energy_connection.reserveResource(200) assert energy_connection.reserved_requested_amount == 200 assert energy_connection.reserved_available_amount == 0 # At this point, we asked for 200 (but never checked how much was there). So we have a deficiency of 200 assert energy_connection.getReservationDeficiency() == 200
def test_preGiveResource(energy_connection: Connection.Connection): energy_connection.target.preGiveResource = MagicMock(return_value=32) # It should be 32, because the origin returns that assert energy_connection.preGiveResource(20) == 32 # This function is just a convenience, so ensure that the node get's called right energy_connection.target.preGiveResource.assert_called_once_with( "energy", 20)
def test_reset(energy_connection: Connection.Connection): energy_connection.lock() energy_connection.reserveResource(200) energy_connection.reserved_available_amount = 12 energy_connection.reset() assert not energy_connection.locked assert energy_connection.reserved_requested_amount == 0 assert energy_connection.reserved_available_amount == 0
def connectWith(self, resource_type: str, target: "Node") -> None: """ Create a connection that transports the provided resource_type from this node to the provided node. :param resource_type: The resource that this node needs to connect. :param target: The node that is the target of the connection :return: """ with self._update_lock: new_connection = Connection(origin=self, target=target, resource_type=resource_type) self._outgoing_connections.append(new_connection) target.addConnection(new_connection)
def test_getReserveResource(energy_connection: Connection.Connection): energy_connection.getResource = MagicMock(return_value=200) energy_connection.reserveResource(300) energy_gained = energy_connection.getReservedResource() assert energy_gained == 200 # The get resource returned 200
def test_giveResource(energy_connection: Connection.Connection): energy_connection.target.giveResource = MagicMock(return_value=9001) assert energy_connection.giveResource(300) == 9001 # check if the target that got the resources got their heat tickled energy_connection.target.addHeat.assert_called_once()
def test_getResource(energy_connection: Connection.Connection): energy_connection.origin.getResource = MagicMock(return_value=900) assert energy_connection.getResource(200) == 900 # Check if the side that got the resources also got their heat "tickled" energy_connection.target.addHeat.assert_called_once()