Skip to content

Commit

Permalink
Add lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
doccstat authored Sep 6, 2023
1 parent 53af91d commit fcb6136
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ inst/doc
vignettes/*.aux
.vscode/
docs
.lintr
3 changes: 3 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exclusions: list(
"R/RcppExports.R"
)
42 changes: 19 additions & 23 deletions tests/testthat/test-fastcpd.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ testthat::test_that("logistic regression", {
# sync if the documentation ever changes.
set.seed(1)

kChangePointLocation <- 125
kNumberOfDataPoints <- 300
kDimension <- 5
kChangePointLocation <- 125 # nolint: Google Style Guide
kNumberOfDataPoints <- 300 # nolint: Google Style Guide
kDimension <- 5 # nolint: Google Style Guide

# There are 300 five-dimensional data points.
x <- matrix(rnorm(kNumberOfDataPoints * kDimension, 0, 1), ncol = kDimension)
Expand Down Expand Up @@ -83,9 +83,9 @@ testthat::test_that("logistic regression", {
# sync if the documentation ever changes.
set.seed(1)

kChangePointLocation <- 125
kNumberOfDataPoints <- 300
kDimension <- 5
kChangePointLocation <- 125 # nolint: Google Style Guide
kNumberOfDataPoints <- 300 # nolint: Google Style Guide
kDimension <- 5 # nolint: Google Style Guide

# There are 300 five-dimensional data points.
x <- matrix(rnorm(kNumberOfDataPoints * kDimension, 0, 1), ncol = kDimension)
Expand Down Expand Up @@ -503,7 +503,7 @@ testthat::test_that("huber regression with 0.1 vanilla", {
testthat::test_that("confidence interval experiment", {
testthat::skip("This test is intended to be run manually.")
set.seed(1)
kDimension <- 1
kDimension <- 1 # nolint: Google Style Guide
change_point_locations <- NULL
for (experiment_id in seq_len(20)) {
data <- rbind(
Expand Down Expand Up @@ -546,7 +546,7 @@ testthat::test_that("confidence interval experiment", {
change_point_locations <- c(change_point_locations, mean_loss_result@cp_set)
}

change_point_locations_cookie_bucket <- NULL
change_locations_cookie_bucket <- NULL
cookie_bucket_id_list <- sample.int(n = 20, size = 1000, replace = TRUE)
all_data <- data
for (cookie_bucket_id in seq_len(20)) {
Expand Down Expand Up @@ -582,8 +582,8 @@ testthat::test_that("confidence interval experiment", {
ordinal_mapped_cp <- which(
cumsum(cookie_bucket_id_list != cookie_bucket_id) == cp
)[1]
change_point_locations_cookie_bucket <-
c(change_point_locations_cookie_bucket, ordinal_mapped_cp)
change_locations_cookie_bucket <-
c(change_locations_cookie_bucket, ordinal_mapped_cp)
}
}

Expand All @@ -595,25 +595,21 @@ testthat::test_that("confidence interval experiment", {
unname(table_change_point_locations), c(1, 1, 19, 20), ignore_attr = TRUE
)

table_change_point_locations_cookie_bucket <-
table(change_point_locations_cookie_bucket)
table_cp_cookie_bucket <- table(change_locations_cookie_bucket)
testthat::expect_equal(
rownames(table_change_point_locations_cookie_bucket),
c("299", "300", "697", "700")
rownames(table_cp_cookie_bucket), c("299", "300", "697", "700")
)
testthat::expect_equal(
unname(table_change_point_locations_cookie_bucket),
c(1, 19, 1, 19),
ignore_attr = TRUE
unname(table_cp_cookie_bucket), c(1, 19, 1, 19), ignore_attr = TRUE
)
})

testthat::test_that("confidence interval experiment with one change point", {
testthat::skip("This test is intended to be run manually.")
set.seed(1)
kDimension <- 1
kDimension <- 1 # nolint: Google Style Guide
change_point_locations <- list()
change_point_locations_cookie_bucket <- rep(list(NULL), 1000)
change_locations_cookie_bucket <- rep(list(NULL), 1000)
containing_change_point <- rep(FALSE, 1000)
for (experiment_id in seq_len(1000)) {
data <- rbind(
Expand Down Expand Up @@ -687,17 +683,17 @@ testthat::test_that("confidence interval experiment with one change point", {
for (cp in mean_loss_result@cp_set) {
ordinal_mapped_cp <-
which(cumsum(cookie_bucket_id_list != cookie_bucket_id) == cp)[1]
change_point_locations_cookie_bucket[[experiment_id]] <- c(
change_point_locations_cookie_bucket[[experiment_id]],
change_locations_cookie_bucket[[experiment_id]] <- c(
change_locations_cookie_bucket[[experiment_id]],
ordinal_mapped_cp
)
}
}
if (
quantile(
change_point_locations_cookie_bucket[[experiment_id]], 0.025
change_locations_cookie_bucket[[experiment_id]], 0.025
) <= 50 && quantile(
change_point_locations_cookie_bucket[[experiment_id]], 0.975
change_locations_cookie_bucket[[experiment_id]], 0.975
) >= 50
) {
containing_change_point[experiment_id] <- TRUE
Expand Down

0 comments on commit fcb6136

Please sign in to comment.