From 22bf5e26a7cc4f9c3f9612007c0dd81825733d85 Mon Sep 17 00:00:00 2001 From: noerw Date: Mon, 7 May 2018 01:10:53 +0200 Subject: [PATCH] increase test coverage, fixes #8 --- tests/testthat/test_box.R | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/testthat/test_box.R b/tests/testthat/test_box.R index db0698f..745cd68 100644 --- a/tests/testthat/test_box.R +++ b/tests/testthat/test_box.R @@ -3,6 +3,7 @@ context('box') try({ boxes = osem_boxes() + box = osem_box(boxes$X_id[[1]]) }) test_that('a single box can be retrieved by ID', { @@ -14,6 +15,7 @@ test_that('a single box can be retrieved by ID', { expect_true('data.frame' %in% class(box)) expect_true(nrow(box) == 1) expect_true(box$X_id == boxes$X_id[[1]]) + expect_silent(osem_box(boxes$X_id[[1]])) }) @@ -22,3 +24,23 @@ test_that('[.sensebox maintains attributes', { expect_true(all(attributes(boxes[1:nrow(boxes), ]) %in% attributes(boxes))) }) + +test_that("print.sensebox filters important attributes", { + msg = capture.output({ + print(box) + }) + expect_false(any(grepl('description', msg)), 'should filter attribute "description"') +}) + +test_that("summary.sensebox outputs all metrics", { + msg = capture.output({ + summary(box) + }) + expect_true(any(grepl('sensors per box:', msg))) + expect_true(any(grepl('oldest box:', msg))) + expect_true(any(grepl('newest box:', msg))) + expect_true(any(grepl('\\$last_measurement_within', msg))) + expect_true(any(grepl('boxes by model:', msg))) + expect_true(any(grepl('boxes by exposure:', msg))) + expect_true(any(grepl('boxes total: 1', msg))) +})