Skip to content

Commit

Permalink
calc_min_dist function tests
Browse files Browse the repository at this point in the history
  • Loading branch information
epress12 committed Jan 8, 2021
1 parent ba8d813 commit 93808ea
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 0 deletions.
80 changes: 80 additions & 0 deletions tests/testthat/test-calc_min_dist_box.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
## Import flydra data
flydra_data <-
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(
relabel_viewr_axes = FALSE,
gather_tunnel_data = FALSE,
trim_tunnel_outliers = FALSE,
standardization_option = "redefine_tunnel_center",
length_method = "middle",
height_method = "user-defined",
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_test <-
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")

flydra_min_dist <-
flydra_test %>%
calc_min_dist_box()

test_that("calc_min_dist_box() fails when nonsense is supplied", {
expect_error(calc_min_dist_box("steve"))
expect_error(calc_min_dist_box(c("a", "b", "c")))
expect_error(calc_min_dist_box())
expect_error(calc_min_dist_box(flydra_full)) ## no insert treatments
expect_error(calc_min_dist_box(data.frame(rnorm(100))))
})


## Test output data frame
test_that("calc_min_dist_box() adds variables appropriately",{
# output has correct variable names
expect_equal(names(flydra_min_dist)[24:26],
c("min_dist_pos", "min_dist_neg", "min_dist_end")
)
# output has correct dimensions
expect_equal(dim(flydra_min_dist), c(381, 26)
)
})


# Test calculations
test_that(
"get_vis_angle() makes correct calculations based on position_width", {
# correct visual angles result
expect_equal(flydra_min_dist$min_dist_pos[1:5],
c(0.4936291, 0.4981546, 0.5014801, 0.5048294, 0.5087834),
tolerance = 1e-5
)
expect_equal(flydra_min_dist$min_dist_neg[1:5],
c(0.5063709, 0.5018454, 0.4985199, 0.4951706, 0.4912166),
tolerance = 1e-5
)
expect_equal(flydra_min_dist$min_dist_end[1:5],
c(2.420628, 2.402764, 2.384981, 2.367326, 2.349635),
tolerance = 1e-5
)
})
81 changes: 81 additions & 0 deletions tests/testthat/test-calc_min_dist_v.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
## 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(
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_test <-
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")

motive_min_dist <-
motive_test %>%
calc_min_dist_v(simplify_output = FALSE)

test_that("calc_min_dist_v() fails when nonsense is supplied", {
expect_error(calc_min_dist_v("steve"))
expect_error(calc_min_dist_v(c("a", "b", "c")))
expect_error(calc_min_dist_v())
expect_error(calc_min_dist_v(motive_full)) ## no insert treatments
expect_error(calc_min_dist_v(data.frame(rnorm(100))))
})


## Test output data frame
test_that("calc_min_dist_v() adds variables appropriately",{
# output has correct variable names
expect_equal(names(motive_min_dist)[34:42],
c("vertical_2_vertex", "vertical_2_screen",
"horizontal_2_screen_pos", "horizontal_2_screen_neg",
"min_dist_pos", "min_dist_neg", "bound_pos", "bound_neg",
"min_dist_end")
)
# output has correct dimensions
expect_equal(dim(motive_min_dist), c(449,42)
)
})


# Test calculations
test_that(
"calc_min_dist_v() makes correct calculations based on position_width", {
# correct visual angles result
expect_equal(motive_min_dist$min_dist_pos[223:227],
c(0.4474490, 0.1525866, 0.1505689, 0.1497356, 0.1481083),
tolerance = 1e-5
)
expect_equal(motive_min_dist$min_dist_neg[223:227],
c(0.1897518, 0.3329440, 0.3330949, 0.3336412, 0.3331090),
tolerance = 1e-5
)
expect_equal(motive_min_dist$min_dist_end[223:227],
c(0.3445865, 1.6564893, 1.6305929, 1.6034372, 1.5770317),
tolerance = 1e-5
)
})

0 comments on commit 93808ea

Please sign in to comment.