Path: blob/master/2020-spring/materials/worksheet_04/tests_worksheet_04.R
2715 views
library(testthat)1library(digest)23test_0.1 <- function(){4test_that('Solution is incorrect', {5expect_equal(digest(answer0.1_A), '05ca18b596514af73f6880309a21b5dd')6expect_equal(digest(answer0.1_B), 'd2a90307aac5ae8d0ef58e2fe730d38b')7expect_equal(digest(answer0.1_C), '05ca18b596514af73f6880309a21b5dd')8expect_equal(digest(answer0.1_D), '05ca18b596514af73f6880309a21b5dd')9expect_equal(digest(answer0.1_E), 'd2a90307aac5ae8d0ef58e2fe730d38b')# we hid the answer to the test here so you can't see it, but we can still run the test10})11print("Success!")12}1314test_0.2 <- function(){15test_that('Solution is incorrect', {16expect_equal(digest(answer0.2), '75f1160e72554f4270c809f041c7a776') # we hid the answer to the test here so you can't see it, but we can still run the test17})18print("Success!")19}2021test_0.3 <- function(){22test_that('Solution is incorrect', {23expect_equal(digest(answer0.3), 'c1f86f7430df7ddb256980ea6a3b57a4') # we hid the answer to the test here so you can't see it, but we can still run the test24})25print("Success!")26}2728test_0.4 <- function(){29test_that('Solution is incorrect', {30expect_equal(digest(answer0.4), 'c1f86f7430df7ddb256980ea6a3b57a4') # we hid the answer to the test here so you can't see it, but we can still run the test31})32print("Success!")33}3435test_0.5 <- function(){36test_that('Solution is incorrect', {37expect_equal(digest(answer0.5_1), '75f1160e72554f4270c809f041c7a776')38expect_equal(digest(answer0.5_2), '01a75cb73d67b0f895ff0e61449c7bf8')39expect_equal(digest(answer0.5_3), '3a5505c06543876fe45598b5e5e5195d')40expect_equal(digest(answer0.5_4), 'f76b651ab8fcb8d470f79550bf2af53a')41expect_equal(digest(answer0.5_5), 'c1f86f7430df7ddb256980ea6a3b57a4')42expect_equal(digest(answer0.5_6), '475bf9280aab63a82af60791302736f6')# we hid the answer to the test here so you can't see it, but we can still run the test43})44print("Success!")45}4647test_1.0 <- function(){48test_that('Solution is incorrect', {49expect_equal(digest(answer1.0), '75f1160e72554f4270c809f041c7a776') # we hid the answer to the test here so you can't see it, but we can still run the test50})51print("Success!")52}5354test_1.1 <- function(){55test_that('Did not create an object named world_vaccination', {56expect_true(exists("world_vaccination"))57})58test_that('world_vaccination should be a data frame.', {59expect_true('data.frame' %in% class(world_vaccination))60})61test_that('Did not remove NA values from the pct_vaccinated column.', {62expect_equal(any(is.na(world_vaccination$pct_vaccinated)), FALSE)63})64test_that('world_vaccination does not contain the correct number of rows and/or columns.', {65expect_equal(dim(world_vaccination), c(385, 4))66})67test_that('Columns in world_vaccination contain incorrect values.', {68expect_equal(digest(as.numeric(sum(world_vaccination$yr))), 'ed828cd9c4dbc736fb12a1a8643aaeec')69})70print("Success!")71}7273test_1.2 <- function(){74test_that('Did not create a plot named world_vacc_plot', {75expect_true(exists("world_vacc_plot"))76})77test_that('year should be on the x-axis.', {78expect_that("yr" %in% c(rlang::get_expr(world_vacc_plot$mapping$x),rlang::get_expr(world_vacc_plot$layers[[1]]$mapping$x)), is_true())79})80test_that('pct_vaccinated should be on the y-axis.', {81expect_that("pct_vaccinated" %in% c(rlang::get_expr(world_vacc_plot$mapping$y), rlang::get_expr(world_vacc_plot$layers[[1]]$mapping$y)) , is_true())82})83test_that('world_vacc_plot should be a scatter plot.', {84expect_that("GeomPoint" %in% c(class(world_vacc_plot$layers[[1]]$geom)) , is_true())85})86test_that('Labels on the axes should be descriptive and human readable.', {87expect_that((world_vacc_plot$labels$y) == 'pct_vaccinated', is_false())88expect_that((world_vacc_plot$labels$x) == 'yr', is_false())89})90print("Success!")91}9293test_1.3 <- function(){94test_that('Solution is incorrect', {95expect_equal(digest(answer1.3), 'c1f86f7430df7ddb256980ea6a3b57a4') # we hid the answer to the test here so you can't see it, but we can still run the test96})97print("Success!")98}99100test_1.4 <- function(){101properties <- c(compare_vacc_plot$layers[[1]]$mapping, compare_vacc_plot$mapping)102labels <- compare_vacc_plot$labels103test_that('Did not create a plot named compare_vacc_plot', {104expect_true(exists("compare_vacc_plot"))105})106test_that('year should be on the x-axis.', {107expect_true("yr" == rlang::get_expr(properties$x))108})109test_that('pct_vaccinated should be on the y-axis.', {110expect_true("pct_vaccinated" == rlang::get_expr(properties$y))111})112test_that('vaccine should map to colour and shape.', {113expect_true("vaccine" == rlang::get_expr(properties$colour))114})115test_that('vaccine should map to shape and colour.', {116expect_true("vaccine" == rlang::get_expr(properties$shape))117})118test_that('vaccine should map to shape and colour.', {119expect_that("character" %in% class(compare_vacc_plot$layers[[1]]$mapping$shape), is_false())120})121test_that('vaccine should map to shape and colour.', {122expect_that("character" %in% class(compare_vacc_plot$layers[[1]]$mapping$colour), is_false())123})124test_that('compare_vacc_plot should be a scatter plot.', {125expect_that("GeomPoint" %in% c(class(compare_vacc_plot$layers[[1]]$geom)) , is_true())126})127test_that('Labels on the axes and legend need to be changed to be descriptive, nicely formatted, and human readable.', {128expect_that((labels$y) == 'pct_vaccinated', is_false())129expect_that((labels$x) == 'yr', is_false())130expect_that((labels$colour) == 'vaccine', is_false())131expect_that((labels$shape) == 'vaccine', is_false())132})133print("Success!")134}135136test_1.5 <- function(){137test_that('Did not create an object named polio', {138expect_true(exists("polio"))139})140test_that('The vaccine column in polio should only contain the polio vaccine.', {141expect_equal(unique(polio$vaccine), "polio")142})143test_that('polio does not contain the correct number of rows and/or columns.', {144expect_equal(dim(polio), c(228, 4))145})146test_that('Columns in polio contain incorrect values.', {147expect_equal(digest(as.numeric(sum(polio$pct_vaccinated))), 'cfd7ed9e50ed446d50289ff89ef338a4') # we hid the answer to the test here so you can't see it, but we can still run the test148})149print("Success!")150}151152test_1.6 <- function(){153properties <- c(polio_regions$layers[[1]]$mapping, polio_regions$mapping)154labels <- polio_regions$labels155test_that('Did not create a plot named polio_regions', {156expect_true(exists("polio_regions"))157})158test_that('year should be on the x-axis.', {159expect_true("yr" == rlang::get_expr(properties$x))160})161test_that('pct_vaccinated should be on the y-axis.', {162expect_true("pct_vaccinated" == rlang::get_expr(properties$y))163})164test_that('who_region should map to colour and shape.', {165expect_true("who_region" == rlang::get_expr(properties$colour))166})167test_that('who_region should map to shape and colour.', {168expect_true("who_region" == rlang::get_expr(properties$shape))169})170test_that('polio_regions should be a scatter plot.', {171expect_that("GeomPoint" %in% c(class(polio_regions$layers[[1]]$geom)) , is_true())172})173test_that('Labels on the axes and legend should be descriptive and human readable.', {174expect_that((labels$y) == 'pct_vaccinated', is_false())175expect_that((labels$x) == 'yr', is_false())176})177print("Success!")178}179180181test_1.7.1 <- function(){182183properties <- c(polio_regions_line$layers[[1]]$mapping, polio_regions_line$mapping)184labels <- polio_regions_line$labels185186test_that('Did not create a plot named polio_regions_line', {187expect_true(exists("polio_regions_line"))188})189test_that('year should be on the x-axis.', {190expect_true("yr" == rlang::get_expr(properties$x))191})192test_that('pct_vaccinated should be on the y-axis.', {193expect_true("pct_vaccinated" == rlang::get_expr(properties$y))194})195test_that('who_region should map to colour.', {196expect_true("who_region" == rlang::get_expr(properties$colour))197})198199if (length(polio_regions_line$layers) == 2) {200test_that('who_region should map to colour.', {201expect_that("who_region" == rlang::get_expr(c(polio_regions_line$layers[[1]]$mapping)$colour) &202"who_region" == rlang::get_expr(c(polio_regions_line$layers[[2]]$mapping)$colour) |203"who_region" == rlang::get_expr(c(polio_regions_line$layers[[2]]$mapping)$colour) &204"who_region" == rlang::get_expr(c(polio_regions_line$layers[[1]]$mapping)$colour), is_true())205} )} else {206test_that('who_region should map to colour.', {207expect_true("who_region" == rlang::get_expr(properties$colour))208})209}210211if (length(polio_regions_line$layers) == 2) { # if there are 2 layers then check if the two layers are points and lines212test_that('polio_regions_line should be a line plot.', {213expect_that("GeomPoint" %in% c(class(polio_regions_line$layers[[1]]$geom)) &214"GeomLine" %in% c(class(polio_regions_line$layers[[2]]$geom)) |215"GeomPoint" %in% c(class(polio_regions_line$layers[[2]]$geom)) &216"GeomLine" %in% c(class(polio_regions_line$layers[[1]]$geom)), is_true())217} )} else {218test_that('polio_regions_line should be a line plot.', {219expect_that("GeomLine" %in% c(class(polio_regions_line$layers[[1]]$geom)) , is_true())220})221}222test_that('Labels on the axes should be descriptive and human readable.', {223expect_that((labels$y) == 'pct_vaccinated', is_false())224expect_that((labels$x) == 'yr', is_false())225})226print("Success!")227}228229230test_1.7.2 <- function(){231properties <- c(polio_regions_line$layers[[1]]$mapping, polio_regions_line$mapping)232labels <- polio_regions_line$labels233test_that('Did not create a plot named polio_regions_line', {234expect_true(exists("polio_regions_line"))235})236test_that('year should be on the x-axis.', {237expect_true("yr" == rlang::get_expr(properties$x))238})239test_that('pct_vaccinated should be on the y-axis.', {240expect_true("pct_vaccinated" == rlang::get_expr(properties$y))241})242test_that('who_region should map to colour.', {243expect_true("who_region" == rlang::get_expr(properties$colour))244})245246if (length(polio_regions_line$layers) == 2) {247test_that('who_region should map to colour.', {248expect_that("who_region" == rlang::get_expr(c(polio_regions_line$layers[[1]]$mapping)$colour) &249"who_region" == rlang::get_expr(c(polio_regions_line$layers[[2]]$mapping)$colour) |250"who_region" == rlang::get_expr(c(polio_regions_line$layers[[2]]$mapping)$colour) &251"who_region" == rlang::get_expr(c(polio_regions_line$layers[[1]]$mapping)$colour), is_true())252} )} else {253test_that('who_region should map to colour.', {254expect_true("who_region" == rlang::get_expr(properties$colour))255})256}257258if (length(polio_regions_line$layers) == 2) { # if there are 2 layers then check if the two layers are points and lines259test_that('polio_regions_line should be a line plot.', {260expect_that("GeomPoint" %in% c(class(polio_regions_line$layers[[1]]$geom)) &261"GeomLine" %in% c(class(polio_regions_line$layers[[2]]$geom)) |262"GeomPoint" %in% c(class(polio_regions_line$layers[[2]]$geom)) &263"GeomLine" %in% c(class(polio_regions_line$layers[[1]]$geom)), is_true())264} )} else {265test_that('polio_regions_line should be a line plot.', {266expect_that("GeomLine" %in% c(class(polio_regions_line$layers[[1]]$geom)) , is_true())267})268}269test_that('Labels on the axes and legend should be descriptive and human readable.', {270expect_that((labels$y) == 'pct_vaccinated', is_false())271expect_that((labels$x) == 'yr', is_false())272expect_that((labels$colour) == 'who_region', is_false())273})274print("Success!")275}276277278test_1.8 <- function(){279properties <- c(side_by_side_world$layers[[1]]$mapping, side_by_side_world$mapping)280labels <- side_by_side_world$labels281test_that('Did not create a plot named side_by_side_world', {282expect_true(exists("side_by_side_world"))283})284test_that('year should be on the x-axis.', {285expect_true("yr" == rlang::get_expr(properties$x))286})287test_that('pct_vaccinated should be on the y-axis.', {288expect_true("pct_vaccinated" == rlang::get_expr(properties$y))289})290test_that('side_by_side_world should be faceted by the vaccine column.', {291expect_that('FacetGrid' %in% class(rlang::get_expr(side_by_side_world$facet)), is_true())292})293test_that("side_by_side_world should be split horizontally", {294expect_that("vaccine" %in% names(rlang::get_expr(side_by_side_world$facet$params$cols)), is_true())295})296if (length(side_by_side_world$layers) == 2) {297test_that('who_region should map to colour.', {298expect_that("who_region" == rlang::get_expr(c(side_by_side_world$layers[[1]]$mapping)$colour) &299"who_region" == rlang::get_expr(c(side_by_side_world$layers[[2]]$mapping)$colour) |300"who_region" == rlang::get_expr(c(side_by_side_world$layers[[2]]$mapping)$colour) &301"who_region" == rlang::get_expr(c(side_by_side_world$layers[[1]]$mapping)$colour), is_true())302} )} else {303test_that('who_region should map to colour.', {304expect_true("who_region" == rlang::get_expr(properties$colour))305})306}307308if (length(side_by_side_world$layers) == 2) { # if there are 2 layers then check if the two layers are points and lines309test_that('side_by_side_world should be a line plot.', {310expect_that("GeomPoint" %in% c(class(side_by_side_world$layers[[1]]$geom)) &311"GeomLine" %in% c(class(side_by_side_world$layers[[2]]$geom)) |312"GeomPoint" %in% c(class(side_by_side_world$layers[[2]]$geom)) &313"GeomLine" %in% c(class(side_by_side_world$layers[[1]]$geom)), is_true())314} )} else {315test_that('side_by_side_world should be a line plot.', {316expect_that("GeomLine" %in% c(class(side_by_side_world$layers[[1]]$geom)) , is_true())317})318}319test_that('Labels on the axes and legend should be descriptive and human readable.', {320expect_that((labels$y) == 'pct_vaccinated', is_false())321expect_that((labels$x) == 'yr', is_false())322expect_that((labels$colour) == 'who_region', is_false())323})324print("Success!")325}326327test_1.9.1 <- function(){328properties <- c(vertical_world$layers[[1]]$mapping, vertical_world$mapping)329labels <- vertical_world$labels330test_that('Did not create a plot named vertical_world', {331expect_true(exists("vertical_world"))332})333test_that('year should be on the x-axis.', {334expect_true("yr" == rlang::get_expr(properties$x))335})336test_that('pct_vaccinated should be on the y-axis.', {337expect_true("pct_vaccinated" == rlang::get_expr(properties$y))338})339test_that('vertical_world should be faceted by the vaccine column.', {340expect_that('FacetGrid' %in% class(rlang::get_expr(vertical_world$facet)), is_true())341})342test_that("vertical_world should be split vertically", {343expect_that("vaccine" %in% names(rlang::get_expr(vertical_world$facet$params$rows)), is_true())344})345if (length(vertical_world$layers) == 2) {346test_that('who_region should map to colour.', {347expect_that("who_region" == rlang::get_expr(c(vertical_world$layers[[1]]$mapping)$colour) &348"who_region" == rlang::get_expr(c(vertical_world$layers[[2]]$mapping)$colour) |349"who_region" == rlang::get_expr(c(vertical_world$layers[[2]]$mapping)$colour) &350"who_region" == rlang::get_expr(c(vertical_world$layers[[1]]$mapping)$colour), is_true())351} )} else {352test_that('who_region should map to colour.', {353expect_true("who_region" == rlang::get_expr(properties$colour))354})355}356357if (length(vertical_world$layers) == 2) { # if there are 2 layers then check if the two layers are points and lines358test_that('vertical_world should be a line plot.', {359expect_that("GeomPoint" %in% c(class(vertical_world$layers[[1]]$geom)) &360"GeomLine" %in% c(class(vertical_world$layers[[2]]$geom)) |361"GeomPoint" %in% c(class(vertical_world$layers[[2]]$geom)) &362"GeomLine" %in% c(class(vertical_world$layers[[1]]$geom)), is_true())363} )} else {364test_that('vertical_world should be a line plot.', {365expect_that("GeomLine" %in% c(class(vertical_world$layers[[1]]$geom)) , is_true())366})367}368test_that('Labels on the axes and legend should be descriptive and human readable.', {369expect_that((labels$y) == 'pct_vaccinated', is_false())370expect_that((labels$x) == 'yr', is_false())371expect_that((labels$colour) == 'who_region', is_false())372})373print("Success!")374}375376test_1.9.2 <- function(){377test_that('Solution is incorrect', {378expect_equal(digest(answer1.9.2), 'c1f86f7430df7ddb256980ea6a3b57a4') # we hid the answer to the test here so you can't see it, but we can still run the test379})380print("Success!")381}382383test_2.1 <- function(){384test_that('Solution is incorrect', {385expect_equal(digest(answer2.1), '3a5505c06543876fe45598b5e5e5195d') # we hid the answer to the test here so you can't see it, but we can still run the test386})387print("Success!")388}389390test_2.2 <- function(){391test_that('Did not create an object named fast_food', {392expect_true(exists("fast_food"))393})394test_that('fast_food does not contain the correct number of rows and/or columns.', {395expect_equal(dim(fast_food), c(10000, 2))396})397test_that('Columns in fast_food contain incorrect values.', {398expect_equal(digest(as.character(fast_food[[3,1]])), '2e716500dfeb89b1b087089a5b1355f8') # we hid the answer to the test here so you can't see it, but we can still run the test399expect_equal(digest(as.character(fast_food[[4,2]])), 'd599245d7d7e3f56863ba3a6112ca71b')400})401print("Success!")402}403404test_2.3 <- function(){405test_that('Did not create an object named top_restaurants', {406expect_true(exists("top_restaurants"))407})408test_that('top_restaurants does not contain the correct number of rows and/or columns.', {409expect_equal(dim(top_restaurants), c(9, 2))410})411test_that('Columns in fast_food contain incorrect values.', {412expect_equal(digest(sum(as.numeric(top_restaurants$n, na.rm = TRUE))), '4745bd90664c8cb9935cfb1a4cf51d77')413})414print("Success!")415}416417test_2.4 <- function(){418properties <- c(count_bar_chart$layers[[1]]$mapping, count_bar_chart$mapping)419labels <- count_bar_chart$labels420test_that('Did not create a plot named count_bar_chart', {421expect_true(exists("count_bar_chart"))422})423test_that('name should be on the x-axis.', {424expect_true("name" == rlang::get_expr(properties$x))425})426test_that('n should be on the y-axis.', {427expect_true("n" == rlang::get_expr(properties$y))428})429test_that('vertical_world should be a bar plot.', {430expect_that("GeomBar" %in% c(class(count_bar_chart$layers[[1]]$geom)) , is_true())431})432test_that('Labels on the axes and legend should be descriptive and human readable.', {433expect_that((labels$y) == 'n', is_false())434expect_that((labels$x) == 'name', is_false())435})436print("Success!")437}438439test_2.5_A <- function(){440properties <- c(count_bar_chart_A$layers[[1]]$mapping, count_bar_chart_A$mapping)441labels <- count_bar_chart_A$labels442test_that('Did not create a plot named count_bar_chart_A', {443expect_true(exists("count_bar_chart_A"))444})445test_that('name should be on the x-axis.', {446expect_true("name" == rlang::get_expr(properties$x))447})448test_that('x-axis (bar) labels should be at an angle between 20 and 90 degrees.', {449expect_that(count_bar_chart_A$theme$axis.text.x$angle <= 90 & count_bar_chart_A$theme$axis.text.x$angle >= 20, is_true())450})451test_that('hjust should equal 1', {452expect_equal(digest(as.numeric(count_bar_chart_A$theme$axis.text.x$hjust)), '6717f2823d3202449301145073ab8719')453})454test_that('n should be on the y-axis.', {455expect_true("n" == rlang::get_expr(properties$y))456})457test_that('vertical_world should be a bar plot.', {458expect_that("GeomBar" %in% c(class(count_bar_chart_A$layers[[1]]$geom)) , is_true())459})460test_that('Labels on the axes and legend should be descriptive and human readable.', {461expect_that((labels$y) == 'n', is_false())462expect_that((labels$x) == 'name', is_false())463})464print("Success!")465}466467test_2.5_B <- function(){468properties <- c(count_bar_chart_B$layers[[1]]$mapping, count_bar_chart_B$mapping)469labels <- count_bar_chart_B$labels470test_that('Did not create a plot named count_bar_chart_B', {471expect_true(exists("count_bar_chart_B"))472})473test_that('name should be on the x-axis.', {474expect_true("name" == rlang::get_expr(properties$x))475})476test_that('The coordinate axes should be flipped', {477expect_true("CoordFlip" %in% class(ggplot_build(count_bar_chart_B)$layout$coord))478})479test_that('n should be on the y-axis.', {480expect_true("n" == rlang::get_expr(properties$y))481})482test_that('vertical_world should be a bar plot.', {483expect_that("GeomBar" %in% c(class(count_bar_chart_B$layers[[1]]$geom)) , is_true())484})485test_that('Labels on the axes and legend should be descriptive and human readable.', {486expect_that((labels$y) == 'n', is_false())487expect_that((labels$x) == 'name', is_false())488})489print("Success!")490}491492test_2.6 <- function(){493test_that('Solution is incorrect', {494expect_equal(digest(answer2.6), '948a9b527842ee791d4f18fb5594fbf7')495})496print("Success!")497}498499test_2.7 <- function(){500test_that('Did not create an object named state_counts', {501expect_true(exists("state_counts"))502})503test_that('The state column in state_counts should only contain CA, OR, and WA', {504expect_equal((state_counts$st), c("CA", "OR", "WA"))505})506test_that('state_counts does not contain the correct number of rows and/or columns.', {507expect_equal(dim(state_counts), c(3, 2))508})509test_that('Columns in state_counts contain incorrect values.', {510expect_equal(digest(sum(as.numeric(state_counts$n, na.rm = TRUE))), '4745bd90664c8cb9935cfb1a4cf51d77')511})512print("Success!")513}514515test_2.8 <- function(){516properties <- c(state_counts_plot$layers[[1]]$mapping, state_counts_plot$mapping)517labels <- state_counts_plot$labels518test_that('Did not create a plot named state_counts_plot', {519expect_true(exists("state_counts_plot"))520})521test_that('state should be on the x-axis.', {522expect_true("st" == rlang::get_expr(properties$x))523})524test_that('n should be on the y-axis.', {525expect_true("n" == rlang::get_expr(properties$y))526})527test_that('state_counts_plot should be a bar plot.', {528expect_that("GeomBar" %in% c(class(state_counts_plot$layers[[1]]$geom)) , is_true())529})530test_that('state_counts_plot should not be filled.', {531expect_that("PositionFill" %in% class(state_counts_plot$layers[[1]]$position), is_false())532})533test_that('Labels on the axes and legend should be descriptive and human readable.', {534expect_that((labels$y) == 'n', is_false())535expect_that((labels$x) == 'st', is_false())536})537print("Success!")538}539540test_2.9.1 <- function(){541test_that('Solution is incorrect', {542expect_equal(digest(answer2.9.1), '2bedd54d48692762c119b27f5ec7a320')543})544print("Success!")545}546547test_2.9.2 <- function(){548test_that('Did not create an object named top_n_state', {549expect_true(exists("top_n_state"))550})551test_that('The state column in top_n_state should only contain CA, OR, and WA', {552expect_equal(digest(top_n_state$st), '8e6ddcfd9ebaf85379a6d46f7949bce0')553})554test_that('top_n_state does not contain the correct number of rows and/or columns.', {555expect_equal(dim(top_n_state), c(27, 3))556})557test_that('Columns in top_n_state contain incorrect values.', {558expect_equal(digest(sum(as.numeric(top_n_state$n, na.rm = TRUE))), '4745bd90664c8cb9935cfb1a4cf51d77')559})560print("Success!")561}562563test_2.9.3 <- function(){564properties <- c(top_n_state_plot$layers[[1]]$mapping, top_n_state_plot$mapping)565labels <- top_n_state_plot$labels566test_that('Did not create a plot named top_n_state_plot', {567expect_true(exists("top_n_state_plot"))568})569test_that('state should be on the x-axis.', {570expect_true("st" == rlang::get_expr(properties$x))571})572test_that('n should be on the y-axis.', {573expect_true("n" == rlang::get_expr(properties$y))574})575test_that('name should be used to determine bar fill colour.', {576expect_true("name" == rlang::get_expr(properties$fill))577})578test_that('top_n_state_plot should be a bar plot.', {579expect_that("GeomBar" %in% c(class(top_n_state_plot$layers[[1]]$geom)) , is_true())580})581test_that('top_n_state_plot position should be dodge.', {582expect_that("PositionDodge" %in% class(top_n_state_plot$layers[[1]]$position) , is_true())583})584test_that('Labels on the axes and legend should be descriptive and human readable.', {585expect_that((labels$y) == 'n', is_false())586expect_that((labels$x) == 'st', is_false())587expect_that((labels$fill) == 'name', is_false())588})589print("Success!")590}591592test_2.9.4 <- function(){593properties <- c(top_n_state_plot$layers[[1]]$mapping, top_n_state_plot$mapping)594labels <- top_n_state_plot$labels595test_that('Did not create a plot named top_n_state_plot', {596expect_true(exists("top_n_state_plot"))597})598test_that('state should be on the x-axis.', {599expect_true("st" == rlang::get_expr(properties$x))600})601test_that('n should be on the y-axis.', {602expect_true("n" == rlang::get_expr(properties$y))603})604test_that('name should be used to determine bar fill colour.', {605expect_true("name" == rlang::get_expr(properties$fill))606})607test_that('top_n_state_plot should be a bar plot.', {608expect_that("GeomBar" %in% c(class(top_n_state_plot$layers[[1]]$geom)) , is_true())609})610test_that('top_n_state_plot position should be fill', {611expect_that("PositionFill" %in% class(top_n_state_plot$layers[[1]]$position) , is_true())612})613test_that('Labels on the axes and legend should be descriptive and human readable.', {614expect_that((labels$y) == 'n', is_false())615expect_that((labels$x) == 'st', is_false())616expect_that((labels$x) == 'name', is_false())617})618print("Success!")619}620621test_2.9.5 <- function(){622test_that('Solution is incorrect', {623expect_equal(digest(answer2.9.5), '0590b0427c1b19a6eb612d19888aa52f') # we hid the answer to the test here so you can't see it, but we can still run the test624})625print("Success!")626}627628