code: def test_validate_tt_tensor():
      rng = tl.check_random_state(12345)
      true_shape = (3, 4, 5)
      true_rank = (1, 3, 2, 1)
      factors = random_tt(true_shape, rank=true_rank).factors
  
      # Check that the correct shape/rank are returned
      shape, rank = _validate_tt_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_tt_tensor(factors)
  
      # Consecutive factors ranks don't match
      factors[0] = tl.tensor(rng.random_sample((1, 3, 2)))
      with assert_raises(ValueError):
          _validate_tt_tensor(factors)
  
      # Boundary conditions not respected
      factors[0] = tl.tensor(rng.random_sample((3, 3, 2)))
      with assert_raises(ValueError):
          _validate_tt_tensor(factors)
  
file_path: tensorly/tensorly/tests/test_tt_tensor.py
imports: import numpy
  import tensorly
  from ..decomposition import tensor_train
  from ..tt_tensor import _validate_tt_tensor, pad_tt_rank
  from ..tt_tensor import validate_tt_rank, _tt_n_param
  from ..testing import assert_array_almost_equal, assert_equal, assert_raises, assert_
  from ..random import random_tt, random_tr, random_tt_matrix
  import pytest
label_desc: Use image node_id 1 for calling a global function with example usage: test_validate_tt_tensor() without return types