tests/testthat/test_getCrCorYX.R

library(testthat)

test_that('GetCrCorYX works on a trivial example', {
  
  set.seed(123)
  A = matrix(rnorm(10*7), ncol=7); 
  B = matrix(rnorm(10*4), ncol=4);
  
  covA = cov(A)
  covB = cov(B)
  covAB = cov(A,B) 
  
  expect_equal(GetCrCorYX(covAB, covA, covB),cor(A,B))  
  
  expect_equal(GetCrCorYX(covAB, diag(covA), diag(covB)),cor(A,B))  
  
})

test_that('GetCrCorYX works on a trivial example with a scalar', {
  
  set.seed(123)
  A = matrix(rnorm(101*7), ncol=7); 
  B = rnorm(101);
  
  covA = cov(A)
  covB = var(B)
  covAB = cov(A,B) 
  
  expect_equal(GetCrCorYX(covAB, covA, covB),cor(A,B))  
  
  expect_equal(GetCrCorYX(covAB, diag(covA), covB),cor(A,B))  
  
})
functionaldata/tPACE documentation built on Aug. 16, 2022, 8:27 a.m.