Skip to content

Commit

Permalink
Grid tests and allow more steps in trial
Browse files Browse the repository at this point in the history
  • Loading branch information
khozzy committed Aug 12, 2019
1 parent 2edb476 commit f8b485d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gym_grid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .grid import Grid

max_episode_steps = 200
max_episode_steps = 9999

register(
id='grid-20-v0',
Expand Down
39 changes: 39 additions & 0 deletions gym_grid/tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,42 @@ def test_should_get_reward(self):
assert obs == ('20', '20')
assert reward == 1000
assert done is True

def test_should_move_in_each_direction(self):
# given
grid = gym.make('grid-20-v0')
np.random.seed(54)
grid.reset() # (16, 6)

# when & then
state, _, _, _ = grid.step(MOVE_LEFT)
assert state == ("15", "6")

state, _, _, _ = grid.step(MOVE_UP)
assert state == ("15", "7")

state, _, _, _ = grid.step(MOVE_RIGHT)
assert state == ("16", "7")

state, _, _, _ = grid.step(MOVE_DOWN)
assert state == ("16", "6")

def test_should_reach_reward(self):
# given
grid = gym.make('grid-20-v0')

# from left
np.random.seed(128)
grid.reset() # (19, 20)
state, reward, done, _ = grid.step(MOVE_RIGHT)
assert state == ("20", "20")
assert reward == 1000
assert done is True

# from bottom
np.random.seed(342)
grid.reset() # (20, 19)
state, reward, done, _ = grid.step(MOVE_UP)
assert state == ("20", "20")
assert reward == 1000
assert done is True

0 comments on commit f8b485d

Please sign in to comment.