Skip to content

Commit 0f9797f

Browse files
authored
Merge pull request #1 from tdaverse/coverage
Bring code coverage to 100%.
2 parents c75dae3 + 5a88e76 commit 0f9797f

4 files changed

Lines changed: 35 additions & 5 deletions

File tree

R/two-sample-test.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#' - A persistence set, which is a collection of persistence diagrams.
77
#' - A distance matrix, which is a pairwise distance matrix between persistence
88
#' diagrams.
9-
#' - One of the PH vectorizations available in the [{tdarec}]() package.
9+
#' - One of the PH vectorizations available in the
10+
#' [{TDAvec}](https://cran.r-project.org/package=TDAvec) package.
1011
#'
1112
#' @param x An object of class `persistence_set` typically produced by
1213
#' [`phutil::as_persistence_set()`] or of class `dist` typically produced by

R/utils.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ null_spec <- function(y, parameters) {
33
}
44

55
compute_distance_matrix <- function(x, dimension = 0L, p = 2L, ncores = 1L) {
6+
if (p == 0L) {
7+
cli::cli_abort(
8+
"The p-norm {.val p} must be greater than zero. Use {.val p = Inf} for the Bottleneck distance."
9+
)
10+
}
11+
612
if (is.infinite(p)) {
713
D <- phutil::bottleneck_pairwise_distances(
814
x = x,

inst/tinytest/test-two-sample-test.R

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ test_two_sample_test_inputs <- function() {
1414
result <- two_sample_test(ps1, ps2, B = 10L)
1515
expect_true(is.numeric(result))
1616

17-
ps1 <- phutil::wasserstein_pairwise_distances(
17+
D <- phutil::wasserstein_pairwise_distances(
1818
ps1,
1919
dimension = 0L,
2020
p = 2L,
2121
ncores = 1L
2222
)
2323
ps2 <- 0
24-
expect_error(two_sample_test(ps1, ps2))
24+
expect_error(two_sample_test(D, ps2))
2525
ps2 <- c(5L, 5L) # Sample sizes
26-
result <- two_sample_test(ps1, ps2, B = 10L)
26+
result <- two_sample_test(D, ps2, B = 10L)
2727
expect_true(is.numeric(result))
2828
}
2929

@@ -69,6 +69,18 @@ test_two_sample_test_verbose <- function() {
6969
ps2 <- trefoils2[1:5]
7070

7171
expect_silent(two_sample_test(ps1, ps2, B = 10L, verbose = FALSE))
72+
expect_message(
73+
two_sample_test(ps1, ps2, B = 10L, verbose = TRUE),
74+
"Parsing inputs..."
75+
)
76+
expect_message(
77+
two_sample_test(ps1, ps2, B = 10L, verbose = TRUE),
78+
"Setting up the plausibility function..."
79+
)
80+
expect_message(
81+
two_sample_test(ps1, ps2, B = 10L, verbose = TRUE),
82+
"Calculating the p-value..."
83+
)
7284
}
7385

7486
# Test different npc methods
@@ -83,6 +95,15 @@ test_two_sample_test_npc <- function() {
8395
expect_true(is.numeric(result_fisher))
8496
}
8597

98+
test_two_sample_test_bottleneck <- function() {
99+
ps1 <- trefoils1[1:5]
100+
ps2 <- trefoils2[1:5]
101+
102+
result <- two_sample_test(ps1, ps2, p = Inf, B = 10L)
103+
expect_true(is.numeric(result))
104+
expect_true(result >= 0 && result <= 1)
105+
}
106+
86107
# Run all tests
87108
test_two_sample_test <- function() {
88109
test_two_sample_test_inputs()
@@ -91,6 +112,7 @@ test_two_sample_test <- function() {
91112
test_two_sample_test_dist()
92113
test_two_sample_test_verbose()
93114
test_two_sample_test_npc()
115+
test_two_sample_test_bottleneck()
94116
}
95117

96118
test_two_sample_test()

man/two_sample_test.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)