Skip to content

Commit 43965e1

Browse files
Tests: Add equality test for Box (#1499)
1 parent f59daa6 commit 43965e1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/spaces/test_box.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,29 @@ def test_infinite_space(low, high, shape, dtype):
353353
assert np.all(np.sign(space.low) <= np.sign(sample))
354354

355355

356+
def test_equality():
357+
# Check if two spaces are equivalent.
358+
space_a = Box(low=0, high=1, shape=[2], dtype=np.float32)
359+
360+
space_b = Box(low=0, high=1, shape=[2], dtype=np.float32)
361+
assert space_a == space_b
362+
363+
space_b = Box(low=0, high=np.array([1, 1]), shape=[2], dtype=np.float32)
364+
assert space_a == space_b
365+
366+
space_b = Box(low=-1, high=1, shape=[2], dtype=np.float32)
367+
assert space_a != space_b
368+
369+
space_b = Box(low=0, high=np.array([1, 2]), shape=[2], dtype=np.float32)
370+
assert space_a != space_b
371+
372+
space_b = Box(low=0, high=1, shape=[3], dtype=np.float32)
373+
assert space_a != space_b
374+
375+
space_b = Box(low=0, high=1, shape=[2], dtype=np.int32)
376+
assert space_a != space_b
377+
378+
356379
def test_legacy_state_pickling():
357380
legacy_state = {
358381
"dtype": np.dtype("float32"),

0 commit comments

Comments
 (0)