Skip to content

Commit

Permalink
adding remaining tests #61 #49 #45
Browse files Browse the repository at this point in the history
  • Loading branch information
erika-redding committed Jan 18, 2024
1 parent c4404a8 commit 210f446
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 2 deletions.
17 changes: 17 additions & 0 deletions tests/testthat/test-hts_prep_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

context("Test suite for hts_prep_data function")

# Load necessary libraries and setup environment
library(testthat)
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)

expect_is(results, "list", info = "hts_prep_data should return a list")

})

15 changes: 15 additions & 0 deletions tests/testthat/test-hts_prep_triprate.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

context("Test suite for hts_prep_triprate function")

# Load necessary libraries and setup environment
library(testthat)
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)

expect_is(results, "list", info = "hts_prep_triprate should return a list")

})
15 changes: 15 additions & 0 deletions tests/testthat/test-hts_remove_missing_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

context("Test suite for hts_remove_missing_data function")

# Load necessary libraries and setup environment
library(testthat)
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)

expect_is(results, "list", info = "hts_remove_missing_data should return a list")

})
15 changes: 15 additions & 0 deletions tests/testthat/test-hts_remove_outliers.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

context("Test suite for hts_remove_outliers function")

# Load necessary libraries and setup environment
library(testthat)
library(data.table)


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")

})
18 changes: 18 additions & 0 deletions tests/testthat/test-hts_summary.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

context("Test suite for hts_summary function")

# Load necessary libraries and setup environment
library(testthat)
library(data.table)


test_that("hts_summary should return counts and units", {

results = hts_summary(
test_data,
summarize_var = 'race',
variables_dt = variable_list)

expect_is(results, "list", info = "hts_summary should return a list")

})
18 changes: 18 additions & 0 deletions tests/testthat/test-hts_summary_cat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

context("Test suite for hts_summary_cat function")

# Load necessary libraries and setup environment
library(testthat)
library(data.table)


test_that("hts_summary_cat should return counts and units", {

results = hts_summary_cat(
prepped_dt = test_data$person,
summarize_var = 'age',
variable_list = variable_list)

expect_is(results, "list", info = "hts_summary_cat should return a list")

})
17 changes: 17 additions & 0 deletions tests/testthat/test-hts_summary_num.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

context("Test suite for hts_summary_num function")

# Load necessary libraries and setup environment
library(testthat)
library(data.table)


test_that("hts_summary_num should return counts and units", {

results = hts_summary_num(
prepped_dt = test_data$trip,
summarize_var = 'speed_mph')

expect_is(results, "list", info = "hts_summary_num should return a list")

})
16 changes: 16 additions & 0 deletions tests/testthat/test-hts_to_so.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

context("Test suite for hts_to_so function")

# Load necessary libraries and setup environment
library(testthat)
library(data.table)
library(srvyr)


test_that("hts_to_so should return counts and units", {

results = hts_to_so(test_data$day)

expect_is(results, "survey.design", info = "hts_to_so should return a list")

})
37 changes: 37 additions & 0 deletions tests/testthat/test-hts_trip_vehid.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

context("Test suite for hts_trip_vehid function")

# Load necessary libraries and setup environment
library(testthat)
library(data.table)

# Sample trip_table and vehicle_table for testing
trip_ex = data.table(
hh_id = sample(1:10, size = 30, replace = TRUE),
trip_id = 1:30,
mode_type = sample(1:2, size = 30, replace = TRUE),
mode_1 = sample(1, size = 30, replace = TRUE))

vehicle_ex = data.table(
hh_id = sample(1:10, size = 30, replace = TRUE),
vehicle_id = 1:30)

values_ex = data.table(
variable = c(rep('mode_type', 2), ('mode_1')),
value = c(1,2,1),
value_label = c('Vehicle', 'Walk', 'Car')
)


test_that("hts_trip_vehid should create vehicle_id correctly", {

results = hts_trip_vehid(trip_table = trip_ex,
vehicle_table = vehicle_ex,
vehicle_mode_type = 'Vehicle',
values_dt = values_ex)

expect_is(results, "data.table", info = "hts_trip_vehid should return a data.table object")

expect_true("vehicle_id" %in% names(results), info = "Results should include 'vehicle_id' column")

})
2 changes: 1 addition & 1 deletion tests/testthat/test_factorize_column.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
context("factorize_column")
library(tmrtools)
library(travelSurveyTools)
library(data.table)

x = sample(5, replace=TRUE, size=10)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_factorize_df.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
context("factorize_df")
library(tmrtools)
library(travelSurveyTools)
library(data.table)


Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test_hts_melt_vars.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

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")


# expect_equal(2 * 2, 4)
})
16 changes: 16 additions & 0 deletions tests/testthat/test_hts_prep_byvar.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

context("Test suite for hts_prep_byvar function")

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)

expect_is(results, "data.table",
info = "hts_prep_byvar should return a data.table")

# expect_equal()
})

0 comments on commit 210f446

Please sign in to comment.