Skip to content

Commit

Permalink
add unit test for #1233
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentvanhees committed Nov 21, 2024
1 parent a926321 commit 2973049
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/testthat/test_read.myacc.csv.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ test_that("read.myacc.csv can handle files without header, no decimal places in
testfile[4] = "testcsv4.csv"
write.csv(S3, file = testfile[4], row.names = FALSE)

# UNIXsec
testfile[5] = "testcsv5.csv"
S5 = S1
S5$time = as.numeric(S5$time)
write.csv(S5, file = testfile[5], row.names = FALSE)

# UNIXmsec
testfile[6] = "testcsv6.csv"
S6 = S5
S6$time = S6$time * 1000
write.csv(S6, file = testfile[6], row.names = FALSE)

# attempt to load
D1 = read.myacc.csv(rmc.file = testfile[1], rmc.nrow = 20, rmc.dec = ".",
rmc.firstrow.acc = 1, rmc.firstrow.header = c(),
Expand Down Expand Up @@ -196,6 +208,29 @@ test_that("read.myacc.csv can handle files without header, no decimal places in
expect_that(ncol(D4$data), equals(4))
expect_that(D4$header, equals("no header"))

# Timestamps in UNIXsec
D5 = read.myacc.csv(rmc.file = testfile[5], rmc.nrow = 20, rmc.dec = ".",
rmc.firstrow.acc = 1, rmc.firstrow.header = c(),
rmc.col.acc = c(1,3,4), rmc.col.temp = 5, rmc.col.time = 2,
rmc.unit.acc = "g",
rmc.unit.time = "UNIXsec",
desiredtz = "Europe/London", rmc.sf = sf)

expect_equal(mean(D5$data$x), 0.1078671, tol = 0.0001)
expect_equal(mean(D5$data$y), -0.06675716, tol = 0.0001)
expect_equal(D5$data$time[1], 1667394076, tol = 0.1)

# Timestamps in UNIXmsec
D6 = read.myacc.csv(rmc.file = testfile[6], rmc.nrow = 20, rmc.dec = ".",
rmc.firstrow.acc = 1, rmc.firstrow.header = c(),
rmc.col.acc = c(1,3,4), rmc.col.temp = 5, rmc.col.time = 2,
rmc.unit.acc = "g",
rmc.unit.time = "UNIXmsec",
desiredtz = "Europe/London", rmc.sf = sf)
expect_equal(mean(D6$data$x), 0.1078671, tol = 0.0001)
expect_equal(mean(D6$data$y), -0.06675716, tol = 0.0001)
expect_equal(D6$data$time[1], 1667394076, tol = 0.1)

for (i in 1:length(testfile)) {
expect_true(file.exists(testfile[i]))
if (file.exists(testfile[i])) file.remove(testfile[i])
Expand Down

0 comments on commit 2973049

Please sign in to comment.