Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Oct 17, 2024
1 parent d6a5eed commit 12957b6
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/testthat/test-fit.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
test_that("fit_power_law() works", {
# g <- sample_pa(100) # increase this number to have a better estimate
# d <- degree(g, mode = "in")
d <- c(
9, 3, 8, 1, 10, 4, 8, 0, 4, 4, 5, 2, 2, 7, 2, 0, 0, 0, 1, 0, 5, 0, 1, 2, 0, 0,
1, 3, 0, 1, 1, 0, 0, 0, 0, 2, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0,
0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0
)

expected <- list(
continuous = FALSE,
alpha = 1.9113310272735056,
xmin = 1,
logLik = -65.06453615610745,
KS.stat = 0.07720553650317852
)
fit <- fit_power_law(d)

expect_equal(fit, expected)

set.seed(20241017)
expected_p <- 0.2308
fit <- fit_power_law(d, p.value = TRUE)

expect_equal(fit[names(fit) != "KS.p"], expected)
expect_equal(fit$KS.p, expected_p)
})

0 comments on commit 12957b6

Please sign in to comment.