-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from biometryhub/feature/unit-test
Feature/unit test
- Loading branch information
Showing
10 changed files
with
136 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
is_positive_wholenumber <- function(x, tol = .Machine$double.eps^0.5) { | ||
is_wholenumber(x, tol) && x > 0 | ||
} | ||
|
||
is_wholenumber <- function(x, tol = .Machine$double.eps^0.5) { | ||
abs(x - round(x)) < tol | ||
} | ||
|
||
verify_rss_params <- function(pop, n, H, K) { | ||
pop_dimension <- dim(pop) | ||
if (length(pop_dimension) != 2) { | ||
stop("`pop` must be a 2-dimension matrix-like object.") | ||
} | ||
|
||
if (pop_dimension[[2]] < 2) { | ||
stop("`pop` must have at least 2 columns.") | ||
} | ||
|
||
if (!is_positive_wholenumber(n)) { | ||
stop("`n` must be a positive whole number.") | ||
} | ||
|
||
if (!is_positive_wholenumber(H)) { | ||
stop("`H` must be a positive whole number.") | ||
} | ||
|
||
if (!is_positive_wholenumber(K)) { | ||
stop("`K` must be a positive whole number.") | ||
} | ||
|
||
if (pop_dimension[[1]] < n) { | ||
stop("`pop` must have at least `n` rows.") | ||
} | ||
|
||
if (n < H) { | ||
stop("`n` must >= `H`.") | ||
} | ||
|
||
if (n %% H != 0) { | ||
stop("`n` must be a multiple of `H`.") | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
test_that("RSSDF has a correct output.", { | ||
skip_if(getRversion() < 3.4) | ||
# TODO: create a matrix to not rely on `population.rda` | ||
load("../population.rda") | ||
|
||
rss_matrix <- RSSDF(population, 100, 10, 2) | ||
expect_equal(dim(rss_matrix), c(100, 3)) | ||
expect_equal(sort(unique(rss_matrix[, 2])), 1:10) | ||
|
||
sample_counts_in_sets <- table(rss_matrix[, 2]) | ||
expect_equal(sample_counts_in_sets[[2]], 10) | ||
expect_equal(table(sample_counts_in_sets)[[1]], 10) | ||
|
||
# # # in case we are supporting `n %% H > 0` | ||
# rss_matrix_with_dropped_sample <- RSSDF(population, 100, 11, 2) | ||
# expect_equal(sort(unique(rss_matrix_with_dropped_sample[, 2])), 0:11) | ||
# | ||
# sample_counts_in_sets <- table(rss_matrix_with_dropped_sample[, 2]) | ||
# expect_equal(sample_counts_in_sets[[2]], 9) | ||
# expect_equal(table(sample_counts_in_sets)[[2]], 11) | ||
}) | ||
|
||
test_that("Inputs are valid.", { | ||
matrix_ <- matrix(1:10, nrow = 5, ncol = 2) | ||
|
||
expect_error(RSSDF(1:10, -100, 10, 1), "`pop` must be a 2-dimension matrix-like object.") | ||
expect_error(RSSDF(matrix(1:10), -100, 10, 1), "`pop` must have at least 2 columns.") | ||
expect_error(RSSDF(matrix_, -100, 10, 1), "`n` must be a positive whole number.") | ||
expect_error(RSSDF(matrix_, 100, -10, 1), "`H` must be a positive whole number.") | ||
expect_error(RSSDF(matrix_, 100, 10, -1), "`K` must be a positive whole number.") | ||
expect_error(RSSDF(matrix_, 100, 10, 1), "`pop` must have at least `n` rows.") | ||
expect_error(RSSDF(matrix_, 5, 11, 1), "`n` must >= `H`.") | ||
expect_error(RSSDF(matrix_, 5, 4, 1), "`n` must be a multiple of `H`.") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
test_that("RSSDF has a correct output.", { | ||
skip_if(getRversion() < 3.4) | ||
# TODO: create a matrix to not rely on `population.rda` | ||
load("../population.rda") | ||
|
||
rss_matrix <- RSSNRF(population, 100, 10, 2) | ||
expect_equal(dim(rss_matrix), c(100, 3)) | ||
expect_equal(sort(unique(rss_matrix[, 2])), 1:10) | ||
|
||
sample_counts_in_sets <- table(rss_matrix[, 2]) | ||
expect_equal(sample_counts_in_sets[[2]], 10) | ||
expect_equal(table(sample_counts_in_sets)[[1]], 10) | ||
}) | ||
|
||
test_that("Inputs are valid.", { | ||
matrix_ <- matrix(1:10, nrow = 5, ncol = 2) | ||
|
||
expect_error(RSSNRF(1:10, -100, 10, 1), "`pop` must be a 2-dimension matrix-like object.") | ||
expect_error(RSSNRF(matrix(1:10), -100, 10, 1), "`pop` must have at least 2 columns.") | ||
expect_error(RSSNRF(matrix_, -100, 10, 1), "`n` must be a positive whole number.") | ||
expect_error(RSSNRF(matrix_, 100, -10, 1), "`H` must be a positive whole number.") | ||
expect_error(RSSNRF(matrix_, 100, 10, -1), "`K` must be a positive whole number.") | ||
expect_error(RSSNRF(matrix_, 100, 10, 1), "`pop` must have at least `n` rows.") | ||
expect_error(RSSNRF(matrix_, 5, 11, 1), "`n` must >= `H`.") | ||
expect_error(RSSNRF(matrix_, 5, 4, 1), "`n` must be a multiple of `H`.") | ||
}) |