-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add some tests for osem_measurements_archive
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
source('testhelpers.R') | ||
|
||
context('osem_box_to_archivename()') | ||
|
||
try({ | ||
boxes = osem_boxes(grouptag = 'ifgi') | ||
box = filter(boxes, row_number() == 1) | ||
}) | ||
|
||
test_that('osem_box_to_archive_name does the correct character replacements', { | ||
b = data.frame( | ||
name = 'aA1._- äß!"?$%&/', | ||
X_id = 'UUID' | ||
) | ||
|
||
archivename = opensensmapr:::osem_box_to_archivename(b) | ||
expect_equal(archivename, 'UUID-aA1._-__________') | ||
}) | ||
|
||
test_that('osem_box_to_archive_name works for one box', { | ||
if (is.null(box)) skip('no box data could be fetched') | ||
|
||
archivename = opensensmapr:::osem_box_to_archivename(box) | ||
expect_length(archivename, 1) | ||
expect_type(archivename, 'character') | ||
}) | ||
|
||
test_that('osem_box_to_archive_name works for multiple boxes', { | ||
if (is.null(boxes)) skip('no box data available') | ||
|
||
archivename = opensensmapr:::osem_box_to_archivename(boxes) | ||
expect_length(archivename, nrow(boxes)) | ||
expect_type(archivename, 'character') | ||
}) | ||
|
||
context('osem_measurements_archive()') | ||
|
||
test_that('osem_measurements_archive works for one box', { | ||
if (is.null(box)) skip('no box data could be fetched') | ||
|
||
m = osem_measurements_archive(box, as.POSIXlt('2018-08-08')) | ||
expect_length(m, nrow(box$sensors[[1]]) + 1) # one column for each sensor + createdAt | ||
expect_s3_class(m, c('osem_measurements', 'tbl_df')) | ||
}) | ||
|
||
test_that('osem_measurements_archive fails for multiple boxes', { | ||
if (is.null(boxes)) skip('no box data available') | ||
|
||
expect_error( | ||
osem_measurements_archive(boxes, as.POSIXlt('2018-08-08')), | ||
'this function only works for exactly one senseBox!' | ||
) | ||
}) |