The R Project SVN R

Rev

Rev 60192 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
56345 jmc 1
## Tests for handling classes with same name & different package slots
2
## First:  Can we define the classes and get the separate definitions
3
## from the appropriate namespace or from the package slot in class(x)?
69213 ripley 4
if(!require(Matrix)) q()
56345 jmc 5
 
6
## from: example(chol)
7
sy2 <- new("dsyMatrix", Dim = as.integer(c(2,2)), x = c(14, NA,32,77))
8
c2 <- chol(sy2)
9
 
10
clM <- getClass("Cholesky")
11
 
12
setClass("Cholesky", contains = "numeric", representation(size = "integer"))
13
 
14
clG <- getClass("Cholesky", where = .GlobalEnv)
15
 
16
stopifnot(identical(getClass("Cholesky", where = asNamespace("Matrix")),
17
                    clM))
18
 
19
stopifnot(identical(getClass(class(c2)), clM))
20
 
21
stopifnot(identical(evalq(getClass("Cholesky"), asNamespace("Matrix")),
22
                    clM))
23
stopifnot(identical(getClass("Cholesky"), clG))
24
 
25
## Second:  tests of methods defined for the same generic
26
## (NOT YET!)
27
 
60192 jmc 28
## Related: retaining package slots in methods signatures (reported by Martin Morgan)
29
setClass("A")
30
setGeneric("bar", function(x, y) standardGeneric("bar"))
31
setMethod(bar, signature(x="A", y="A"), function(x, y) {})
32
setMethod(bar, signature(x="A", y="ANY"), function(x, y) {})
33
 
34
## tests one use of .matchSigLength
35
stopifnot(all(nzchar(getMethod("bar", signature(x="A", y="ANY"))@target@package)))