Skip to content

Commit a912b7d

Browse files
committed
Test standings and abbreviations
1 parent 1ecad1b commit a912b7d

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

tests/testthat/test-abbrev.R

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
tm <- league_teams("42654852")
2+
3+
test_that("team abbreviation", {
4+
x <- team_abbrev(1, tm)
5+
expect_length(x, 1)
6+
expect_s3_class(x, "factor")
7+
expect_equal(as.character(x), "AUS")
8+
})
9+
10+
test_that("team un-abbreviation", {
11+
x <- team_unabbrev("AUS", tm)
12+
expect_length(x, 1)
13+
expect_type(x, "integer")
14+
expect_equal(x, 1)
15+
})
16+
17+
test_that("team abbreviation errors", {
18+
expect_error(team_abbrev(1, mtcars))
19+
})
20+
21+
# -------------------------------------------------------------------------
22+
23+
test_that("slot abbreviation", {
24+
x <- slot_abbrev(0)
25+
expect_length(x, 1)
26+
expect_s3_class(x, "factor")
27+
expect_equal(as.character(x), "QB")
28+
})
29+
30+
test_that("slot un-abbreviation", {
31+
x <- slot_unabbrev("QB")
32+
expect_length(x, 1)
33+
expect_type(x, "integer")
34+
expect_equal(x, 0)
35+
})
36+
37+
test_that("slot abbreviation errors", {
38+
expect_error(slot_abbrev("test"))
39+
})
40+
41+
# -------------------------------------------------------------------------
42+
43+
test_that("position abbreviation", {
44+
x <- pos_abbrev(1)
45+
expect_length(x, 1)
46+
expect_s3_class(x, "factor")
47+
expect_equal(as.character(x), "QB")
48+
})
49+
50+
test_that("position un-abbreviation", {
51+
x <- pos_unabbrev("QB")
52+
expect_length(x, 1)
53+
expect_type(x, "integer")
54+
expect_equal(x, 1)
55+
})
56+
57+
# -------------------------------------------------------------------------
58+
59+
test_that("position abbreviation", {
60+
x <- pro_abbrev(1)
61+
expect_length(x, 1)
62+
expect_s3_class(x, "factor")
63+
expect_equal(as.character(x), "Atl")
64+
})
65+
66+
test_that("position un-abbreviation", {
67+
x <- pro_unabbrev("Atl")
68+
expect_length(x, 1)
69+
expect_type(x, "integer")
70+
expect_equal(x, 1)
71+
})
72+
73+
# -------------------------------------------------------------------------
74+
75+
test_that("position abbreviation", {
76+
x <- stat_abbrev(1)
77+
expect_length(x, 1)
78+
expect_equal(x, "PC")
79+
})
80+
81+
test_that("position un-abbreviation", {
82+
x <- stat_unabbrev("PC")
83+
expect_length(x, 1)
84+
expect_type(x, "integer")
85+
expect_equal(x, 1)
86+
})

tests/testthat/test-standings.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
test_that("standings returns data frame", {
2+
s <- league_standings("42654852")
3+
expect_s3_class(s, "data.frame")
4+
expect_length(s, 17)
5+
})
6+
7+
test_that("combine all historical standings", {
8+
s <- combine_history(league_standings, "252353")
9+
expect_s3_class(s, "data.frame")
10+
expect_gt(nrow(s), 10)
11+
expect_gt(length(unique(s$seasonId)), 1)
12+
})
13+
14+
test_that("simulations returns data frame", {
15+
s <- league_simulation("42654852")
16+
expect_s3_class(s, "data.frame")
17+
expect_length(s, 11)
18+
expect_true("playoffPct" %in% names(s))
19+
})

0 commit comments

Comments
 (0)