Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
- Replace depracated expect_equivalent
- Fixed indentation
  • Loading branch information
burgerga committed Dec 21, 2023
1 parent 6d437e8 commit c82ad76
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
47 changes: 27 additions & 20 deletions tests/testthat/test-read-mdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,60 @@ ref_text <-

ref_text_1_cluster <-
c("MTrackJ 1.5.1 Data File", "Assembly 1", "Cluster 1", "Track 1",
"Point 1 187.1 263.2 27.4 1.0 1.0", "Point 2 309.2 264.4 15.8 2.0 1.0",
"Track 2", "Point 1 18.4 438.5 28.1 1.0 1.0", "Point 2 142.9 58.6 28.2 2.0 1.0",
"Point 3 290.1 197.5 18.8 3.0 1.0", "Track 3", "Point 1 310.1 15.4 5.8 1.0 1.0",
"Track 4", "Point 1 99.1 33.5 22.5 1.0 1.0", "Point 2 220.2 396.0 16.4 2.0 1.0",
"Track 5", "Point 1 8.4 305.8 30.2 1.0 1.0", "Point 2 84.7 227.7 21.1 2.0 1.0",
"End of MTrackJ Data File")
"Point 1 187.1 263.2 27.4 1.0 1.0", "Point 2 309.2 264.4 15.8 2.0 1.0",
"Track 2", "Point 1 18.4 438.5 28.1 1.0 1.0", "Point 2 142.9 58.6 28.2 2.0 1.0",
"Point 3 290.1 197.5 18.8 3.0 1.0", "Track 3", "Point 1 310.1 15.4 5.8 1.0 1.0",
"Track 4", "Point 1 99.1 33.5 22.5 1.0 1.0", "Point 2 220.2 396.0 16.4 2.0 1.0",
"Track 5", "Point 1 8.4 305.8 30.2 1.0 1.0", "Point 2 84.7 227.7 21.1 2.0 1.0",
"End of MTrackJ Data File")

test_that("Loading without arguments should have cl, id, t, x:z", {
expect_equivalent(read.mdf('test_mdf.mdf'),
test.df[,c('cl', 'id', 't', letters[24:26])])
expect_equal(read.mdf('test_mdf.mdf'),
test.df[,c('cl', 'id', 't', letters[24:26])],
ignore_attr = T)
})

test_that("Reading from file connection works when connection is closed", {
file <- "test_mdf.mdf"
con <- file(file)
expect_false(isOpen(con))
expect_equivalent(read.mdf(con),
test.df[,c('cl', 'id', 't', letters[24:26])])
expect_equal(read.mdf(con),
test.df[,c('cl', 'id', 't', letters[24:26])],
ignore_attr = T)
})

test_that("Testing drop.Z for 2D data", {
expect_equivalent(read.mdf('test_mdf.mdf', drop.Z = T),
test.df[,c('cl', 'id', 't', letters[24:25])])
expect_equal(read.mdf('test_mdf.mdf', drop.Z = T),
test.df[,c('cl', 'id', 't', letters[24:25])],
ignore_attr = T)
})

test_that("Include point numbers", {
expect_equivalent(read.mdf('test_mdf.mdf', include.point.numbers = T),
test.df[,c('cl', 'id', 't', letters[24:26], 'p')])
expect_equal(read.mdf('test_mdf.mdf', include.point.numbers = T),
test.df[,c('cl', 'id', 't', letters[24:26], 'p')],
ignore_attr = T)
})

test_that("Include channel", {
expect_equivalent(read.mdf('test_mdf.mdf', include.channel = T),
test.df[,c('cl', 'id', 't', letters[24:26], 'ch')])
expect_equal(read.mdf('test_mdf.mdf', include.channel = T),
test.df[,c('cl', 'id', 't', letters[24:26], 'ch')],
ignore_attr = T)
})

test_that("Reading from text works", {
expect_equivalent(read.mdf(text = ref_text),
test.df[,c('cl', 'id', 't', letters[24:26])])
expect_equal(read.mdf(text = ref_text),
test.df[,c('cl', 'id', 't', letters[24:26])],
ignore_attr = T)
})

test_that("Generate unique ids", {
# With one cluster (id should be uid)
temp.df <- read.mdf(text = ref_text_1_cluster, generate.unique.ids = T)
expect_equal(temp.df$uid, temp.df$id)
# With more clusters
expect_equivalent(read.mdf('test_mdf.mdf', generate.unique.ids = T),
test.df[,c('cl', 'id', 't', letters[24:26], 'uid')])
expect_equal(read.mdf('test_mdf.mdf', generate.unique.ids = T),
test.df[,c('cl', 'id', 't', letters[24:26], 'uid')],
ignore_attr = T)

})

Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-write-mdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ ref.mdf5s <- c('9b98632350636ab11735feed7fb60958', 'ebe73d04d76925f36c6fbeb74f07

test_that("Data frames with columns id, t, x, y, z (MotilyLab) can be exported
using default arguments (numeric columns)", {
expect_output(write.mdf(test.df[,c('uid','t', 'x', 'y', 'z')]),
ref_expected_output)
})
expect_output(write.mdf(test.df[,c('uid','t', 'x', 'y', 'z')]),
ref_expected_output)
})

test_that("Writing tibbles works", {
expect_output(write.mdf(tibble::as_tibble(test.df[,c('uid','t', 'x', 'y', 'z')])),
Expand Down Expand Up @@ -104,9 +104,9 @@ Track 5
Point 1 8.4 305.8 30.2 0.1 1
Point 2 84.7 227.7 21.1 0.2 1
End of MTrackJ Data File$"
expect_output(write.mdf(test.df[,c('uid','t', 'x', 'y', 'z')],
scale.time = 0.1),
expected_output)
expect_output(write.mdf(test.df[,c('uid','t', 'x', 'y', 'z')],
scale.time = 0.1),
expected_output)
})

test_that("Default channel is set correctly", {
Expand Down

0 comments on commit c82ad76

Please sign in to comment.