Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lgatto committed Dec 25, 2023
1 parent e8cf961 commit ff9bc37
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
33 changes: 19 additions & 14 deletions tests/testthat/test_estimateBaseline.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ test_that("estimateBaselineMedian", {
2), b)
## user method
expect_identical(estimateBaseline(s$mass, s$intensity,
method="median", halfWindowSize = 1), b1)
method = "median", halfWindowSize = 1), b1)
expect_identical(estimateBaseline(s$mass, s$intensity,
method="median", halfWindowSize = 2), b)
method = "median", halfWindowSize = 2), b)
## halfWindowSize
expect_error(estimateBaselineMedian(s$mass, s$intensity, 0),
expect_error(MsCoreUtils:::.estimateBaselineMedian(s$mass, s$intensity, 0),
"too small")
expect_error(estimateBaselineMedian(s$mass, s$intensity, 20),
expect_error(MsCoreUtils:::.estimateBaselineMedian(s$mass, s$intensity, 20),
"too large")
})

Expand All @@ -42,12 +42,11 @@ test_that("estimateBaselineSnip", {
times = 2))),
increasing = list(b = c(10:1, 5:4, 5.5, 7:1),
b100 = c(10:1, 3.75, 3.375, 3:1, 2.5, 4:1)))

## test default decreasing argument
expect_identical(MsCoreUtils:::.estimateBaselineSnip(s$mass, s$intensity, 2),
b$decreasing$b)

for (j in seq(along=b)) {
for (j in seq(along = b)) {
d <- names(b)[j] == "decreasing"

expect_identical(MsCoreUtils:::.estimateBaselineSnip(s$mass, s$intensity,
Expand All @@ -58,10 +57,16 @@ test_that("estimateBaselineSnip", {
b[[j]]$b100)

## user method
expect_identical(estimateBaseline(s, method = "SNIP", iterations = 2,
decreasing = d), b[[j]]$b)
expect_identical(estimateBaseline(s, iterations = 2, decreasing = d), b[[j]]$b)
expect_equal(estimateBaseline(s, decreasing = d), b[[j]]$b100)
expect_identical(estimateBaseline(s$mass, s$intensity,
method = "SNIP", iterations = 2,
decreasing = d),
b[[j]]$b)
expect_identical(estimateBaseline(s$mass, s$intensity,
iterations = 2, decreasing = d),
b[[j]]$b)
expect_equal(estimateBaseline(s$mass, s$intensity,
decreasing = d),
b[[j]]$b100)
}
})

Expand All @@ -72,14 +77,14 @@ test_that("estimateBaselineTopHat", {
1), b1)
expect_identical(MsCoreUtils:::.estimateBaselineTopHat(s$mass, s$intensity,
2), b)

## user method
expect_identical(estimateBaseline(s, method = "TopHat", halfWindowSize = 2), b)

expect_identical(estimateBaseline(s$mass, s$intensity,
method = "TopHat",
halfWindowSize = 2),
b)
## halfWindowSize
expect_error(MsCoreUtils:::.estimateBaselineTopHat(s$mass, s$intensity, 0),
"too small")
expect_error(MsCoreUtils:::.estimateBaselineTopHat(s$mass, s$intensity, 20),
"too large")

})
4 changes: 2 additions & 2 deletions tests/testthat/test_morphologicalFilter.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ d <- list(c(rep(8, 3), rep(7, 2), rep(10, 3)),

test_that(".erosion", {
for (i in seq(along = x)) {
expect_equal(.erosion(x[[i]], halfWindowSize = 2), e[[i]])
expect_equal(MsCoreUtils:::.erosion(x[[i]], halfWindowSize = 2), e[[i]])
}
})

test_that(".dilation", {
for (i in seq(along = x)) {
expect_equal(.dilation(x[[i]], halfWindowSize = 2), d[[i]])
expect_equal(MsCoreUtils:::.dilation(x[[i]], halfWindowSize = 2), d[[i]])
}
})

0 comments on commit ff9bc37

Please sign in to comment.