Skip to content

Commit

Permalink
tests for insert_treatments
Browse files Browse the repository at this point in the history
  • Loading branch information
epress12 committed Jan 8, 2021
1 parent 489a972 commit a9cc804
Showing 1 changed file with 93 additions and 44 deletions.
137 changes: 93 additions & 44 deletions tests/testthat/test-insert_treaments.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
## Import the motive and flydra example datasets
motive_data <-
read_motive_csv(system.file("extdata", "pathviewR_motive_example_data.csv",
package = 'pathviewR'))
## Import motive data
motive_data <- # import
read_motive_csv(
system.file("extdata", "pathviewR_motive_example_data.csv",
package = 'pathviewR')
)
## Clean motive data
motive_full <-
motive_data %>%
clean_viewr(desired_percent = 50,
max_frame_gap = "autodetect",
span = 0.95)
clean_viewr(
relabel_viewr_axes = TRUE,
gather_tunnel_data = TRUE,
trim_tunnel_outliers = TRUE,
standardization_option = "rotate_tunnel",
select_x_percent = TRUE,
desired_percent = 50,
rename_viewr_characters = FALSE,
separate_trajectories = TRUE,
max_frame_gap = "autodetect",
get_full_trajectories = TRUE,
span = 0.95
)

## Prep motive data
motive_treat <-
motive_full %>%
insert_treatments(tunnel_config = "v",
perch_2_vertex = 0.3855,
vertex_angle = 90,
tunnel_length = 2,
stim_param_lat_pos = 0.05,
stim_param_lat_neg = 0.05,
stim_param_end_pos = 0.1,
stim_param_end_neg = 0.1,
treatment = "latB")

## Import flydra data
flydra_data <-
read_flydra_mat(system.file("extdata", "pathviewR_flydra_example_data.mat",
read_flydra_mat(
system.file("extdata", "pathviewR_flydra_example_data.mat",
package = 'pathviewR'),
subject_name = "birdie_wooster")

## Clean flydra data
flydra_full <-
flydra_data %>%
clean_viewr(
Expand All @@ -25,53 +54,73 @@ flydra_full <-
height_zero = 1.44,
get_velocity = FALSE,
select_x_percent = TRUE,
desired_percent = 60,
rename_viewr_characters = FALSE,
separate_trajectories = TRUE,
get_full_trajectories = TRUE
)

## Prep flydra data
flydra_treat <-
flydra_full %>%
insert_treatments(tunnel_config = "box",
tunnel_width = 1,
tunnel_length = 3,
stim_param_lat_pos = 0.05,
stim_param_lat_neg = 0.05,
stim_param_end_pos = 0.1,
stim_param_end_neg = 0.1,
treatment = "latB")

test_that("insert_treatments() fails when nonsense is supplied", {
expect_error(insert_treatments("steve"))
expect_error(insert_treatments(c("a", "b", "c")))
expect_error(insert_treatments())
expect_error(insert_treatments(flydra_treat,
tunnel_config = "box",
tunnel_width = -1, # negative tunnel width
tunnel_length = 3,
stim_param_lat_pos = 0.05,
stim_param_lat_neg = 0.05,
stim_param_end_pos = 0.1,
stim_param_end_neg = 0.1,
treatment = "latB"))
expect_error(insert_treatments(flydra_treat,
tunnel_config = "box",
tunnel_width = 1,
tunnel_length = -3, # negative tunnel length
stim_param_lat_pos = 0.05,
stim_param_lat_neg = 0.05,
stim_param_end_pos = 0.1,
stim_param_end_neg = 0.1,
treatment = "latB"))
expect_error(insert_treatments(flydra_treat,
tunnel_config = "box",
tunnel_width = 1,
tunnel_length = 3,
stim_param_lat_pos = -0.05, # negative stim_param
stim_param_lat_neg = 0.05,
stim_param_end_pos = 0.1,
stim_param_end_neg = 0.1,
treatment = "latB"))

## Run insert_treatments() on each
motive_test <-
motive_full %>%
insert_treatments(vertex_height = 0.3855,
vertex_angle = 45,
stim_param_pos = 0.1,
stim_param_neg = 0.2,
treatment = "latB")
})

flydra_test <-
flydra_full %>%
insert_treatments(pos_wall = 0.5,
neg_wall = 0.5,
front_wall = 1.0,
stim_param_pos = 0.1,
stim_param_neg = 0.1,
stim_param_front = 0.2,
treatment = "latB")

## Test output objects
test_that("insert_treatments() adds variables appropriately", {
## Inserted variables at beginning of df
expect_equal(names(motive_test)[1:5],
c("vertex_height", "vertex_angle", "stim_param_pos",
"stim_param_neg", "treatment"))
expect_equal(names(flydra_test)[1:7],
c("pos_wall", "neg_wall", "front_wall", "stim_param_pos",
"stim_param_neg", "stim_param_front", "treatment"))
## output objects are of correct dimensions
expect_equal(dim(motive_test), c(449, 29))
expect_equal(dim(flydra_test), c(133, 22))
})

## Test error message for incorrect argument combination
test_that("incorrect argument combination triggers error message", {
expect_error(insert_treatments(motive_full,
vertex_height = 45,
pos_wall = 0.5)
expect_equal(names(motive_treat)[1:9],
c("tunnel_config", "perch_2_vertex", "vertex_angle",
"tunnel_length", "stim_param_lat_pos", "stim_param_lat_neg",
"stim_param_end_pos", "stim_param_end_neg", "treatment")
)
expect_equal(names(flydra_treat)[1:8],
c("tunnel_config", "tunnel_width", "tunnel_length",
"stim_param_lat_pos", "stim_param_lat_neg",
"stim_param_end_pos", "stim_param_end_neg", "treatment")
)
## output objects are of correct dimensions
expect_equal(dim(motive_treat), c(449, 33))
expect_equal(dim(flydra_treat), c(381, 23))
})



0 comments on commit a9cc804

Please sign in to comment.