Path: blob/master/2020-spring/materials/worksheet_01/tests_worksheet_01.R
2051 views
library(testthat)1library(digest)23test_3.2 <- function(){4test_that('seconds_in_a_minute should exist and have the value of how many seconds are in a minute.', {5expect_equal(digest(seconds_in_a_minute), '4bdb128c943f718f5b8f347bb4b7641b') # we hid the answer to the test here so you can't see it, but we can still run the test6})7test_that('seconds_in_a_hour should exist and have the value of how many seconds are in a hour.', {8expect_equal(digest(seconds_in_an_hour), 'a69521e1dbffd4cd8f6ed869a4eba073') # we hid the answer to the test here so you can't see it, but we can still run the test9})10print("Success!")11}1213test_4.0 <- function(){14test_that('Solution is incorrect', {15expect_equal(digest(title), 'c76933115bc8095b2140c11556800725') # we hid the answer to the test here so you can't see it, but we can still run the test16})17print("Success!")18}1920test_4.1 <- function(){21test_that('Solution is incorrect', {22expect_equal(digest(smallest), 'db8e490a925a60e62212cefc7674ca02') # we hid the answer to the test here so you can't see it, but we can still run the test23})24print("Success!")25}2627test_5.1 <- function(){28test_that('Solution is incorrect, the rvest package needs to be loaded', {29expect_that("package:rvest" %in% search() , is_true())30})31print("Success!")32}3334test_6.1 <- function(){35test_that('Solution is incorrect', {36expect_equal(digest(answer6.1), '75f1160e72554f4270c809f041c7a776') # we hid the answer to the test here so you can't see it, but we can still run the test37})38print("Success!")39}4041test_7.0.1 <- function(){42test_that('Solution is incorrect', {43expect_equal(digest(answer7.0.1), '3a5505c06543876fe45598b5e5e5195d') # we hid the answer to the test here so you can't see it, but we can still run the test44})45print("Success!")46}4748test_7.0.2 <- function(){49test_that('Solution is incorrect', {50expect_equal(digest(answer7.0.2), '05ca18b596514af73f6880309a21b5dd') # we hid the answer to the test here so you can't see it, but we can still run the test51})52print("Success!")53}5455test_7.0.3 <- function(){56test_that('Solution is incorrect', {57expect_equal(digest(answer7.0.3), '475bf9280aab63a82af60791302736f6') # we hid the answer to the test here so you can't see it, but we can still run the test58})59print("Success!")60}6162test_7.1.1 <- function(){63test_that('Did not create an object named marathon_small', {64expect_true(exists("marathon_small"))65})66test_that('marathon_small should be a data frame', {67expect_true('data.frame' %in% class(marathon_small))68})69test_that('marathon_small does not contain the correct data', {70expect_equal(dim(marathon_small), c(1833, 5))71expect_equal(sum(marathon_small$age), 66455.5)72expect_equal(colnames(marathon_small), c("age", "bmi", "km5_time_seconds", "km10_time_seconds", "sex"))73})74print("Success!")75}7677test_7.1.2 <- function(){78test_that('Solution is incorrect', {79expect_equal(digest(answer7.1.2), '3a5505c06543876fe45598b5e5e5195d') # we hid the answer to the test here so you can't see it, but we can still run the test80})81print("Success!")82}8384test_7.2.1 <- function(){85test_that('Solution is incorrect.', {86expect_equal(digest(number_rows), '58fac55045cec17cd9f4006f4b5ab349') # we hid the answer to the test here so you can't see it, but we can still run the test87})88print("Success!")89}9091test_7.3.1 <- function(){92test_that('marathon_filtered has the incorrect number of rows', {93expect_equal(digest(nrow(marathon_filtered)), 'd9509be2b148230926a2df0f355c16b2') # we hid the answer to the test here so you can't see it, but we can still run the test94})95test_that('marathon_filtered has the incorrect number of column', {96expect_equal(digest(ncol(marathon_filtered)), 'dd4ad37ee474732a009111e3456e7ed7') # we hid the answer to the test here so you can't see it, but we can still run the test97})98test_that('marathon_filtered bmi column contains the incorrect values', {99expect_equal(colnames(marathon_filtered), c("age", "bmi", "km5_time_seconds", "km10_time_seconds", "sex"))100expect_equal(digest(as.numeric(sum(marathon_filtered$bmi))), '206ea048affbda5298ce20573b9cb321') # we hid the answer to the test here so you can't see it, but we can still run the test101})102print("Success!")103}104105test_7.4.1 <- function(){106test_that('marathon_male has the incorrect number of rows', {107expect_equal(digest(nrow(marathon_male)), 'd9509be2b148230926a2df0f355c16b2') # we hid the answer to the test here so you can't see it, but we can still run the test108})109test_that('marathon_male has the incorrect number of columns', {110expect_equal(digest(ncol(marathon_male)), 'c01f179e4b57ab8bd9de309e6d576c48') # we hid the answer to the test here so you can't see it, but we can still run the test111})112test_that('marathon_male bmi and/or km10_time_seconds column(s) contains the incorrect values', {113expect_equal(digest(sum(marathon_male$bmi)), '206ea048affbda5298ce20573b9cb321') # we hid the answer to the test here so you can't see it, but we can still run the test114expect_equal(digest(sum(as.numeric(marathon_male$km10_time_seconds))), '9c9393e1464352cd4fbea94dfadfa02a') # we hid the answer to the test here so you can't see it, but we can still run the test115})116print("Success!")117}118119test_7.4.2 <- function(){120test_that('Solution is incorrect', {121expect_match(digest(answer7.4.2), "a9cf135185e7fe4ae642c8dcb228cd2d")122})123print("Success!")124}125126test_7.4.3 <- function(){127test_that('Solution is incorrect', {128expect_match(digest(answer7.4.3), "edf7faf67d063030eba4ec85c6f7cc55")129})130print("Success!")131}132133test_7.5.1 <- function(){134test_that('marathon_minutes has the incorrect number of rows', {135expect_equal(digest(nrow(marathon_minutes)), 'd9509be2b148230926a2df0f355c16b2') # we hid the answer to the test here so you can't see it, but we can still run the test136})137test_that('marathon_minutes has the incorrect number of columns', {138expect_equal(digest(ncol(marathon_minutes)), '11946e7a3ed5e1776e81c0f0ecd383d0') # we hid the answer to the test here so you can't see it, but we can still run the test139})140test_that('km10_time_minutes column does not exist contains incorrect values', {141expect_equal(digest(sum(marathon_minutes$km10_time_minutes)), '9c9393e1464352cd4fbea94dfadfa02a') # we hid the answer to the test here so you can't see it, but we can still run the test142})143print("Success!")144}145146test_7.6.1 <- function(){147test_that('Solution is incorrect', {148expect_match(digest(answer7.6.1), '3a5505c06543876fe45598b5e5e5195d')149})150print("Success!")151}152153