-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests_copmap.R
37 lines (31 loc) · 994 Bytes
/
tests_copmap.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
context("copmap")
source("copmap.R")
test_that("tests for consistency with what I know should happen",{
set.seed(101)
x<-rnorm(100)
y<-(1/sqrt(2))*x+(1/sqrt(2))*rnorm(100)
x<-5*x
y<-5*y
p<-c(-1,-.5,0,.5,1)
numreps<-5
#test things like the class and the size of the matrix result
res<-copmap(x,y,p,numreps,"cov")
expect_equal(class(res),"matrix")
expect_equal(dim(res),c(numreps,length(p)))
#test extreme values, for which I know what the result should be
h<-cov(sort(x),sort(y))
expect_true(all(res[,5]==h))
h<-cov(sort(x),rev(sort(y)))
expect_true(all(res[,1]==h))
#similar tests for "cor" input
res<-copmap(x,y,p,numreps,"cor")
expect_equal(class(res),"matrix")
expect_equal(dim(res),c(numreps,length(p)))
expect_true(all(res>=-1))
expect_true(all(res<=1))
h<-cor(sort(x),sort(y))
expect_true(all(res[,5]==h))
h<-cor(sort(x),rev(sort(y)))
expect_true(all(res[,1]==h))
})
#would be good to have some more exacting tests than this