docstr: Tests the two utility functions `batch` and `unbatch`.
docstr_tok: ["Tests","the","two","utility","functions","`","batch","`","and","`","unbatch","`","."]
code: def test_batch_and_unbatch(self):
      """Tests the two utility functions `batch` and `unbatch`."""
      # Test, whether simple structs are batch/unbatch'able as well.
      # B=8
      simple_struct = [0, 1, 2, 3, 4, 5, 6, 7]
      simple_struct_batched = batch(simple_struct)
      check(unbatch(simple_struct_batched), simple_struct)
  
      # Create a complex struct of individual batches (B=2).
      complex_struct = {
          "a": (
              np.array([-10.0, -20.0]),
              {
                  "a1": np.array([-1, -2]),
                  "a2": np.array([False, False]),
              },
          ),
          "b": np.array([0, 1]),
          "c": {
              "c1": np.array([True, False]),
              "c2": np.array([1, 2]),
              "c3": (np.array([3, 4]), np.array([5, 6])),
          },
          "d": np.array([0.0, 0.1]),
      }
      complex_struct_unbatched = unbatch(complex_struct)
      # Check that we now have a list of two complex items, the first one
      # containing all the index=0 values, the second one containing all the index=1
      # values.
      check(
          complex_struct_unbatched,
          [
              tree.map_structure(lambda s: s[0], complex_struct),
              tree.map_structure(lambda s: s[1], complex_struct),
          ],
      )
  
      # Re-batch the unbatched struct.
      complex_struct_rebatched = batch(complex_struct_unbatched)
      # Should be identical to original struct.
      check(complex_struct, complex_struct_rebatched)
  
file_path: ray/python/ray/rllib/utils/spaces/tests/test_space_utils.py
imports: import unittest
  from gymnasium.spaces import Box, Discrete, MultiDiscrete, MultiBinary, Tuple, Dict
  import numpy
  import tree
  from ray.rllib.utils.spaces.space_utils import batch, convert_element_to_space_type, get_base_struct_from_space, unbatch, unsquash_action
  from ray.rllib.utils.test_utils import check
label_desc: Use image node_id 3 for calling the TestSpaceUtils obj's underlying member method code with example usage: obj.test_batch_and_unbatch() without return types