Session | Date | Area | Level |
---|---|---|---|
Hacker Stats (AKA Resampling Methods) | 14:00-15:00 Wed 14th August 2024 | R | |
Flexdashboard | 13:00-14:30 Thu 15th August 2024 | R |
07/08/2024
Session | Date | Area | Level |
---|---|---|---|
Hacker Stats (AKA Resampling Methods) | 14:00-15:00 Wed 14th August 2024 | R | |
Flexdashboard | 13:00-14:30 Thu 15th August 2024 | R |
testthat
walkthroughWEBVTT
Q1::>
00:00:00.000 --> 00:00:14.080
<v Brendan Clarke> this was the first question in the transcript
00:00:14.080 --> 00:00:32.180
<v Someone Else> then someone replied with this answer
Q2::>
00:00:32.180 --> 00:00:48.010
<v Brendan Clarke> then there was another question
00:00:48.010 --> 00:00:58.010
<v Someone Else> and another tedious response
file <- "data/input.txt"
readLines(file) |>
as_tibble() |>
filter(!value == "") |>
filter(!value == "WEBVTT") |>
mutate(question = str_extract(value, "^(Q.*?)::>$")) |>
fill(question, .direction = 'down') |>
filter(!str_detect(value, "^(Q.*?)::>$")) |>
mutate(ind = rep(c(1, 2),length.out = n())) |>
group_by(ind) |>
mutate(id = row_number()) |>
spread(ind, value) |>
select(-id) |>
separate("1", c("start_time", "end_time"), " --> ") |>
separate("2", c("name", "comment"), ">") |>
mutate(source = str_remove_all(file, "\\.txt"),
name = str_remove_all(name, "\\<v "),
comment = str_trim(comment),
question = str_remove_all(question, "::>")) |>
knitr::kable()
question | start_time | end_time | name | comment | source |
---|---|---|---|---|---|
Q1 | 00:00:00.000 | 00:00:14.080 | Brendan Clarke | this was the first question in the transcript | data/input |
Q1 | 00:00:14.080 | 00:00:32.180 | Someone Else | then someone replied with this answer | data/input |
Q2 | 00:00:32.180 | 00:00:48.010 | Brendan Clarke | then there was another question | data/input |
Q2 | 00:00:48.010 | 00:00:58.010 | Someone Else | and another tedious response | data/input |
testthat
:testthat
testthat
testthat
works best when you’re testing functionsor include the body inline for simple functions:
multo(2,2)
should equal 4, so we use:
test_that()
to set up our test environmentexpect_equal()
inside the test environment to check for equalityy <- x
test_that("check my vec sets", {
expect_success(expect_setequal(x, y)) # all x in y
expect_failure(expect_mapequal(x, y)) # same names, y is proper subset x) # all x in y)
show_failure(expect_contains(x[1:19], y)) # y proper subset x)
expect_success(expect_in(x, y)) # x proper subset y
})
Failed expectation:
x[1:19] (`actual`) doesn't fully contain all the values in `y` (`expected`).
* Missing from `actual`: "Stockholm", "Vienna"
* Present in `actual`: "Athens", "Barcelona", "Brussels", "Calais", "Cherbourg", "Cologne", "Copenhagen", "Geneva", "Gibraltar", ...
Test passed 😀
y <- sample(x, length(x)-2)
test_that("check my vec sets", {
expect_failure(expect_setequal(x, y)) # all x in y
expect_failure(expect_mapequal(x, y)) # same names, y is proper subset x) # all x in y)
expect_success(expect_contains(x, y)) # y proper subset x)
expect_failure(expect_in(x, y)) # x is a proper subset y
})
Test passed 🎊
waldo
, you shouldn’t have to do anything fancy to test on tibbles:[1] "list"
[1] "tbl_df" "tbl" "data.frame"
[1] FALSE
NULL
[1] TRUE
[1] "tbl_df" "tbl" "data.frame"
test_that("penguin types", {
expect_type(penguins, "list")
expect_s3_class(penguins, "tbl_df")
expect_s3_class(penguins, "tbl")
expect_s3_class(penguins, "data.frame")
expect_type(penguins$island, "integer")
expect_s3_class(penguins$island, "factor")
})
Test passed 😸
expect_s4_class
for those with that high clear mercury sound ringing in their earsSession | Date | Area | Level |
---|---|---|---|
Hacker Stats (AKA Resampling Methods) | 14:00-15:00 Wed 14th August 2024 | R | |
Flexdashboard | 13:00-14:30 Thu 15th August 2024 | R |