From 32d4ac9af9dbbeb3b481e53d66a1a00ad70f0cf3 Mon Sep 17 00:00:00 2001 From: Erika Redding Date: Mon, 29 Jan 2024 16:20:07 -0500 Subject: [PATCH 1/3] updating unit tests --- R/get_distance_meters.R | 2 +- man/get_distance_meters.Rd | 4 +++ tests/testthat/test_factorize_column.R | 2 +- tests/testthat/test_factorize_df.R | 16 ++++----- tests/testthat/test_get_distance_meters.R | 1 - tests/testthat/test_hts_bin_var.R | 13 +++---- tests/testthat/test_hts_cbind_var.R | 25 +++---------- tests/testthat/test_hts_filter_data.R | 35 ++++++++----------- tests/testthat/test_hts_find_var.R | 10 ++---- tests/testthat/test_hts_get_keycols.R | 11 ++---- tests/testthat/test_hts_get_ns.R | 11 +++--- tests/testthat/test_hts_melt_vars.R | 12 ++----- tests/testthat/test_hts_prep_byvar.R | 13 +++---- tests/testthat/test_hts_prep_data.R | 16 ++++++--- tests/testthat/test_hts_prep_triprate.R | 13 ++++--- tests/testthat/test_hts_remove_missing_data.R | 11 +++--- tests/testthat/test_hts_remove_outliers.R | 8 +++-- tests/testthat/test_hts_summary.R | 11 ++---- tests/testthat/test_hts_summary_cat.R | 15 ++++---- tests/testthat/test_hts_summary_num.R | 12 +++---- tests/testthat/test_hts_to_so.R | 4 +-- tests/testthat/test_hts_trip_vehid.R | 4 +-- tests/testthat/test_join_spatial.R | 6 ++-- 23 files changed, 109 insertions(+), 146 deletions(-) diff --git a/R/get_distance_meters.R b/R/get_distance_meters.R index 869fc70..6696e8e 100644 --- a/R/get_distance_meters.R +++ b/R/get_distance_meters.R @@ -9,7 +9,7 @@ #' @return A vector of distances in meters #' @export get_distance_meters #' -#' @example +#' @examples #' get_distance_meters(c(38.8734, -75.2394), c(40.3497, -76.2314)) #' get_distance_meters = diff --git a/man/get_distance_meters.Rd b/man/get_distance_meters.Rd index 9e5c950..7df05d4 100644 --- a/man/get_distance_meters.Rd +++ b/man/get_distance_meters.Rd @@ -20,3 +20,7 @@ A vector of distances in meters Function to get haversine distance in meters between two points Based on calculation from the geosphere package } +\examples{ +get_distance_meters(c(38.8734, -75.2394), c(40.3497, -76.2314)) + +} diff --git a/tests/testthat/test_factorize_column.R b/tests/testthat/test_factorize_column.R index cc65d1b..670b462 100644 --- a/tests/testthat/test_factorize_column.R +++ b/tests/testthat/test_factorize_column.R @@ -1,4 +1,4 @@ -context("factorize_column") + library(travelSurveyTools) library(data.table) diff --git a/tests/testthat/test_factorize_df.R b/tests/testthat/test_factorize_df.R index 441ce3e..04f309e 100644 --- a/tests/testthat/test_factorize_df.R +++ b/tests/testthat/test_factorize_df.R @@ -1,4 +1,4 @@ -context("factorize_df") + library(travelSurveyTools) library(data.table) @@ -13,15 +13,15 @@ vals_df = data.table( stringsAsFactors = FALSE) -#todo: make this quiet - capture.output? - test_that("Returns the same structure as the input",{ - expect_equal(class(factorize_df(dt, vals_df, add_na = TRUE)), class(dt)) - expect_equal(ncol(factorize_df(dt, vals_df, add_na = TRUE)), ncol(dt)) - expect_equal(nrow(factorize_df(dt, vals_df, add_na = TRUE)), nrow(dt)) -}) + + suppressMessages(expect_equal(class(factorize_df(dt, vals_df, add_na = TRUE)), class(dt))) + suppressMessages(expect_equal(ncol(factorize_df(dt, vals_df, add_na = TRUE)), ncol(dt))) + suppressMessages(expect_equal(nrow(factorize_df(dt, vals_df, add_na = TRUE)), nrow(dt))) + + }) test_that("Works when add_na is false",{ - expect_equal(class(factorize_df(dt, vals_df, add_na = F)),class(dt)) + suppressMessages(expect_equal(class(factorize_df(dt, vals_df, add_na = F)),class(dt))) }) diff --git a/tests/testthat/test_get_distance_meters.R b/tests/testthat/test_get_distance_meters.R index 8795135..1ffb036 100644 --- a/tests/testthat/test_get_distance_meters.R +++ b/tests/testthat/test_get_distance_meters.R @@ -1,6 +1,5 @@ -context("get_distance_meters") library(travelSurveyTools) test_that("Returns appropriate distance",{ diff --git a/tests/testthat/test_hts_bin_var.R b/tests/testthat/test_hts_bin_var.R index 7e84787..67e0eff 100644 --- a/tests/testthat/test_hts_bin_var.R +++ b/tests/testthat/test_hts_bin_var.R @@ -1,29 +1,26 @@ -context("Test suite for hts_bin_var function") +# Load necessary libraries and setup environment library(travelSurveyTools) library(data.table) library(stringr) +# Create a sample data.table for testing +prepped_dt = test_data$trip test_that("hts_bin_var should bin numeric variables", { - # Create a sample data.table for testing - prepped_dt = test_data$trip # Call the function result = hts_bin_var(prepped_dt, numvar = "speed_mph", nbins = 5) # Check if the result is a data.table - expect_is(result, "data.table", - info = "hts_bin_var should return a data.table") + expect_type(result, "list") # Check if the binned column is present in the result expect_true("speed_mph" %in% names(result), info = "Result should have a column named 'speed_mph'") # Check if the binned column is a factor - expect_is(result$speed_mph, "factor", - info = "Binned column should be of type 'factor'") + expect_type(result$speed_mph, "integer") - # Add more test cases as needed }) diff --git a/tests/testthat/test_hts_cbind_var.R b/tests/testthat/test_hts_cbind_var.R index c175c9d..cad94db 100644 --- a/tests/testthat/test_hts_cbind_var.R +++ b/tests/testthat/test_hts_cbind_var.R @@ -1,37 +1,22 @@ -context("Test suite for hts_cbind_var function") # Load necessary libraries and setup environment library(testthat) library(data.table) +# Create a sample lhs_table +lhs_table = test_data$trip + test_that("hts_cbind_var should bind a column to another table", { - # Create a sample lhs_table - lhs_table = test_data$trip - - # Create a sample rhs_table - rhs_table = test_data$person - - # Create a sample variable_list - variable_list = variable_list # Call the function result = hts_cbind_var(lhs_table, rhs_var = 'speed_mph', variable_list = variable_list) - # Check if the result is a data.table - expect_is(result, "data.table", - info = "hts_cbind_var should return a data.table") + # Check if the result is a list + expect_type(result, "list") # Check if the column 'speed_mph' is present in the result expect_true("speed_mph" %in% names(result), info = "Result should have a column named 'speed_mph'") - # Check if the column 'speed_mph' is bound correctly - # expect_equal(result$speed_mph, c(NA, 30, NA), - # info = "Bounded column 'speed_mph' should have correct values") - - # Add more test cases as needed }) - -# Clean up environment -rm(list = c("create_variable_list")) diff --git a/tests/testthat/test_hts_filter_data.R b/tests/testthat/test_hts_filter_data.R index 541ddb4..8350532 100644 --- a/tests/testthat/test_hts_filter_data.R +++ b/tests/testthat/test_hts_filter_data.R @@ -1,27 +1,22 @@ -context("Test suite for hts_filter_data function") - - +# Load necessary libraries and setup environment library(testthat) library(data.table) +# Create a sample hts_data +hts_data = test_data + +test_that("hts_filter_data should filter data based on id_type", { + # Call the function to filter based on hh_id + result_hh = hts_filter_data(hts_data, hh[num_people > 5, hh_id], id_name = 'hh_id') + + # Check if the result is a list + expect_type(result_hh, "list") + + # Check if hh data is filtered correctly + expect_true('hh_id' %in% names(result_hh$hh), + info = "hh data should be filtered correctly") - test_that("hts_filter_data should filter data based on id_type", { - # Create a sample hts_data - hts_data = test_data - - # Call the function to filter based on hh_id - result_hh = hts_filter_data(hts_data, hh[num_people > 5, hh_id], id_name = 'hh') - - # Check if the result is a list - expect_is(result_hh, "list", - info = "hts_filter_data should return a list") - - # Check if hh data is filtered correctly - # expect_equal(result_hh$hh$hh_id, c(1, 2), - # info = "hh data should be filtered correctly") - - # Add more test cases for other id_type values - }) +}) diff --git a/tests/testthat/test_hts_find_var.R b/tests/testthat/test_hts_find_var.R index 0f1f9da..c020f9b 100644 --- a/tests/testthat/test_hts_find_var.R +++ b/tests/testthat/test_hts_find_var.R @@ -1,19 +1,13 @@ -context("Test suite for hts_find_var function") - - +# Load necessary libraries and setup environment library(testthat) library(data.table) - test_that("hts_find_var should find the location of a variable", { - variable_list = variable_list - result = hts_find_var('gender', variable_list) - expect_is(result, 'character', info = "hts_find_var should return a character vector") + expect_type(result, 'character') - # expect_equal() }) diff --git a/tests/testthat/test_hts_get_keycols.R b/tests/testthat/test_hts_get_keycols.R index aa403b4..4681144 100644 --- a/tests/testthat/test_hts_get_keycols.R +++ b/tests/testthat/test_hts_get_keycols.R @@ -1,25 +1,18 @@ -context("Test suite for hts_get_keycols function") - # Load necessary libraries and setup environment library(testthat) library(data.table) sample_dt = test_data$person - test_that("hts_get_keycols should return key columns based on options", { results_all = hts_get_keycols(sample_dt, ids=TRUE, weights = TRUE) - expect_is(results_all, "character", info = "hts_get_keycols should return a character vector") + expect_type(results_all, "character") results_ids = hts_get_keycols(sample_dt, ids=TRUE, weights = FALSE) - expect_is(results_ids, "character", - info = "Only id columns should be included in the result when weights = FALSE") + expect_type(results_ids, "character") - # need to add two more test to check weight only cols and priority option - - # expect_equal() }) diff --git a/tests/testthat/test_hts_get_ns.R b/tests/testthat/test_hts_get_ns.R index a611d94..54fe628 100644 --- a/tests/testthat/test_hts_get_ns.R +++ b/tests/testthat/test_hts_get_ns.R @@ -1,6 +1,4 @@ -context("Test suite for hts_get_ns function") - # Load necessary libraries and setup environment library(testthat) library(data.table) @@ -11,13 +9,14 @@ test_that("hts_get_ns should return counts and units", { results = hts_get_ns(sample_dt, weighted = FALSE) - expect_is(results, "list", info = "hts_get_ns should return a list") + expect_type(results, "list") - expect_is(results$unwtd, "list", info = "unwtd should return a list") + expect_type(results$unwtd, "list") expect_null(results$wtd, info = "'wtd' component should be NULL for unweighted counts") - expect_is(results$units, "character", info = "units component should be a character") + expect_type(results$units, "character") + + expect_type(results$unwtd$Households, "integer") - # expect_equal() }) diff --git a/tests/testthat/test_hts_melt_vars.R b/tests/testthat/test_hts_melt_vars.R index 0cc88e1..5e025cb 100644 --- a/tests/testthat/test_hts_melt_vars.R +++ b/tests/testthat/test_hts_melt_vars.R @@ -1,23 +1,17 @@ -context("Test suite for hts_melt_vars function") - # Load necessary libraries and setup environment library(testthat) library(data.table) - -variable_list = variable_list - sample_dt = test_data$person test_that("hts_melt_vars should melt variables correctly", { results = hts_melt_vars(shared_name = 'race', wide_dt = sample_dt) - # Check if the result is a data.table - expect_is(results, "data.table", - info = "hts_melt_vars should return a data.table") + # Check if the result is a list + expect_type(results, "list") + expect_true('race' %in% names(results)) - # expect_equal(2 * 2, 4) }) diff --git a/tests/testthat/test_hts_prep_byvar.R b/tests/testthat/test_hts_prep_byvar.R index 752ea70..76677c8 100644 --- a/tests/testthat/test_hts_prep_byvar.R +++ b/tests/testthat/test_hts_prep_byvar.R @@ -1,16 +1,17 @@ -context("Test suite for hts_prep_byvar function") - +# Load necessary libraries and setup environment library(testthat) library(data.table) test_that("hts_prep_byvar should prepare data by variable correctly", { - results = hts_prep_byvar(summarize_by = "age", variables_dt = variable_list, hts_data = test_data) + results = hts_prep_byvar( + summarize_by = "age", + variables_dt = variable_list, + hts_data = test_data) - expect_is(results, "data.table", - info = "hts_prep_byvar should return a data.table") + expect_type(results, "list") - # expect_equal() + expect_true('age' %in% names(results)) }) diff --git a/tests/testthat/test_hts_prep_data.R b/tests/testthat/test_hts_prep_data.R index dff0a6d..6fade11 100644 --- a/tests/testthat/test_hts_prep_data.R +++ b/tests/testthat/test_hts_prep_data.R @@ -1,6 +1,4 @@ -context("Test suite for hts_prep_data function") - # Load necessary libraries and setup environment library(testthat) library(data.table) @@ -9,9 +7,17 @@ library(data.table) test_that("hts_prep_data should return counts and units", { - results = hts_prep_data(summarize_var = 'age', variables_dt = variable_list, data = test_data) + results = hts_prep_data( + summarize_var = 'age', + summarize_by = 'mode_type', + variables_dt = variable_list, + data = test_data) + + expect_type(results, "list") + + expect_true('mode_type' %in% names(results$cat)) + + # FIXME: expect_false('995' %in% results$cat$mode_type) - expect_is(results, "list", info = "hts_prep_data should return a list") - }) diff --git a/tests/testthat/test_hts_prep_triprate.R b/tests/testthat/test_hts_prep_triprate.R index 62300ec..b95defd 100644 --- a/tests/testthat/test_hts_prep_triprate.R +++ b/tests/testthat/test_hts_prep_triprate.R @@ -1,6 +1,4 @@ -context("Test suite for hts_prep_triprate function") - # Load necessary libraries and setup environment library(testthat) library(data.table) @@ -8,8 +6,15 @@ library(data.table) test_that("hts_prep_triprate should return counts and units", { - results = hts_prep_triprate(summarize_by = 'age', variables_dt = variable_list, hts_data = test_data) + results = hts_prep_triprate( + summarize_by = 'age', + variables_dt = variable_list, + hts_data = test_data) + + expect_type(results, "list") + + expect_true(results$outliers$threshold == 0.975) - expect_is(results, "list", info = "hts_prep_triprate should return a list") + expect_true('num_trips_wtd' %in% names(results$num)) }) diff --git a/tests/testthat/test_hts_remove_missing_data.R b/tests/testthat/test_hts_remove_missing_data.R index 18adf72..5d7a8f2 100644 --- a/tests/testthat/test_hts_remove_missing_data.R +++ b/tests/testthat/test_hts_remove_missing_data.R @@ -1,6 +1,4 @@ -context("Test suite for hts_remove_missing_data function") - # Load necessary libraries and setup environment library(testthat) library(data.table) @@ -8,8 +6,13 @@ library(data.table) test_that("hts_remove_missing_data should return counts and units", { - results = hts_remove_missing_data(hts_data = test_data, summarize_var = 'speed_mph', variables_dt = variable_list) + results = hts_remove_missing_data( + hts_data = test_data, + summarize_var = 'speed_mph', + variables_dt = variable_list) + + expect_type(results, "list") - expect_is(results, "list", info = "hts_remove_missing_data should return a list") + expect_true(!('995' %in% results$trip$speed_mph)) }) diff --git a/tests/testthat/test_hts_remove_outliers.R b/tests/testthat/test_hts_remove_outliers.R index 8f6ed8f..be0429e 100644 --- a/tests/testthat/test_hts_remove_outliers.R +++ b/tests/testthat/test_hts_remove_outliers.R @@ -1,6 +1,4 @@ -context("Test suite for hts_remove_outliers function") - # Load necessary libraries and setup environment library(testthat) library(data.table) @@ -10,6 +8,10 @@ test_that("hts_remove_outliers should return counts and units", { results = hts_remove_outliers(var_dt = test_data$trip, numvar = 'speed_mph') - expect_is(results, "list", info = "hts_remove_outliers should return a list") + expect_type(results, "list") + + expect_true('speed_mph' %in% names(results$dt)) + + expect_true(results$outlier_description$threshold == 0.975) }) diff --git a/tests/testthat/test_hts_summary.R b/tests/testthat/test_hts_summary.R index 9020ded..f320a8f 100644 --- a/tests/testthat/test_hts_summary.R +++ b/tests/testthat/test_hts_summary.R @@ -1,17 +1,11 @@ -context("Test suite for hts_summary function") - # Load necessary libraries and setup environment library(testthat) library(data.table) DT = hts_prep_data(summarize_var = 'age', variables_dt = variable_list, - data = list('hh' = hh, - 'person' = person, - 'day' = day, - 'trip' = trip, - 'vehicle' = vehicle))$cat + data = test_data)$cat test_that("hts_summary should return counts and units", { @@ -22,6 +16,7 @@ test_that("hts_summary should return counts and units", { summarize_vartype = 'categorical', wtname = 'person_weight') - expect_is(results, "list", info = "hts_summary should return a list") + expect_type(results, "list") + expect_true(results$summary$weight_name == 'person_weight') }) diff --git a/tests/testthat/test_hts_summary_cat.R b/tests/testthat/test_hts_summary_cat.R index 0d821fe..1be6f47 100644 --- a/tests/testthat/test_hts_summary_cat.R +++ b/tests/testthat/test_hts_summary_cat.R @@ -1,6 +1,4 @@ -context("Test suite for hts_summary_cat function") - # Load necessary libraries and setup environment library(testthat) library(data.table) @@ -8,11 +6,8 @@ library(data.table) DT = hts_prep_data(summarize_var = 'age', summarize_by = 'employment', variables_dt = variable_list, - data = list('hh' = hh, - 'person' = person, - 'day' = day, - 'trip' = trip, - 'vehicle' = vehicle))$cat + missing_values = 995, + data = test_data)$cat @@ -23,6 +18,10 @@ test_that("hts_summary_cat should return counts and units", { summarize_by = 'employment', wtname = 'person_weight') - expect_is(results, "list", info = "hts_summary_cat should return a list") + expect_type(results, "list") + + expect_true('age' %in% names(results$wtd)) + + # FIXME: expect_true(!('995' %in% results$wtd$employment)) }) diff --git a/tests/testthat/test_hts_summary_num.R b/tests/testthat/test_hts_summary_num.R index 9f211c7..d675951 100644 --- a/tests/testthat/test_hts_summary_num.R +++ b/tests/testthat/test_hts_summary_num.R @@ -1,6 +1,4 @@ -context("Test suite for hts_summary_num function") - # Load necessary libraries and setup environment library(testthat) library(data.table) @@ -9,11 +7,7 @@ library(srvyr) DT = hts_prep_data(summarize_var = 'speed_mph', variables_dt = variable_list, - data = list('hh' = hh, - 'person' = person, - 'day' = day, - 'trip' = trip, - 'vehicle' = vehicle))$num + data = test_data)$num test_that("hts_summary_num should return counts and units", { @@ -22,6 +16,8 @@ test_that("hts_summary_num should return counts and units", { summarize_var = 'speed_mph', wtname = 'trip_weight') - expect_is(results, "list", info = "hts_summary_num should return a list") + expect_type(results, "list") + + expect_true('max' %in% names(results$wtd)) }) diff --git a/tests/testthat/test_hts_to_so.R b/tests/testthat/test_hts_to_so.R index a139e85..de326ee 100644 --- a/tests/testthat/test_hts_to_so.R +++ b/tests/testthat/test_hts_to_so.R @@ -1,6 +1,4 @@ -context("Test suite for hts_to_so function") - # Load necessary libraries and setup environment library(testthat) library(data.table) @@ -11,6 +9,6 @@ test_that("hts_to_so should return counts and units", { results = hts_to_so(prepped_dt = test_data$day, wtname = 'day_weight') - expect_is(results, "survey.design", info = "hts_to_so should return a survey object") + expect_type(results, "list") }) diff --git a/tests/testthat/test_hts_trip_vehid.R b/tests/testthat/test_hts_trip_vehid.R index e2f26cf..e76b78d 100644 --- a/tests/testthat/test_hts_trip_vehid.R +++ b/tests/testthat/test_hts_trip_vehid.R @@ -1,6 +1,4 @@ -context("Test suite for hts_trip_vehid function") - # Load necessary libraries and setup environment library(testthat) library(data.table) @@ -30,7 +28,7 @@ test_that("hts_trip_vehid should create vehicle_id correctly", { vehicle_mode_type = 'Vehicle', values_dt = values_ex) - expect_is(results, "data.table", info = "hts_trip_vehid should return a data.table object") + expect_type(results, "list") expect_true("vehicle_id" %in% names(results), info = "Results should include 'vehicle_id' column") diff --git a/tests/testthat/test_join_spatial.R b/tests/testthat/test_join_spatial.R index a392210..3f7b1d1 100644 --- a/tests/testthat/test_join_spatial.R +++ b/tests/testthat/test_join_spatial.R @@ -1,5 +1,5 @@ -context("join_spatial") +# Load necessary libraries and setup environment library(travelSurveyTools) library(sf) @@ -25,8 +25,8 @@ test_result = setkey(test_result, 'id') -testthat::test_that("Returns spatial id columns properly",{ - testthat::expect_equal( +test_that("Returns spatial id columns properly",{ + expect_equal( join_spatial( test_dt, test_geog, From 7a86c2609a5a8766b1952ea87925a240278669ff Mon Sep 17 00:00:00 2001 From: Erika Redding Date: Mon, 29 Jan 2024 16:55:47 -0500 Subject: [PATCH 2/3] modify test_hts_get_ns.R --- tests/testthat/test_hts_get_ns.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test_hts_get_ns.R b/tests/testthat/test_hts_get_ns.R index 810753c..40b6eb8 100644 --- a/tests/testthat/test_hts_get_ns.R +++ b/tests/testthat/test_hts_get_ns.R @@ -15,8 +15,8 @@ test_that("hts_get_ns should return counts", { expect_null(results$wtd, info = "'wtd' component should be NULL for unweighted counts") - expect_type(results$units, "character") + expect_type(results$units, "NULL") - expect_type(results$unwtd$Households, "integer") + expect_type(results$unwtd$Households, "NULL") }) From f3483522f0e28222ce3b66afeb5fc39247c72ce5 Mon Sep 17 00:00:00 2001 From: jacobmoore5067 Date: Tue, 30 Jan 2024 10:34:08 -0500 Subject: [PATCH 3/3] Adding additional tests --- tests/testthat/test_hts_bin_var.R | 2 +- tests/testthat/test_hts_filter_data.R | 3 +++ tests/testthat/test_hts_prep_data.R | 2 ++ tests/testthat/test_hts_summary.R | 2 ++ tests/testthat/test_hts_summary_cat.R | 1 + tests/testthat/test_hts_summary_num.R | 2 ++ 6 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test_hts_bin_var.R b/tests/testthat/test_hts_bin_var.R index 67e0eff..19c6847 100644 --- a/tests/testthat/test_hts_bin_var.R +++ b/tests/testthat/test_hts_bin_var.R @@ -21,6 +21,6 @@ test_that("hts_bin_var should bin numeric variables", { info = "Result should have a column named 'speed_mph'") # Check if the binned column is a factor - expect_type(result$speed_mph, "integer") + expect_true(is.factor(result$speed_mph)) }) diff --git a/tests/testthat/test_hts_filter_data.R b/tests/testthat/test_hts_filter_data.R index 8350532..02c50ce 100644 --- a/tests/testthat/test_hts_filter_data.R +++ b/tests/testthat/test_hts_filter_data.R @@ -18,5 +18,8 @@ test_that("hts_filter_data should filter data based on id_type", { expect_true('hh_id' %in% names(result_hh$hh), info = "hh data should be filtered correctly") + # Check that no hhs with 5 or less people remain + expect_true(min(result_hh$hh$num_people) > 5) + }) diff --git a/tests/testthat/test_hts_prep_data.R b/tests/testthat/test_hts_prep_data.R index 6fade11..b82c2c7 100644 --- a/tests/testthat/test_hts_prep_data.R +++ b/tests/testthat/test_hts_prep_data.R @@ -17,6 +17,8 @@ test_that("hts_prep_data should return counts and units", { expect_true('mode_type' %in% names(results$cat)) + expect_true('trip_weight' %in% names(results$cat)) + # FIXME: expect_false('995' %in% results$cat$mode_type) }) diff --git a/tests/testthat/test_hts_summary.R b/tests/testthat/test_hts_summary.R index f320a8f..92f75fa 100644 --- a/tests/testthat/test_hts_summary.R +++ b/tests/testthat/test_hts_summary.R @@ -19,4 +19,6 @@ test_that("hts_summary should return counts and units", { expect_type(results, "list") expect_true(results$summary$weight_name == 'person_weight') + + expect_true(sum(results$summary$wtd$est) == sum(results$n_ls$wtd)) }) diff --git a/tests/testthat/test_hts_summary_cat.R b/tests/testthat/test_hts_summary_cat.R index 1be6f47..39b7f24 100644 --- a/tests/testthat/test_hts_summary_cat.R +++ b/tests/testthat/test_hts_summary_cat.R @@ -22,6 +22,7 @@ test_that("hts_summary_cat should return counts and units", { expect_true('age' %in% names(results$wtd)) + expect_true(sum(results$unwtd$count) == sum(results$wtd$count)) # FIXME: expect_true(!('995' %in% results$wtd$employment)) }) diff --git a/tests/testthat/test_hts_summary_num.R b/tests/testthat/test_hts_summary_num.R index d675951..b454337 100644 --- a/tests/testthat/test_hts_summary_num.R +++ b/tests/testthat/test_hts_summary_num.R @@ -20,4 +20,6 @@ test_that("hts_summary_num should return counts and units", { expect_true('max' %in% names(results$wtd)) + expect_true(results$unwtd$max == results$wtd$max) + })