1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 08:32:04 +02:00

first isolate missing dates fix

This commit is contained in:
2019-05-13 14:56:23 +02:00
parent c4aa92b4a7
commit cc403169c6
15 changed files with 200 additions and 146 deletions

View File

@ -42,9 +42,12 @@ test_that("as.ab works", {
expect_warning(as.ab("Z00ZZ00")) # not yet available in data set
expect_warning(as.ab("UNKNOWN"))
expect_warning(as.ab(""))
expect_output(print(as.ab("amox")))
expect_identical(class(pull(antibiotics, ab)), "ab")
# first 5 chars of official name
expect_equal(as.character(as.atc(c("nitro", "cipro"))),
c("J01XE01", "J01MA02"))
@ -53,4 +56,7 @@ test_that("as.ab works", {
expect_equal(as.character(as.atc("AMX")),
"J01CA04")
expect_equal(as.character(as.ab("Phloxapen")),
"FLC")
})

View File

@ -48,4 +48,6 @@ test_that("creation of data sets is valid", {
test_that("CoL version info works", {
expect_identical(class(catalogue_of_life_version()),
c("catalogue_of_life_version", "list"))
expect_output(print(catalogue_of_life_version()))
})

35
tests/testthat/test-disk.R Executable file
View File

@ -0,0 +1,35 @@
# ==================================================================== #
# TITLE #
# Antidiskrobial Resistance (AMR) Analysis #
# #
# SOURCE #
# https://gitlab.com/msberends/AMR #
# #
# LICENCE #
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# #
# This R package was created for academic research and was publicly #
# released in the hope that it will be useful, but it comes WITHOUT #
# ANY WARRANTY OR LIABILITY. #
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
# ==================================================================== #
context("disk.R")
test_that("disk works", {
expect_true(as.disk(8) == as.disk("8"))
expect_true(is.disk(as.disk(8)))
expect_equal(suppressWarnings(as.logical(as.disk("INVALID VALUE"))), NA)
# all levels should be valid disks
expect_silent(as.disk(levels(as.disk(15))))
expect_warning(as.disk("INVALID VALUE"))
})

View File

@ -25,7 +25,7 @@ test_that("first isolates work", {
# first isolates
expect_equal(
sum(
first_isolate(tbl = septic_patients,
first_isolate(x = septic_patients,
col_date = "date",
col_patient_id = "patient_id",
col_mo = "mo",
@ -37,7 +37,7 @@ test_that("first isolates work", {
expect_equal(
suppressWarnings(
sum(
first_isolate(tbl = septic_patients %>% mutate(keyab = key_antibiotics(.)),
first_isolate(x = septic_patients %>% mutate(keyab = key_antibiotics(.)),
# let syntax determine these automatically:
# col_date = "date",
# col_patient_id = "patient_id",
@ -51,7 +51,7 @@ test_that("first isolates work", {
expect_equal(
suppressWarnings(
sum(
first_isolate(tbl = septic_patients %>% dplyr::as_tibble() %>% mutate(keyab = key_antibiotics(.)),
first_isolate(x = septic_patients %>% dplyr::as_tibble() %>% mutate(keyab = key_antibiotics(.)),
# let syntax determine these automatically:
# col_date = "date",
# col_patient_id = "patient_id",
@ -65,7 +65,7 @@ test_that("first isolates work", {
expect_equal(
suppressWarnings(
sum(
first_isolate(tbl = septic_patients %>% mutate(keyab = key_antibiotics(.)),
first_isolate(x = septic_patients %>% mutate(keyab = key_antibiotics(.)),
col_date = "date",
col_patient_id = "patient_id",
col_mo = "mo",
@ -79,7 +79,7 @@ test_that("first isolates work", {
expect_equal(
suppressWarnings(
sum(
first_isolate(tbl = septic_patients %>% mutate(keyab = key_antibiotics(.)),
first_isolate(x = septic_patients %>% mutate(keyab = key_antibiotics(.)),
col_date = "date",
col_patient_id = "patient_id",
col_mo = "mo",
@ -106,7 +106,7 @@ test_that("first isolates work", {
random_rows <- sample(x = 1:2000, size = 1500, replace = FALSE)
expect_lt(
sum(
first_isolate(tbl = mutate(septic_patients,
first_isolate(x = mutate(septic_patients,
specimen = if_else(row_number() %in% random_rows,
"Urine",
"Other")),
@ -121,7 +121,7 @@ test_that("first isolates work", {
# same, but now exclude ICU
expect_lt(
sum(
first_isolate(tbl = mutate(septic_patients,
first_isolate(x = mutate(septic_patients,
specimen = if_else(row_number() %in% random_rows,
"Urine",
"Other")),
@ -175,4 +175,16 @@ test_that("first isolates work", {
col_mo = "mo",
col_patient_id = "patient_id"))
df <- septic_patients
df[1:100, "date"] <- NA
expect_equal(
sum(
first_isolate(x = df,
col_date = "date",
col_patient_id = "patient_id",
col_mo = "mo",
info = TRUE),
na.rm = TRUE),
1279)
})