Skip to content

Commit 60a5acf

Browse files
committed
Fix test suite using new function names.
1 parent a89c4ac commit 60a5acf

4 files changed

Lines changed: 133 additions & 131 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
.DS_Store
66
.quarto
77
docs
8+
9+
/.quarto/

README.Rmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,22 @@ sampled from the respective shape, with Gaussian noise added (standard deviation
5959
function with a maximum scale of 6 and up to dimension 2.
6060

6161
You can use the
62-
[`two_sample_test()`](https://tdaverse.github.io/inphr/reference/two_sample_test.html)
62+
[`two_sample_diagram_test()`](https://tdaverse.github.io/inphr/reference/two_sample_diagram_test.html)
6363
function to perform a two-sample test on these persistence diagrams. For
6464
example, to test whether the first 5 persistence diagrams from the first set are
6565
significantly different from the first 5 persistence diagrams from the second
6666
set, you can run:
6767

6868
```{r}
69-
two_sample_test(trefoils1[1:5], trefoils2[1:5], B = 100L)
69+
two_sample_diagram_test(trefoils1[1:5], trefoils2[1:5], B = 100L)
7070
```
7171

7272
To test whether the first 5 persistence diagrams from the first set are
7373
significantly different from the first 5 persistence diagrams from the third
7474
set, you can run:
7575

7676
```{r}
77-
two_sample_test(trefoils1[1:5], archspirals[1:5], B = 100L)
77+
two_sample_diagram_test(trefoils1[1:5], archspirals[1:5], B = 100L)
7878
```
7979

8080
## Contributions
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Test parse_inputs() function
2+
test_two_sample_diagram_test_inputs <- function() {
3+
ps1 <- 0
4+
ps2 <- 0
5+
expect_error(two_sample_diagram_test(ps1, ps2))
6+
ps1 <- trefoils1[1:5]
7+
expect_error(two_sample_diagram_test(ps1, ps2))
8+
ps2 <- trefoils2[1:5]
9+
result <- two_sample_diagram_test(ps1, ps2, B = 10L)
10+
expect_true(is.numeric(result))
11+
12+
ps1 <- c(trefoils1[1:5], trefoils2[1:5])
13+
ps2 <- c(5L, 5L) # Sample sizes
14+
result <- two_sample_diagram_test(ps1, ps2, B = 10L)
15+
expect_true(is.numeric(result))
16+
17+
D <- phutil::wasserstein_pairwise_distances(
18+
ps1,
19+
dimension = 0L,
20+
p = 2L,
21+
ncores = 1L
22+
)
23+
ps2 <- 0
24+
expect_error(two_sample_diagram_test(D, ps2))
25+
ps2 <- c(5L, 5L) # Sample sizes
26+
result <- two_sample_diagram_test(D, ps2, B = 10L)
27+
expect_true(is.numeric(result))
28+
}
29+
30+
# Test basic functionality
31+
test_two_sample_diagram_test_basic <- function() {
32+
ps1 <- trefoils1[1:5]
33+
ps2 <- trefoils2[1:5]
34+
35+
result <- two_sample_diagram_test(ps1, ps2, B = 10L)
36+
expect_true(is.numeric(result))
37+
expect_true(result >= 0 && result <= 1)
38+
}
39+
40+
# Test parameter validation
41+
test_two_sample_diagram_test_params <- function() {
42+
ps1 <- trefoils1[1:5]
43+
ps2 <- trefoils2[1:5]
44+
45+
expect_error(two_sample_diagram_test(ps1, ps2, dimension = -1L))
46+
expect_error(two_sample_diagram_test(ps1, ps2, p = 0L))
47+
expect_error(two_sample_diagram_test(ps1, ps2, B = 0L))
48+
expect_error(two_sample_diagram_test(ps1, ps2, npc = "invalid"))
49+
}
50+
51+
# Test with distance matrix input
52+
test_two_sample_diagram_test_dist <- function() {
53+
D <- phutil::wasserstein_pairwise_distances(
54+
c(trefoils1[1:5], trefoils2[1:5]),
55+
dimension = 0L,
56+
p = 2L,
57+
ncores = 1L
58+
)
59+
sample_sizes <- c(5L, 5L)
60+
61+
result <- two_sample_diagram_test(D, sample_sizes, B = 10L)
62+
expect_true(is.numeric(result))
63+
expect_true(result >= 0 && result <= 1)
64+
}
65+
66+
# Test verbose output
67+
test_two_sample_diagram_test_verbose <- function() {
68+
ps1 <- trefoils1[1:5]
69+
ps2 <- trefoils2[1:5]
70+
71+
expect_silent(two_sample_diagram_test(ps1, ps2, B = 10L, verbose = FALSE))
72+
expect_message(
73+
two_sample_diagram_test(ps1, ps2, B = 10L, verbose = TRUE),
74+
"Parsing inputs..."
75+
)
76+
expect_message(
77+
two_sample_diagram_test(ps1, ps2, B = 10L, verbose = TRUE),
78+
"Setting up the plausibility function..."
79+
)
80+
expect_message(
81+
two_sample_diagram_test(ps1, ps2, B = 10L, verbose = TRUE),
82+
"Calculating the p-value..."
83+
)
84+
}
85+
86+
# Test different npc methods
87+
test_two_sample_diagram_test_npc <- function() {
88+
ps1 <- trefoils1[1:5]
89+
ps2 <- trefoils2[1:5]
90+
91+
result_tippett <- two_sample_diagram_test(ps1, ps2, B = 10L, npc = "tippett")
92+
result_fisher <- two_sample_diagram_test(ps1, ps2, B = 10L, npc = "fisher")
93+
94+
expect_true(is.numeric(result_tippett))
95+
expect_true(is.numeric(result_fisher))
96+
}
97+
98+
test_two_sample_diagram_test_bottleneck <- function() {
99+
ps1 <- trefoils1[1:5]
100+
ps2 <- trefoils2[1:5]
101+
102+
result <- two_sample_diagram_test(ps1, ps2, p = Inf, B = 10L)
103+
expect_true(is.numeric(result))
104+
expect_true(result >= 0 && result <= 1)
105+
}
106+
107+
test_two_sample_diagram_test_seed <- function() {
108+
ps1 <- trefoils1[1:5]
109+
ps2 <- trefoils2[1:5]
110+
111+
result <- two_sample_diagram_test(ps1, ps2, p = Inf, B = 10L, seed = 1234)
112+
expect_true(is.numeric(result))
113+
expect_true(result >= 0 && result <= 1)
114+
}
115+
116+
# Run all tests
117+
test_two_sample_diagram_test <- function() {
118+
test_two_sample_diagram_test_inputs()
119+
test_two_sample_diagram_test_basic()
120+
test_two_sample_diagram_test_params()
121+
test_two_sample_diagram_test_dist()
122+
test_two_sample_diagram_test_verbose()
123+
test_two_sample_diagram_test_npc()
124+
test_two_sample_diagram_test_bottleneck()
125+
test_two_sample_diagram_test_seed()
126+
}
127+
128+
test_two_sample_diagram_test()

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

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)