Skip to content

Commit b44d595

Browse files
committed
Add some more function tests
Just to get over 90%
1 parent a05f0bc commit b44d595

File tree

9 files changed

+58
-10
lines changed

9 files changed

+58
-10
lines changed

R/combine.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@ combine_history <- function(fun, ...) {
1515
if (!("leagueHistory" %in% names(formals(fun)))) {
1616
stop("leagueHistory is not an argument of this function")
1717
}
18-
old <- bind_df(fun(..., leagueHistory = TRUE), .id = NULL)
18+
old <- fun(..., leagueHistory = TRUE)
19+
if (inherits(old, "data.frame")) {
20+
message("Historical data is already a data.frame")
21+
return(old)
22+
} else {
23+
old <- bind_df(old, .id = NULL)
24+
}
1925
new <- fun(..., leagueHistory = FALSE)
2026
n_old <- ncol(old)
2127
n_new <- ncol(new)
2228
if (n_new > n_old) {
2329
old <- balance_col(old, new)
30+
new <- balance_col(new, old)
2431
} else if (n_old > n_new) {
2532
new <- balance_col(new, old)
2633
}

R/members.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ league_members <- function(leagueId = ffl_id(), leagueHistory = FALSE, ...) {
1515
...
1616
)
1717
if (leagueHistory && is.list(dat$teams)) {
18-
names(dat$teams) <- dat$seasonId
18+
names(dat$members) <- dat$seasonId
1919
lapply(dat$members, out_member)
2020
} else {
2121
out_member(dat$members)

R/utils.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ change_names <- function(dat, old_name, new_name) {
6363
return(dat)
6464
}
6565

66-
replace_col <- function(z, old_name, ...) {
67-
dots <- list(...)
68-
stopifnot(length(dots) == 1, old_name %in% names(z))
69-
z[[old_name]] <- dots[[1]]
70-
z <- change_names(z, old_name, names(dots)[[1]])
71-
return(z)
72-
}
66+
# replace_col <- function(z, old_name, ...) {
67+
# dots <- list(...)
68+
# stopifnot(length(dots) == 1, old_name %in% names(z))
69+
# z[[old_name]] <- dots[[1]]
70+
# z <- change_names(z, old_name, names(dots)[[1]])
71+
# return(z)
72+
# }
7373

7474
col_abbrev <- function(z, col, new) {
7575
new_name <- gsub("Id$", "", col)

tests/testthat/test-history.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@ test_that("historical data can be returned", {
77
expect_length(h, 1)
88
expect_s3_class(h[[1]], "data.frame")
99
})
10+
11+
test_that("historical data can be combined", {
12+
h <- combine_history(
13+
fun = league_simulation,
14+
leagueId = "42654852"
15+
)
16+
expect_s3_class(h, "data.frame")
17+
expect_length(h, 12)
18+
})

tests/testthat/test-members.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@ test_that("league members", {
33
expect_s3_class(m, "data.frame")
44
expect_length(m, 3)
55
})
6+
7+
test_that("league members history with names", {
8+
m <- league_members(leagueId = "42654852", leagueHistory = TRUE)
9+
expect_type(m, "list")
10+
expect_named(m)
11+
expect_s3_class(m[[1]], "data.frame")
12+
expect_length(m[[1]], 3)
13+
})

tests/testthat/test-outlook.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
test_that("get individual player outlook", {
22
o <- player_outlook(
3-
leagueId = "42654852",
3+
leagueId = NULL,
44
limit = 1
55
)
66
expect_s3_class(o, "data.frame")

tests/testthat/test-scores.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@ test_that("scores by scoring period", {
1515
)
1616
expect_equal(length(unique(s$scoringPeriodId)), nrow(s)/4)
1717
})
18+
19+
test_that("scores by past league history", {
20+
s <- tidy_scores(
21+
leagueId = "42654852",
22+
leagueHistory = TRUE,
23+
useMatchup = TRUE
24+
)
25+
expect_type(s, "list")
26+
expect_length(unique(s[[1]]$matchupPeriodId), 17)
27+
})

tests/testthat/test-settings.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ test_that("roster settings for a single season", {
6767
expect_s3_class(r$lineupSlotCounts[[1]], "data.frame")
6868
})
6969

70+
test_that("roster settings for a past seasons", {
71+
r <- roster_settings("42654852", leagueHistory = TRUE)
72+
expect_s3_class(r, "data.frame")
73+
expect_length(r, 8)
74+
expect_s3_class(r$lineupSlotCounts[[1]], "data.frame")
75+
})
76+
7077
# schedule settings -------------------------------------------------------
7178
Sys.sleep(runif(1, 1, 2))
7279

tests/testthat/test-simulation.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
test_that("get simulated season projections", {
2+
s <- league_simulation(
3+
leagueId = "42654852"
4+
)
5+
expect_s3_class(s, "data.frame")
6+
expect_length(s, 11)
7+
})

0 commit comments

Comments
 (0)