@@ -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+
356379def test_legacy_state_pickling ():
357380 legacy_state = {
358381 "dtype" : np .dtype ("float32" ),
0 commit comments