From 36b2c80f217975ef4e227ca77b8551c2952b4d57 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Fri, 1 Nov 2024 11:15:10 -0300 Subject: [PATCH] test expected dataset --- tests/testthat/test-distance-to-leader.R | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/testthat/test-distance-to-leader.R b/tests/testthat/test-distance-to-leader.R index ec41dd45..f00c24fa 100644 --- a/tests/testthat/test-distance-to-leader.R +++ b/tests/testthat/test-distance-to-leader.R @@ -98,3 +98,34 @@ test_that('returns a data.table', { expect_s3_class(distance_to_leader(DT, coords = coords, group = group), 'data.table') }) + + +expect_DT <- data.table( + ID = c('A', 'B'), + X = c(0, 10), + Y = c(0, 0), + group_direction = rep(as_units(0, 'rad'), 2), + group = c(1, 1) +) +centroid_group(expect_DT, coords = coords) +leader_direction_group(expect_DT, coords = coords, + return_rank = TRUE, group = group) +distance_to_leader(expect_DT, coords = c('X', 'Y')) + +test_that('expected results for simple case', { + expect_lte( + expect_DT[, max(distance_leader)], + 10 + ) + + expect_gte( + expect_DT[, min(distance_leader)], + 0 + ) + expect_equal( + expect_DT[distance_leader == min(distance_leader), ID], + 'B' + ) +}) + +