test_that("canonical correlations invariant to permutation", { set.seed(1) n <- 10 T_len <- 6 X <- list( lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2)) ) fit1 <- mcca_fit(method = "kernel", X = X, ncomp = 2) perm <- sample(seq_len(n)) X_perm <- lapply(X, function(block) block[perm]) fit2 <- mcca_fit(method = "kernel", X = X_perm, ncomp = 2) expect_equal(fit1$values, fit2$values, tolerance = 1e-6) })