Skip to content

Commit

Permalink
extend test by comparing to dist and cor
Browse files Browse the repository at this point in the history
  • Loading branch information
rcannood committed Sep 8, 2019
1 parent 54457ce commit 9b66a2c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tests/testthat/test-select_landmarks.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
context("Testing select_landmarks()")

x <- Matrix::rsparsematrix(1000, 1000, .01)
x <- as.matrix(iris[,1:4])
test_that("Selecting landmarks", {
lms <- select_landmarks(x, distance_method = "euclidean", landmark_method = "sample", num_landmarks = 500)

expect_is(lms, "matrix")
expect_gte(min(lms), 0)
expect_equal(dim(lms), c(500, nrow(x)))
expect_equal(dim(lms), c(150, nrow(x)))

lix <- attr(lms, "landmark_ix")
expect_false(is.null(lix))

expect_true(all(lix >= 1 & lix <= nrow(x)))

expect_equivalent(
lms[cbind(seq_along(lix), lix)],
rep(0, length(lix)),
tolerance = 1e-4
)

dis <- as.matrix(dist(x))[lix, , drop = FALSE]
expect_equal(as.vector(dis), as.vector(lms), tolerance = 1e-4)
})

test_that("Selecting landmarks with different parameters", {
Expand All @@ -37,4 +39,7 @@ test_that("Selecting landmarks with different parameters", {
rep(0, length(lix)),
tolerance = 1e-4
)

dis <- (1 - (cor(t(x)) + 1) / 2)[lix, , drop = FALSE]
expect_equal(as.vector(dis), as.vector(lms), tolerance = 1e-4)
})

0 comments on commit 9b66a2c

Please sign in to comment.