code: def test_validate_cp_tensor():
      rng = tl.check_random_state(12345)
      true_shape = (3, 4, 5)
      true_rank = 3
      cp_tensor = random_cp(true_shape, true_rank)
      (weights, factors) = cp_normalize(cp_tensor)
  
      # Check correct rank and shapes are returned
      shape, rank = _validate_cp_tensor((weights, 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 rank
      factors[0], copy = (
          tl.tensor(rng.random_sample((4, 4))),
          factors[0],
      )
      with assert_raises(ValueError):
          _validate_cp_tensor((weights, factors))
  
      # Not the correct amount of weights
      factors[0] = copy
      wrong_weights = weights[1:]
      with assert_raises(ValueError):
          _validate_cp_tensor((wrong_weights, factors))
  
      # Not enough factors
      with assert_raises(ValueError):
          _validate_cp_tensor((weights[:1], factors[:1]))
  
imports: import numpy
  import tensorly
  from ..tenalg import khatri_rao, mode_dot
  from ..cp_tensor import cp_to_tensor, cp_to_unfolded, cp_to_vec, _validate_cp_tensor, cp_normalize, CPTensor, cp_mode_dot, cp_norm, cp_flip_sign, _cp_n_param, validate_cp_rank, cp_lstsq_grad, cp_permute_factors
  from ..base import unfold, tensor_to_vec
  from tensorly.random import random_cp
  from tensorly.testing import assert_equal, assert_raises, assert_, assert_array_equal, assert_array_almost_equal
  import pytest
label_desc: Use image node_id 3 for calling a global function with example usage: test_validate_cp_tensor() without return types