The R Project SVN R

Rev

Rev 84489 | 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)
84489 maechler 9
stopifnot(is(c2, "dtrMatrix"),
10
          all.equal(as.matrix(c2), tol = 7e-7, # see 2.7e-7
11
                    matrix(c(3.74166, 0, 8.55236, 1.96396), 2))
12
          )
88059 maechler 13
clM <- getClass("pMatrix")
84489 maechler 14
cM <- new(clM)
56345 jmc 15
 
88059 maechler 16
## an*other* "pMatrix" class:
17
setClass("pMatrix", contains = "numeric", representation(size = "integer"))
56345 jmc 18
 
88059 maechler 19
clG <- getClass("pMatrix", where = .GlobalEnv)
56345 jmc 20
 
84489 maechler 21
stopifnot(exprs = {
88059 maechler 22
    identical(clM, getClass("pMatrix", where = asNamespace("Matrix")))
23
    identical(evalq(getClass("pMatrix"), asNamespace("Matrix")), clM)
84489 maechler 24
    identical(getClass(class(cM)),  clM)
88059 maechler 25
    identical(getClass("pMatrix"), clG)
84489 maechler 26
})
56345 jmc 27
 
28
## Second:  tests of methods defined for the same generic
29
## (NOT YET!)
30
 
84489 maechler 31
 
60192 jmc 32
## Related: retaining package slots in methods signatures (reported by Martin Morgan)
33
setClass("A")
34
setGeneric("bar", function(x, y) standardGeneric("bar"))
35
setMethod(bar, signature(x="A", y="A"), function(x, y) {})
36
setMethod(bar, signature(x="A", y="ANY"), function(x, y) {})
37
 
38
## tests one use of .matchSigLength
39
stopifnot(all(nzchar(getMethod("bar", signature(x="A", y="ANY"))@target@package)))