code: def test_categorical():
      a = Categorical([1, 2, 3], label="a")
      assert a.simplify() == {"a": a}
      assert a.freeze({"a": 2}) == 2
      exception = a.check_contains({"a": 4})
      assert exception is not None and "not found" in exception.msg
      assert a.contains({"a": 2})
      assert a.contains({"a": 3})
      assert not a.contains({"a": 4})
      with pytest.raises(
          SampleValidationError, match=r"^4 not found in"
      ):
          a.validate({"a": 4})
  
      with pytest.raises(AssertionError, match="must be unique"):
          Categorical([2, 2, 5])
  
      assert list(a.grid()) == [1, 2, 3]
      a = Categorical([1, 2, 3], weights=[0.2, 0.1, 0.7])
      assert list(a.grid()) == [3, 1, 2]
  
      counter = Counter()
      for _ in range(1000):
          counter[a.random()] += 1
      assert 120 <= counter[1] <= 280
      assert 50 <= counter[2] <= 150
      assert 500 <= counter[3] <= 900
  
imports: import math
  from collections import Counter
  import numpy
  import pytest
  from nni.mutable import *
  from nni.mutable.mutable import _dedup_labeled_mutables, _mutable_equal
label_desc: Use image node_id 3 for calling a global function with example usage: test_categorical() without return types