# SCM Repository

[matrix] Diff of /pkg/Matrix/tests/abIndex-tsts.R
 [matrix] / pkg / Matrix / tests / abIndex-tsts.R

# Diff of /pkg/Matrix/tests/abIndex-tsts.R

revision 2506, Fri Dec 11 12:54:28 2009 UTC revision 2507, Tue Dec 22 21:11:49 2009 UTC
# Line 30  Line 30
30            sapply(ab., any) == sapply(ex., any),            sapply(ab., any) == sapply(ex., any),
31            TRUE)            TRUE)
32
33    ## testing c() method, i.e.  currently c.abIndex():
34    tst.c.abI <- function(lii) {
35        stopifnot(is.list(lii),
36                  all(unlist(lapply(lii, mode)) == "numeric"))
37        aii <- lapply(lii, as, "abIndex")
38        v.i <- do.call(c, lii)
39        a.i <- do.call(c, aii)
40        avi <- as(v.i, "abIndex")
41        ## identical() is too hard, as values & lengths can be double/integer
42        stopifnot(all.equal(a.i, avi, tol = 0))
43    }
44    tst.c.abI(list(2:6, 70:50, 5:-2))
45    ## now an example where *all* are uncompressed:
46    tst.c.abI(list(c(5, 3, 2, 4, 7, 1, 6), 3:4, 1:-1))
47    ## and one with parts that are already non-trivial:
48    exc <- ex.[isCmpr]
49    tst.c.abI(exc)
50    set.seed(101)
51    N <- length(exc) # 5
52    for(i in 1:10) {
53        tst.c.abI(exc[sample(N, replace=TRUE)])
54        tst.c.abI(exc[sample(N, N-1)])
55        tst.c.abI(exc[sample(N, N-2)])
56    }
57
58  for(n in 1:120) {  for(n in 1:120) {
59      cat(".")      cat(".")
60      k <- 1 + 4*rpois(1, 5) # >= 1      k <- 1 + 4*rpois(1, 5) # >= 1
# Line 43  Line 68
68                rleD = new("rleDiff", first = rpois(1, 20), rle = rl))                rleD = new("rleDiff", first = rpois(1, 20), rle = rl))
69      validObject(ai)      validObject(ai)
70      ii <- as(ai, "numeric")      ii <- as(ai, "numeric")
71        iN <- ii; iN[180] <- NA; aiN <- as(iN,"abIndex")
72        iN <- as(aiN, "numeric") ## NA from 180 on
73      stopifnot(is.numeric(ii), ii == round(ii),      stopifnot(is.numeric(ii), ii == round(ii),
74                identical(ai, as(ii, "abIndex")))                identical(ai, as(ii, "abIndex")),
75                  identical(is.na(ai), is.na(ii)),
76                  identical(is.na(aiN), is.na(iN)),
77                  identical(is.finite  (aiN),   is.finite(iN)),
78                  identical(is.infinite(aiN), is.infinite(iN))
79                  )
80      if(n %% 40 == 0) cat(n,"\n")      if(n %% 40 == 0) cat(n,"\n")
81  }  }
82
83    ## we have :  identical(lapply(ex., as, "abIndex"), ab.)
84
85    mkStr <- function(ch, n) paste(rep.int(ch, n), collapse="")
86
87    ##O for(grMeth in getGroupMembers("Ops")) {
88    ##O     cat(sprintf("\n%s :\n%s\n", grMeth, mkStr("=", nchar(grMeth))))
89    grMeth <- "Arith"
90        for(ng in getGroupMembers(grMeth)) {
91            cat(ng, ": ")
92            G <- get(ng)
93            t.tol <- if(ng == "/") 8e-16 else 0
94            ## now using special all.equal() method!
95            AEq <- function(a,b, ...) all.equal(a, b, tol=t.tol)
96            for(v in ex.) {
97                va <- as(v, "abIndex")
98                for(s in list(-1, 17L, TRUE, FALSE)) {# numeric *and* logical
99                    if(!(identical(s, FALSE) && ng == "/")) ## division by 0 often "fails"
100                    stopifnot(AEq(as(G(v, s), "abIndex"), G(va, s)),
101                              AEq(as(G(s, v), "abIndex"), G(s, va)))
102                }
103                cat(".")
104            }
105            cat(" [Ok]\n")
106        }
107    ##O }
108
109  cat('Time elapsed: ', (.pt <- proc.time()),'\n') # "stats"  cat('Time elapsed: ', (.pt <- proc.time()),'\n') # "stats"

Legend:
 Removed from v.2506 changed lines Added in v.2507