Added unit tests for lean_simple_partition
This commit is contained in:
parent
002c0db3f9
commit
b8af977117
4 changed files with 28 additions and 1 deletions
|
|
@ -12,3 +12,5 @@ License: GPL-3
|
|||
Encoding: UTF-8
|
||||
LazyData: true
|
||||
RoxygenNote: 7.0.2
|
||||
Suggests:
|
||||
testthat (>= 2.1.0)
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ learn_simple_partition <- function(ordered_points, fii) {
|
|||
part[1:best_i] <- 1
|
||||
part[(best_i + 1):best_j] <- 2
|
||||
part[(best_j + 1):length(part)] <- 3
|
||||
})
|
||||
}
|
||||
)
|
||||
return(part)
|
||||
}
|
||||
4
tests/testthat.R
Normal file
4
tests/testthat.R
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
library(testthat)
|
||||
library(rBAPS)
|
||||
|
||||
test_check("rBAPS")
|
||||
20
tests/testthat/test-admix1.R
Normal file
20
tests/testthat/test-admix1.R
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
context("Admixture analysis")
|
||||
|
||||
|
||||
test_that("learn_simple_partition behaves like Matlab", {
|
||||
p1 <- c(0, .5, 1, 1.5)
|
||||
p2 <- c(seq(0, .5, .1), 1, 1, 1, 2)
|
||||
p3 <- c(.1, .1, .1, .5, .5, .5, 1, 1, 1)
|
||||
expect_equal(
|
||||
object = learn_simple_partition(p1, 2),
|
||||
expected = matrix(c(1, 1, 2, 2))
|
||||
)
|
||||
expect_equal(
|
||||
object = learn_simple_partition(p2, 2),
|
||||
expected = matrix(c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2))
|
||||
)
|
||||
expect_equal(
|
||||
object = learn_simple_partition(p3, .5),
|
||||
expected = matrix(c(1, 1, 1, 2, 2, 2, 3, 3, 3))
|
||||
)
|
||||
})
|
||||
Loading…
Add table
Reference in a new issue