| 52030 |
jmc |
1 |
## test (non-conditional) explicit inheritance
|
|
|
2 |
setClass("xy", representation(x="numeric", y="numeric"))
|
|
|
3 |
|
|
|
4 |
setIs("xy", "complex",
|
|
|
5 |
coerce = function(from) complex(real = from@x, imaginary = from@y),
|
|
|
6 |
replace = function(from, value) {
|
|
|
7 |
from@x <- Re(value)
|
|
|
8 |
from@y <- Im(value)
|
|
|
9 |
from
|
|
|
10 |
})
|
|
|
11 |
|
|
|
12 |
set.seed(124)
|
|
|
13 |
x1 <- rnorm(10)
|
|
|
14 |
y1 <- rnorm(10)
|
|
|
15 |
cc <- complex(real = x1, imaginary=y1)
|
|
|
16 |
xyc <- new("xy", x = x1, y = y1)
|
|
|
17 |
stopifnot(identical(cc, as(xyc, "complex")))
|
|
|
18 |
as(xyc, "complex") <- cc * 1i
|
|
|
19 |
stopifnot(identical(xyc, new("xy", x = -y1, y = x1)))
|
|
|
20 |
|
|
|
21 |
setGeneric("size", function(x)standardGeneric("size"))
|
| 58136 |
jmc |
22 |
## check that generic for size() was created w/o a default method
|
|
|
23 |
stopifnot(is(size, "standardGeneric"),
|
|
|
24 |
is.null(selectMethod("size", "ANY",optional=TRUE)))
|
| 52030 |
jmc |
25 |
|
|
|
26 |
setMethod("size", "vector", function(x)length(x))
|
|
|
27 |
|
|
|
28 |
## class "xy" should inherit the vector method through complex
|
|
|
29 |
stopifnot(identical(size(xyc), length(x1)))
|
|
|
30 |
removeClass("xy")
|
|
|
31 |
removeGeneric("size")
|