code: def test_validate_tr_tensor():
      rng = tl.check_random_state(12345)
      true_shape = (6, 4, 5)
      true_rank = (3, 2, 2, 3)
      factors = random_tr(true_shape, rank=true_rank).factors
  
      # Check that the correct shape/rank are returned
      shape, rank = _validate_tr_tensor(factors)
      assert_equal(
          shape,
          true_shape,
          err_msg=f"Returned incorrect shape (got {shape}, expected {true_shape})",
      )
      assert_equal(
          rank,
          true_rank,
          err_msg=f"Returned incorrect rank (got {rank}, expected {true_rank})",
      )
  
      # One of the factors has the wrong ndim
      factors[0] = tl.tensor(rng.random_sample((4, 4)))
      with assert_raises(ValueError):
          _validate_tr_tensor(factors)
  
      # Consecutive factors ranks don't match
      factors[0] = tl.tensor(rng.random_sample((3, 6, 4)))
      with assert_raises(ValueError):
          _validate_tr_tensor(factors)
  
      # Boundary conditions not respected
      factors[0] = tl.tensor(rng.random_sample((2, 6, 2)))
      with assert_raises(ValueError):
          _validate_tr_tensor(factors)
  
imports: import numpy
  import tensorly
  from ..random import random_tr
  from ..testing import assert_allclose, assert_equal, assert_raises, assert_
  from ..tr_tensor import tr_to_tensor, _validate_tr_tensor, _tr_n_param, validate_tr_rank
label_desc: Use image node_id 1 for calling a global function with example usage: test_validate_tr_tensor() without return types