Skip to content

Commit

Permalink
#5 unit test rendering + clean-up random test
Browse files Browse the repository at this point in the history
  • Loading branch information
ingambe committed Mar 1, 2021
1 parent 104601f commit 0c865e0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
Empty file added tests/flexible/__init__.py
Empty file.
13 changes: 7 additions & 6 deletions tests/flexible/test_fexible_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ def test_random(self):
env = gym.make('JSSEnv:flexible-jss-v1', env_config={'instance_path': '../../JSSEnv/envs/instances/flexible/mt10c1.fjs'})

average = 0
for _ in range(100):
state = env.reset()
self.assertEqual(env.current_time_step, 0)
self.assertNotEqual(env.todo_time_step_job.all(), env.nb_op_job.all())
self.assertEqual(env.todo_time_step_job.all(), 0)
for _ in range(1):
env.reset()
self.assertEqual(env.current_time_step, 0, msg="We start at timestep 0")
self.assertNotEqual(env.todo_time_step_job.all(), env.nb_op_job.all(), msg="We don't modify nb op job")
self.assertEqual(env.todo_time_step_job.all(), 0, msg="We reset todo step job at each reset")
done = False
while not done:
legal_actions = env.get_legal_actions()
actions = np.random.choice(len(legal_actions), 1, p=(legal_actions / legal_actions.sum()))[0]
state, reward, done, _ = env.step(actions)
print(env.current_time_step)
self.assertEqual(env.todo_time_step_job.all(), env.nb_op_job.all())
self.assertEqual(env.todo_time_step_job.all(), env.nb_op_job.all(), msg="We need to perform all job's op")
env.render()
'''
average = 0
for _ in range(100):
Expand Down
25 changes: 25 additions & 0 deletions tests/flexible/test_flexible_rendering_random.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import unittest

import gym
import imageio
import numpy as np


class TestRendering(unittest.TestCase):

def test_random_mt10c1_rendering(self):
env = gym.make('JSSEnv:flexible-jss-v1', env_config={'instance_path': '../../JSSEnv/envs/instances/flexible/mt10c1.fjs'})
env.reset()
self.assertEqual(env.current_time_step, 0)
done = False
step_nb = 0
images = []
while not done:
legal_actions = env.get_legal_actions()
actions = np.random.choice(len(legal_actions), 1, p=(legal_actions / legal_actions.sum()))[0]
state, reward, done, _ = env.step(actions)
temp_image = env.render().to_image()
images.append(imageio.imread(temp_image))
imageio.mimsave("mt10c1.gif", images)
env.reset()
self.assertEqual(env.current_time_step, 0)

0 comments on commit 0c865e0

Please sign in to comment.