Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
88 lines (76 loc) · 3.61 KB

File metadata and controls

88 lines (76 loc) · 3.61 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# pylint: disable=g-bad-file-header
# Copyright 2019 The dm_env Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""Tests for dm_env._environment."""
from absl.testing import absltest
from absl.testing import parameterized
import dm_env
class TimeStepHelpersTest(parameterized.TestCase):
@parameterized.parameters(dict(observation=-1), dict(observation=[2., 3.]))
def test_restart(self, observation):
time_step = dm_env.restart(observation)
self.assertIs(dm_env.StepType.FIRST, time_step.step_type)
self.assertEqual(observation, time_step.observation)
self.assertIsNone(time_step.reward)
self.assertIsNone(time_step.discount)
@parameterized.parameters(
dict(observation=-1., reward=2.0, discount=1.0),
dict(observation=(2., 3.), reward=0., discount=0.))
def test_transition(self, observation, reward, discount):
time_step = dm_env.transition(
reward=reward, observation=observation, discount=discount)
self.assertIs(dm_env.StepType.MID, time_step.step_type)
self.assertEqual(observation, time_step.observation)
self.assertEqual(reward, time_step.reward)
self.assertEqual(discount, time_step.discount)
@parameterized.parameters(
dict(observation=-1., reward=2.0),
dict(observation=(2., 3.), reward=0.))
def test_termination(self, observation, reward):
time_step = dm_env.termination(reward=reward, observation=observation)
self.assertIs(dm_env.StepType.LAST, time_step.step_type)
self.assertEqual(observation, time_step.observation)
self.assertEqual(reward, time_step.reward)
self.assertEqual(0.0, time_step.discount)
@parameterized.parameters(
dict(observation=-1., reward=2.0, discount=1.0),
dict(observation=(2., 3.), reward=0., discount=0.))
def test_truncation(self, reward, observation, discount):
time_step = dm_env.truncation(reward, observation, discount)
self.assertIs(dm_env.StepType.LAST, time_step.step_type)
self.assertEqual(observation, time_step.observation)
self.assertEqual(reward, time_step.reward)
self.assertEqual(discount, time_step.discount)
@parameterized.parameters(
dict(step_type=dm_env.StepType.FIRST,
is_first=True, is_mid=False, is_last=False),
dict(step_type=dm_env.StepType.MID,
is_first=False, is_mid=True, is_last=False),
dict(step_type=dm_env.StepType.LAST,
is_first=False, is_mid=False, is_last=True),
)
def test_step_type_helpers(self, step_type, is_first, is_mid, is_last):
time_step = dm_env.TimeStep(
reward=None, discount=None, observation=None, step_type=step_type)
with self.subTest('TimeStep methods'):
self.assertEqual(is_first, time_step.first())
self.assertEqual(is_mid, time_step.mid())
self.assertEqual(is_last, time_step.last())
with self.subTest('StepType methods'):
self.assertEqual(is_first, time_step.step_type.first())
self.assertEqual(is_mid, time_step.step_type.mid())
self.assertEqual(is_last, time_step.step_type.last())
if __name__ == '__main__':
absltest.main()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.