class_docstr: Tests for `tf.data.experimental.assert_cardinality()`.
class_docstr_tok: ["Tests","for","`","tf.data.experimental.assert_cardinality","(",")","`","."]
code: def testIncorrectCardinality(
      self, num_elements, asserted_cardinality, expected_error
  ):
      dataset = dataset_ops.Dataset.range(num_elements)
      dataset = dataset.apply(
          cardinality.assert_cardinality(asserted_cardinality)
      )
      get_next = self.getNext(dataset)
      with self.assertRaisesRegex(
          errors.FailedPreconditionError, expected_error
      ):
          while True:
              self.evaluate(get_next())
  
file_path: tensorflow/tensorflow/python/data/experimental/kernel_tests/assert_cardinality_test.py
imports: from absl.testing import parameterized
  from tensorflow.python.data.experimental.ops import cardinality
  from tensorflow.python.data.kernel_tests import checkpoint_test_base
  from tensorflow.python.data.kernel_tests import test_base
  from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.data.ops import options
  from tensorflow.python.framework import combinations
  from tensorflow.python.framework import errors
  from tensorflow.python.platform import test
label_desc: Use image node_id 2 for calling the AssertCardinalityTest obj's underlying member method code with example usage: obj.testIncorrectCardinality(num_elements, asserted_cardinality, expected_error) without return types