mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-01 06:07:08 +00:00
* feat: add `isort` to `pre-commit` * ci: skip `__init__.py` file for `isort` * ci: make `isort` mandatory in lint pipeline * docs: add a section on Git hooks * ci: check isort diff * fix: isort from master branch * docs: add pre-commit badge * ci: update black + bandit versions * feat: add PR template * refactor: PR template * ci: remove bandit * docs: add Black badge * ci: try to remove all `|| true` statements * ci: remove lint_python job - Remove `lint_python` CI job - Move `pyupgrade` job to `pre-commit` workflow * fix: avoid messing with typing * docs: add a note on running `pre-cpmmit` manually * ci: apply `pre-commit` to the whole codebase
34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
import numpy as np
|
|
import pytest
|
|
|
|
from gym.envs.toy_text.frozen_lake import generate_random_map
|
|
|
|
|
|
# Test that FrozenLake map generation creates valid maps of various sizes.
|
|
def test_frozenlake_dfs_map_generation():
|
|
def frozenlake_dfs_path_exists(res):
|
|
frontier, discovered = [], set()
|
|
frontier.append((0, 0))
|
|
while frontier:
|
|
r, c = frontier.pop()
|
|
if not (r, c) in discovered:
|
|
discovered.add((r, c))
|
|
directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
|
|
for x, y in directions:
|
|
r_new = r + x
|
|
c_new = c + y
|
|
if r_new < 0 or r_new >= size or c_new < 0 or c_new >= size:
|
|
continue
|
|
if res[r_new][c_new] == "G":
|
|
return True
|
|
if res[r_new][c_new] not in "#H":
|
|
frontier.append((r_new, c_new))
|
|
return False
|
|
|
|
map_sizes = [5, 10, 200]
|
|
for size in map_sizes:
|
|
new_frozenlake = generate_random_map(size)
|
|
assert len(new_frozenlake) == size
|
|
assert len(new_frozenlake[0]) == size
|
|
assert frozenlake_dfs_path_exists(new_frozenlake)
|