@@ -43,3 +43,49 @@ test_that("benchmark uses reference density attributes when they are not supplie
4343 expect_equal(dim(out ), c(2 , 1 ))
4444 expect_true(all(is.finite(out [, 1 ])))
4545})
46+
47+ test_that(" benchmark interpolates reference_density objects" , {
48+ skip_if_not_installed(" terra" )
49+
50+ samples <- matrix (
51+ c(
52+ 0 , 0 , 0.2 , 0.3 , 0.2 , 0.3 ,
53+ 1 , 1 , 0.4 , 0.5 , 0.4 , 0.5 ,
54+ 2 , 2 , 0.6 , 0.7 , 0.6 , 0.7 ,
55+ 3 , 3 , 0.8 , 0.9 , 0.8 , 0.9
56+ ),
57+ ncol = 6 ,
58+ byrow = TRUE
59+ )
60+
61+ ref <- ref_density(
62+ data = samples ,
63+ radius_km = 1000 ,
64+ bin_width = 0.1 ,
65+ bin_num = 10 ,
66+ num_threads = 1L
67+ )
68+ ref_norm <- normalise(
69+ x = ref ,
70+ trim_size = 6 ,
71+ offset = 1
72+ )
73+
74+ expect_no_error(
75+ out <- benchmark(
76+ data = samples [1 : 2 , , drop = FALSE ],
77+ samples = samples ,
78+ ref_density = ref_norm ,
79+ radius_km = 1000 ,
80+ k_pred = 2 ,
81+ k_obs = 1 ,
82+ bin_width = NULL ,
83+ offset = NULL ,
84+ interpolate = TRUE ,
85+ num_threads = 1L
86+ )
87+ )
88+
89+ expect_equal(dim(out ), c(2 , 1 ))
90+ expect_true(all(is.finite(out [, 1 ])))
91+ })
0 commit comments