Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
RoseYuan committed Jan 14, 2025
1 parent 7ffa9a4 commit 54598ee
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions tests/testthat/test-spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,31 @@ data(sp_toys)
d <- sp_toys

test_that("Internal spatial metrics work", {
sm <- getSpatialInternalMetrics(d$label, d[,seq_len(2)], level="dataset")
sm <- getSpatialInternalMetrics(labels=d$label, location=d[,seq_len(2)],
level="dataset")
expect_true(all(!is.na(as.matrix(sm))))
sm <- getSpatialInternalMetrics(d$label, d[,seq_len(2)], level="class")
sm2 <- getSpatialInternalMetrics(d$label, d[,seq_len(2)], level="element",
sm <- getSpatialInternalMetrics(labels=d$label, location=d[,seq_len(2)],
level="class")
sm2 <- getSpatialInternalMetrics(labels=d$label, location=d[,seq_len(2)],
level="element",
metrics=c("PAS","ELSA"))
medElsa <- sapply(split(sm2$ELSA, sm2$PAS), median)
expect_true(all(medElsa[1]<0.2 & medElsa[2]>0.5))
})

test_that("External spatial metrics work", {
sm <- getSpatialExternalMetrics(d$label, d$p1, d[,seq_len(2)],
level="dataset")
sm <- getSpatialExternalMetrics(true=d$label, pred=d$p1,
location=d[,seq_len(2)], level="dataset")
expect_true(all(!is.na(as.matrix(sm))))
sm <- getSpatialExternalMetrics(d$label, d$p1, d[,seq_len(2)],
level="class")
sm <- getSpatialExternalMetrics(true=d$label, pred=d$p1,
location=d[,seq_len(2)], level="class")
expect_true(sm$SpatialAWH[3]==1)
expect_true(sm$SpatialAWC[2]==1)
sm2 <- getSpatialExternalMetrics(d$label, d$p1, d[,seq_len(2)],
level="element",
sm2 <- getSpatialExternalMetrics(true=d$label, pred=d$p1,
location=d[,seq_len(2)], level="element",
metrics=c("SpatialSPC","SpatialNPC"))
sm2 <- getSpatialExternalMetrics(d$label, d$p1, d[,seq_len(2)],
level="element",
sm2 <- getSpatialExternalMetrics(true=d$label, pred=d$p1,
location=d[,seq_len(2)], level="element",
metrics=c("SpatialSPC"), useNegatives=FALSE)
medSPC <- sapply(split(sm2$SpatialSPC, d$label!=d$p1), median)
expect_true(all(medSPC[1]>0.8 & medSPC[2]<0.3))
Expand Down

0 comments on commit 54598ee

Please sign in to comment.