Repository navigation
Adds tests to improve on coverage - #1
Open
averissimo wants to merge 9 commits into
Open
averissimo wants to merge 9 commits into
averissimo wants to merge 9 commits into
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Known bugs generated by Claude
Details
Known defects in MESS 0.6.0 found while writing the tests
Each defect below was reproduced against MESS 0.6.0 installed from this
source tree. Where the defect changes observable behaviour, the test suite
contains a test that asserts the correct behaviour and starts with
skip_known_bug("Bxx")(seehelper-known-bugs.R); all such tests live intest-known-bugs.R. These tests have beenchecked to fail for the stated reason when the skip line is removed.
When a defect is fixed upstream, delete the skip line and the test becomes
active.
IDs are not contiguous; they were assigned per review batch.
auc()withabsolutearea = TRUEis wrong for unsortedxcol.tint()error message refers to "shade"drop1.geeglm()/drop1.geem()withtest = "none"drop the statistic columndrop1.geese()always errorsextended.shared()ignoresrho/thetafor apedigreeListtolfilenameage()returns negative ages whentois earlier thanfromin the same yearextended.shared()fails for a pedigree with exactly one non-founderks_cumtest()does not rescaleprobto sum to 1maximum_subarray()reads out of bounds for an empty vectorcumsumbinning()starts at group 2 when the first value exceeds the thresholddrop1()score tests fail when the model data is not on the search pathdrop1()score tests ongeemobjects always errorselectedholds the discarded variables (doc only, no skipped test)B01:
auc()withabsolutearea = TRUEis wrong for unsortedxR/auc.R:81builds the zero-crossing points from the unsortedx/y(x[idx],y[idx+1]). It should use the sortedox/oy.auc(c(4, 0, 1, 2, 3), c(0, 0, 0, 1, -1), absolutearea = TRUE)auc(0:4, c(0,0,1,-1,0), absolutearea = TRUE)).test-known-bugs.R, "auc() with absolutearea = TRUE handles unsorted x values".B02:
col.tint()error message refers to "shade"R/colorfunctions.R:53,stop("shade must be between 0 and 1").col.tint("blue", 2)test-colorfunctions.R"colour functions error for out-of-range arguments" matches only "between 0 and 1".B03:
drop1.geeglm()/drop1.geem()withtest = "none"drop the statistic columnR/drop1.geeglm.R:88(and:193).switch(test, Wald=..., score=..., sasscore=...)returns NULL for "none", soaod[, NULL] <- scoreadds nothing.fit <- geepack::geeglm(breaks ~ wool + tension, id = rep(1:18, each = 3), data = warpbreaks, family = poisson); drop1(fit, test = "none")DFcolumn. Expected:DFandWald, without p-values (asdrop1.geesedoes).test-known-bugs.R, "drop1() on geeglm with test = 'none' keeps the statistic".B04:
drop1.geese()always errorsR/drop1.geeglm.Rdrop1.geese.drop.scope(object)needs atermscomponent thatgeeseobjects lack. With an explicit scope,eval(glmcall, parent.frame())cannot rebuild the model frame, andobject$geese$vbetaandcoef(object)do not exist on ageeseobject (it uses$betaand$vbeta).gs <- geepack::geese(breaks ~ wool + tension, id = rep(1:18, each = 3), data = warpbreaks, family = poisson); drop1(gs). This gives "no terms component nor attribute".drop1(gs, scope = ~wool + tension)gives "'data' must be of a vector type, was 'NULL'".drop1()on the equivalentgeeglmfit.test-known-bugs.R, "drop1() on geese gives Wald tests per term".B05:
extended.shared()ignoresrho/thetafor apedigreeListR/extended.shared.R:52,extended.shared(family)is called without passingrhoandtheta.pedigreeList, thenextended.shared(pl, rho = 0.5, theta = 0.5).test-known-bugs.R, "extended.shared() passes rho and theta on for a pedigreeList".B06: rnorm_perfect() multiplies the mean by sd
(qnorm(...) + mean)*sdmean(rnorm_perfect(30, mean = 10, sd = 2))mean + sd * qnorm(i/(n+1))).test-known-bugs.R— "the sample is centred at mean and scaled by sd"B07: prepost.test() uses the treated-arm regression (ehat1) in the control-arm augmentation term
(R-pihat0)*(1-Z)*ehat1/pihat0) and :109 ((ehat1-mu20)in iFun2); should be ehat0.post[c(2, 10, 12)] <- NA;prepost.test(bp_base, post, expo)$estimatetest-known-bugs.R— "missing post values are handled with the semiparametric estimator"B08: screen_variables(method = "global-DPP") always errors
norm(x, 2); base::norm() needstype = "2"(character).screen_variables(diag(3), c(3, 2, 1), lambda = 2.5, method = "global-DPP")Error in norm(x, 2): 'type' must be a character string. Expected: list with DPP-screened indices.test-known-bugs.R— "global-DPP method applies the DPP criterion"B09: QIC.geeglm refit cannot find data defined in the caller's environment
eval(object$call, parent.frame())inside the nestedcomputeqic()closure evaluates in QIC.geeglm's frame (enclosure: MESS namespace -> global env), not where the model was fitted. geepack::QIC captures the caller env and works.f <- function() { dat <- geepack::ohio; fit <- geepack::geeglm(resp ~ age, id = id, data = dat, family = binomial); MESS::QIC(fit) }; f()Error in eval(mf, parent.frame()): object 'dat' not found. Expected: same asgeepack::QIC(fit).data = geepack::ohio) — the tests use the latter.test-known-bugs.R— "QIC works when the model data is a local variable"B10: QIC.ordgee is unreachable / broken
geepack::ordgee()returns class "geese" (not "ordgee"), so the method is never dispatched; even if called, the guard at :143 requires class "geeglm" and :173 evaluates the object instead of its call.MESS::QIC(geepack::ordgee(ordered(resp) ~ age, id = id, data = geepack::ohio))no applicable method for 'QIC' applied to an object of class "geese". Expected: QIC values for the ordinal GEE fit.test-known-bugs.R— "QIC works for an ordgee fit"B11: QIC(fit1, fit2) fails: second model binds to
toltolis the 2nd formal, before....MESS::QIC(fit1, fit2)(both geeglm fits)Error in tol * Xsvd$d[1L]: non-numeric argument to binary operator. Expected: 2 x 6 matrix. Works only asQIC(fit1, model2 = fit2).test-known-bugs.R— "models can be compared by passing them positionally"B12: fitted.geese() always errors
model.framecall keepsfamily=), R/fitted.geese.R:30 (family(value)has no method for class "geese").linkinv(X %*% beta), which equalfitted()of the equivalent geeglm fit.test-known-bugs.R, "fitted.geese returns fitted values for a binomial geese fit" and "... for a gaussian geese fit".B13: feature.test() errors whenever the lasso selects a variable
o.select[o.ols.order]).o.ols.orderis only assigned in the nothing-selected branch, because the assignment in the selected branch is commented out.ols.selectedandlasso.selectedordered by importance, plus permutation p-values.options(warn = -1)leak on error was not reproduced.test-known-bugs.R, "feature.test selects the true predictor and returns permutation p-values".B14: panel.hist() / panel.r2() warn on every call and do not restore par("usr")
on.exit(par(usr))passes an unnamed vector; it should beon.exit(par(usr = usr)).par("usr")restored.test-known-bugs.R, "panel.hist and panel.r2 restore par('usr') without warnings". The smoke tests muffle only this specific warning.B15: lower.tri.vector() accepts non-square matrices
!is.matrix(x) & nrow(x) != ncol(x)should use|.lower.tri.vector(matrix(1:12, nrow = 3))returns2 3 6and does not raise an error.test-known-bugs.R, "lower.tri.vector rejects a non-square matrix".B16: loadRData() fails when the saved object is named
filenameload()overwrites the localfilenameargument, and the object is then excluded byls() != "filename".1:3. A fix is toload()into a new environment.test-known-bugs.R, "loadRData returns an object that is named 'filename'".B17: gkgamma() input check is unreachable (dead code, no test)
is.matrix(as.matrix(x))is always TRUE, sostop("x must be a table or matrix")can never run. Invalid input fails later with base-R errors.B20:
age()returns negative ages whentois earlier thanfromin the same yearR/age.R:26. The negativity check is done on the year difference before the month/day adjustment.age("2016-06-01", "2016-01-01")test-known-bugs.R, "age() errors when 'to' is before 'from' within the same year".B21:
extended.shared()fails for a pedigree with exactly one non-founderR/extended.shared.R:89.cbind(id$mindex, id$findex)[nonfounders,]drops to a vector when there is one non-founder, sospouses[,2:1](line 92) errors. Needsdrop = FALSE.extended.shared(kinship2::pedigree(1:3, c(0, 0, 1), c(0, 0, 2), c(1, 2, 1)))test-known-bugs.R, "extended.shared() handles a pedigree with a single non-founder".B22:
ks_cumtest()does not rescaleprobto sum to 1src/kstest.cpp:66-75. The normalisation ofprobis commented out, although the documentation says "It will be scaled to sum to 1".ks_cumtest(1:6, prob = c(5, 1, 1, 1, 1, 1))$statisticprob = c(5, 1, 1, 1, 1, 1) / 10. The p-value is also wrong.test-known-bugs.R, "ks_cumtest() rescales prob to sum to 1".B23:
maximum_subarray()reads out of bounds for an empty vectorsrc/maximum_subarray.cpp:27,double max_so_far = x[0];without a length check.maximum_subarray(numeric(0))sum = 4.69e-310, start 1, end 1). Expected: an error.test-known-bugs.R, "maximum_subarray() rejects an empty vector".B24:
cumsumbinning()starts at group 2 when the first value exceeds the thresholdsrc/cumsumbinning.cpp:64. Whencutwhenpassed = FALSEthe group counter is incremented before the first group has any members.cumsumbinning(c(15, 1, 2), 10)c(2, 3, 3); expectedc(1, 2, 2).test-known-bugs.R, "cumsumbinning() numbers groups from 1 when the first value exceeds the threshold".B25:
drop1()score tests fail when the model data is not on the search pathR/drop1.geeglm.R:69(and:174).update(object, ...)evaluates the stored call indrop1.geeglm's frame, whose enclosure is the MESS namespace. Data defined in the caller's local environment is not found.stats::drop1.defaultavoids this by evaluating inenvironment(formula(object)).f <- function() { dd <- warpbreaks; m <- geepack::geeglm(breaks ~ wool + tension, id = rep(1:18, each = 3), data = dd, family = poisson); drop1(m, test = "score") }; f()test-known-bugs.R, "drop1() score tests work when the data is a local variable". The working score tests use thewarpbreaksdataset, which is on the search path.B26:
drop1()score tests ongeemobjects always errorR/scorefct.R:34useso$family$linkinv,o$id,o$corstrando$geese$alpha, which exist only ongeeglmobjects. Ageemobject stores the family in$FunListand the correlation in$alpha.g <- geeM::geem(breaks ~ wool + tension, id = rep(1:18, each = 3), data = warpbreaks, family = "poisson"); drop1(g, test = "score")test-known-bugs.R, "drop1() on geem computes score tests".B30: power_binom_test() two-sided power exceeds the nominal level for symmetric p0
binom.testrejection region. The documented example (## => power = 0.971) shows the wrong value.binom.testrejection region at level 0.05.test-known-bugs.R, "power_binom_test two-sided test keeps its level for symmetric p0".B31: power_binom_test() cannot solve for p0
p0(which is NULL) where it should usepa.power_binom_test(n = 50, pa = 0.45, power = 0.8, alternative = "greater")gives "Error in uniroot: 'interval' must be a vector of length 2".test-known-bugs.R, "power_binom_test solves for p0".B32: power_prop_test() cannot solve for sig.level
extendInt = "upX"is used, but n decreases as sig.level increases. Extending the interval beyond 1 also produces NaN warnings.power_prop_test(n = 93, p1 = .5, p2 = .7, power = .8, sig.level = NULL)gives "Error in uniroot: did not succeed extending the interval endpoints".stats::power.prop.testgives 0.05.test-known-bugs.R, "power_prop_test solves for sig.level".B33: power_prop_test() one-sided power counts both tails
pnorm(A) + pnorm(B, lower.tail = FALSE)is used for both alternatives. Withtside = 1, the wrong-direction tail is added, so the one-sided test has size 2 * sig.level.power_prop_test(n = 50, p1 = .5, p2 = .5, alternative = "one.sided")$powerreturns 0.10 (should be 0.05). For p1 = .5, p2 = .7 it gives 0.657313, versus 0.657229 from stats.test-known-bugs.R, "power_prop_test one-sided power matches stats::power.prop.test".B34: power_mcnemar_test() rejects psi = 1 although the message says "1 or greater"
any(psi <= 1)).power_mcnemar_test(n = 60, paid = .1, psi = 1)gives "Error: psi must be 1 or greater ...".test-known-bugs.R, "power_mcnemar_test accepts psi = 1 as its error message states".B35: geekin() fails unless geepack is attached
as.name("geeglm")and evaluated inparent.frame(). geepack is only imported, sogeeglmis not visible from user code.library(geepack). A fix is to usegeepack::geeglm.test-known-bugs.R, "geekin works when geepack is not attached". Inside testthat the test environment inherits MESS's imports, which hides the bug.test-qic.R("QIC for a geekin fit ..."), which attaches geepack withwithr::local_package()as the documented usage.B36: print.geekin(digits = ) permanently changes options("digits")
options(digits = digits)with no restore).print(fit, digits = 3); getOption("digits")returns 3.test-known-bugs.R, "print.geekin does not change the global digits option".B40: screen_variables()$selected is not a list when all lambdas screen the same number of variables
apply(discard, 2, which)simplifies to a vector/matrix.screen_variables(diag(3), c(3, 2, 1), lambda = c(2.4, 2.5))$selectedc(3L, 3L)(integer vector; a matrix when lengths > 1). Expected:list(3L, 3L). Also a single lambda returns a bare vector.test-known-bugs.R— "selected is a list even when every lambda selects the same number of variables"B41: screen_variables() documentation:
selectedholds the discarded variables (doc only, no skipped test)discard <- outer(res, criterion, "<")).B42: write.xml() writes bogus rows for a zero-row data frame
sapply(1:nrow(data), ...)iterates over 1:0.write.xml(data.frame(a = 1:2, b = c("x", "y"))[0, ], tf); readLines(tf)<a>NA</a><b>NA</b>and<a>character(0)</a>.... Expected: header,<document>,</document>only. Fix:seq_len(nrow(data)).test-known-bugs.R— "a data frame without rows writes an empty document"B44: earthquakes documentation lists 22 variables (doc only, no skipped test)
Observations (not defects)
unirootreturns an n that achieves the requested power, not necessarily the smallest. For p0 = .3, pa = .5, power = .8 it returns 47, although n = 43 already gives 0.82. The test only checks that the returned n achieves the requested power.