code: def test_ItemSet_length():
      # Integer with valid length
      num = 10
      item_set = gb.ItemSet(num)
      assert len(item_set) == 10
      # Test __iter__() method. Same as below.
      for i, item in enumerate(item_set):
          assert i == item
  
      # Single iterable with valid length.
      ids = torch.arange(0, 5)
      item_set = gb.ItemSet(ids)
      assert len(item_set) == 5
      for i, item in enumerate(item_set):
          assert i == item.item()
  
      # Tuple of iterables with valid length.
      item_set = gb.ItemSet((torch.arange(0, 5), torch.arange(5, 10)))
      assert len(item_set) == 5
      for i, (item1, item2) in enumerate(item_set):
          assert i == item1.item()
          assert i + 5 == item2.item()
  
      class InvalidLength:
          def __iter__(self):
              return iter([0, 1, 2])
  
      # Single iterable with invalid length.
      item_set = gb.ItemSet(InvalidLength())
      with pytest.raises(
          TypeError, match="ItemSet instance doesn't have valid length."
      ):
          _ = len(item_set)
      with pytest.raises(
          TypeError, match="ItemSet instance doesn't support indexing."
      ):
          _ = item_set[0]
      for i, item in enumerate(item_set):
          assert i == item
  
      # Tuple of iterables with invalid length.
      item_set = gb.ItemSet((InvalidLength(), InvalidLength()))
      with pytest.raises(
          TypeError, match="ItemSet instance doesn't have valid length."
      ):
          _ = len(item_set)
      with pytest.raises(
          TypeError, match="ItemSet instance doesn't support indexing."
      ):
          _ = item_set[0]
      for i, (item1, item2) in enumerate(item_set):
          assert i == item1
          assert i == item2
  
imports: import re
  import dgl
  import pytest
  import torch
  from dgl import graphbolt
  from torch.testing import assert_close
label_desc: Use image node_id 2 for calling a global function with example usage: test_ItemSet_length() and returns: iter