Skip to content

Commit 228e67f

Browse files
committed
adds new tests
1 parent b73236b commit 228e67f

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/testthat/test-dist-functions.R

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
context("Test dist_one_one, dist_one_many, dist_many_many ...")
2+
3+
set.seed(2020-08-20)
4+
P <- 1:10 / sum(1:10)
5+
Q <- 20:29 / sum(20:29)
6+
M1 <- t(replicate(10, sample(1:10, size = 10) / 55))
7+
M2 <- t(replicate(20, sample(1:10, size = 10) / 55))
8+
9+
doo1 <- dist_one_one(P, Q, method = "euclidean", testNA = FALSE)
10+
dom1 <- dist_one_many(P, M1, method = "euclidean", testNA = FALSE)
11+
dmm1 <- dist_many_many(M1, M2, method = "euclidean", testNA = FALSE)
12+
13+
test_that("dist_one_one output structure is correct", {
14+
expect_type(doo1, "double")
15+
expect_length(doo1, 1)
16+
})
17+
18+
test_that("dist_one_many output structure is correct", {
19+
expect_type(dom1, "double")
20+
expect_length(dom1, nrow(M1))
21+
})
22+
23+
test_that("dist_many_many output structure is correct", {
24+
expect_type(dmm1, "double")
25+
expect_equal(dim(dmm1), c(nrow(M1), nrow(M2)))
26+
})
27+
28+
doo2 = euclidean(P, Q, FALSE)
29+
30+
test_that("dist_one_one output is correct", {
31+
expect_equal(doo1, doo2)
32+
})
33+
34+
dom2 = vector(length = nrow(M1))
35+
for (i in seq_len(nrow(M1))){
36+
dom2[i] = euclidean(P, M1[i, ], FALSE)
37+
}
38+
39+
test_that("dist_one_many output is correct", {
40+
expect_equal(dom1, dom2)
41+
})
42+
43+
dmm2 = matrix(nrow = nrow(M1), ncol = nrow(M2))
44+
for (i in seq_len(nrow(M1))){
45+
for (j in seq_len(nrow(M2))){
46+
dmm2[i, j] = euclidean(M1[i, ], M2[j, ], FALSE)
47+
}
48+
}
49+
50+
test_that("dist_many_many output is correct", {
51+
expect_equal(dmm1, dmm2)
52+
})

0 commit comments

Comments
 (0)