@@ -248,3 +248,37 @@ test_that("pareto_smooth works for log_weights", {
248248 expect_true(ps $ diagnostics $ khat > 0.7 )
249249
250250})
251+
252+ test_that(" check ps_tail behavior for ndraws_tail less than 5" , {
253+ w <- c(1 : 25 , 1e3 , 1e3 , 1e3 )
254+ lw <- log(w )
255+
256+ # prints correct warning
257+ expect_warning(
258+ tail <- ps_tail(lw , ndraws_tail = 4 , tail = " right" ),
259+ " Can't fit generalized Pareto distribution because ndraws_tail is less than 5."
260+ )
261+ # output has expected shape and k = NA
262+ expect_equal(names(tail ), c(" x" , " k" ))
263+ expect_true(is.na(tail $ k ))
264+ })
265+
266+ test_that(" check ps_tail behavior for constant draws_tail" , {
267+ x <- log(replicate(10 , 0.3 ))
268+
269+ tail <- ps_tail(x , ndraws_tail = 10 , tail = " left" )
270+
271+ # output has expected return values
272+ expect_equal(x , tail $ x )
273+ expect_true(is.na(tail $ k ))
274+ })
275+
276+
277+ test_that(" check ps_min_ss behavior special cases" , {
278+ # k = NA
279+ expect_true(is.na(ps_min_ss(NA )))
280+ # k > 1
281+ expect_true(is.infinite(ps_min_ss(2 )))
282+ # k < 1
283+ expect_equal(ps_min_ss(0.5 ), 10 ^ (1 / (1 - max(0 , 0.5 ))))
284+ })
0 commit comments