def test_require_true(self):
    """Tests that we can check arbitrary functions in `RequireTrue`."""

    def _greater(a, b):
      return tf.greater(a, b)

    @tc.contract(tc.RequireTrue(_greater, tensors=["a", "b"], error="Fail."))
    def my_func(a: tf.Tensor, b: tf.Tensor):
      return a + b

    small = tf.constant([1, 2])
    big = tf.constant([3, 4])

    result = my_func(big, small)
    with self.session() as sess:
      # Passes:
      sess.run(result)

    with self.assertRaises(tf.errors.InvalidArgumentError):
      result = my_func(small, big)
      with self.session() as sess:
        # Fails:
        sess.run(result)
Tests that we can check arbitrary functions in `RequireTrue`.
language/canine/tensor_contracts_test.py