Skip to content

Commit dbad59b

Browse files
committed
Add tests/testthat/test_predict.R
The test verifies project_poisson_nmf returns F with the same column-normalised structure as the input (catches the update.factors = NULL fix)
1 parent 98c0658 commit dbad59b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/testthat/test_predict.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
context("predict")
2+
3+
# Test that project_poisson_nmf returns F with the same structure as the input F
4+
test_that("project_poisson_nmf returns F with the same structure as the input F", {
5+
6+
set.seed(1)
7+
dat <- simulate_multinom_gene_data(175,1200,k = 3)
8+
train <- dat$X[1:100,]
9+
test <- dat$X[101:175,]
10+
11+
fit <- init_poisson_nmf(train,F = dat$F,init.method = "random")
12+
fit <- fit_poisson_nmf(train,fit0 = fit,verbose = "none")
13+
fit <- poisson2multinom(fit)
14+
F_pois <- multinom2poisson(fit)$F
15+
16+
out <- project_poisson_nmf(test,F_pois,numiter = 20,verbose = "none", update.factors = NULL)
17+
18+
norm_col <- function(M) sweep(M,2,colSums(M),"/")
19+
expect_equal(norm_col(out$F),norm_col(F_pois),tolerance = 1e-10)
20+
})

0 commit comments

Comments
 (0)