Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /randovania_randovania /test /layout /test_teleporters.py
| from __future__ import annotations | |
| from typing import NamedTuple | |
| import pytest | |
| from randovania.bitpacking import bitpacking | |
| from randovania.bitpacking.bitpacking import BitPackDecoder | |
| from randovania.game.game_enum import RandovaniaGame | |
| from randovania.game_description.db.area_identifier import AreaIdentifier | |
| from randovania.game_description.db.node_identifier import NodeIdentifier | |
| from randovania.games.prime2.layout.echoes_teleporters import EchoesTeleporterConfiguration, EchoesTeleporterTargetList | |
| from randovania.layout.lib.teleporters import ( | |
| TeleporterConfiguration, | |
| TeleporterList, | |
| TeleporterShuffleMode, | |
| TeleporterTargetList, | |
| ) | |
| class Data(NamedTuple): | |
| reference: TeleporterConfiguration | EchoesTeleporterConfiguration | |
| encoded: bytes | |
| bit_count: int | |
| expected: TeleporterConfiguration | EchoesTeleporterConfiguration | |
| description: str | |
| num_valid_targets: int | |
| def _m( | |
| encoded: bytes, | |
| bit_count: int, | |
| description: str, | |
| *, | |
| num_valid_targets: int = 22, | |
| mode: str = "vanilla", | |
| skip_final_bosses=False, | |
| excluded_teleporters=None, | |
| excluded_targets=None, | |
| ): | |
| if excluded_teleporters is None: | |
| excluded_teleporters = [] | |
| if excluded_targets is None: | |
| excluded_targets = [] | |
| return { | |
| "encoded": encoded, | |
| "bit_count": bit_count, | |
| "description": description, | |
| "num_valid_targets": num_valid_targets, | |
| "json": { | |
| "mode": mode, | |
| "skip_final_bosses": skip_final_bosses, | |
| "excluded_teleporters": excluded_teleporters, | |
| "excluded_targets": excluded_targets, | |
| }, | |
| } | |
| def _a(region, area, instance_id=None): | |
| if instance_id is not None: | |
| return NodeIdentifier.create(region, area, instance_id).as_json | |
| return AreaIdentifier(region, area).as_json | |
| def _g( | |
| encoded: bytes, | |
| bit_count: int, | |
| description: str, | |
| num_valid_targets: int, | |
| mode: str = "vanilla", | |
| excluded_teleporters=None, | |
| excluded_targets=None, | |
| ): | |
| if excluded_teleporters is None: | |
| excluded_teleporters = [] | |
| if excluded_targets is None: | |
| excluded_targets = [] | |
| return { | |
| "encoded": encoded, | |
| "bit_count": bit_count, | |
| "description": description, | |
| "num_valid_targets": num_valid_targets, | |
| "json": { | |
| "mode": mode, | |
| "excluded_teleporters": excluded_teleporters, | |
| "excluded_targets": excluded_targets, | |
| }, | |
| } | |
| def test_generic_data(request): | |
| game = RandovaniaGame.METROID_SAMUS_RETURNS | |
| reference = TeleporterConfiguration( | |
| mode=TeleporterShuffleMode.VANILLA, | |
| excluded_teleporters=TeleporterList((), game), | |
| excluded_targets=TeleporterTargetList((), game), | |
| ) | |
| return Data( | |
| reference=reference, | |
| encoded=request.param["encoded"], | |
| bit_count=request.param["bit_count"], | |
| expected=TeleporterConfiguration.from_json(request.param["json"], game=game), | |
| description=request.param["description"], | |
| num_valid_targets=request.param["num_valid_targets"], | |
| ) | |
| def test_echoes_data(request): | |
| game = RandovaniaGame.METROID_PRIME_ECHOES | |
| reference = EchoesTeleporterConfiguration( | |
| mode=TeleporterShuffleMode.VANILLA, | |
| skip_final_bosses=False, | |
| excluded_teleporters=TeleporterList((), game), | |
| excluded_targets=EchoesTeleporterTargetList((), game), | |
| ) | |
| return Data( | |
| reference=reference, | |
| encoded=request.param["encoded"], | |
| bit_count=request.param["bit_count"], | |
| expected=EchoesTeleporterConfiguration.from_json(request.param["json"], game=game), | |
| description=request.param["description"], | |
| num_valid_targets=request.param["num_valid_targets"], | |
| ) | |
| def test_valid_targets_echoes(test_echoes_data): | |
| config = EchoesTeleporterConfiguration( | |
| mode=test_echoes_data.expected.mode, | |
| skip_final_bosses=False, | |
| excluded_teleporters=test_echoes_data.expected.excluded_teleporters, | |
| excluded_targets=test_echoes_data.expected.excluded_targets, | |
| ) | |
| valid_targets = config.valid_targets | |
| assert len(valid_targets) == test_echoes_data.num_valid_targets | |
| def test_valid_targets_msr(test_generic_data): | |
| config = TeleporterConfiguration( | |
| mode=TeleporterShuffleMode.ONE_WAY_TELEPORTER_REPLACEMENT, | |
| excluded_teleporters=test_generic_data.expected.excluded_teleporters, | |
| excluded_targets=test_generic_data.expected.excluded_targets, | |
| ) | |
| valid_targets = config.valid_targets | |
| assert len(valid_targets) == test_generic_data.num_valid_targets | |
| def test_decode(data, configuration): | |
| # Run | |
| decoder = BitPackDecoder(data.encoded) | |
| result = configuration.bit_pack_unpack(decoder, {"reference": data.reference}) | |
| # Assert | |
| assert result == data.expected | |
| def test_encode(data): | |
| # Setup | |
| value = data.expected | |
| # Run | |
| result, _echoes_bit_count = bitpacking.pack_results_and_bit_count( | |
| value.bit_pack_encode({"reference": data.reference}) | |
| ) | |
| # Assert | |
| assert result == data.encoded | |
| def test_description(data): | |
| assert data.expected.description("elevators") == data.description | |
Xet Storage Details
- Size:
- 6.97 kB
- Xet hash:
- 5c06605435401719ad686fc365532353600d93ad20d2b5e05ffd404f593d1ace
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.