Path: blob/master/2020-fall/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_false("character" %in% class(compare_vacc_plot$layers[[1]]$mapping$shape))120})121test_that('vaccine should map to shape and colour.', {122expect_false("character" %in% class(compare_vacc_plot$layers[[1]]$mapping$colour))123})124test_that('compare_vacc_plot should be a scatter plot.', {125expect_true("GeomPoint" %in% c(class(compare_vacc_plot$layers[[1]]$geom)))126})127test_that('Labels on the axes and legend need to be changed to be descriptive, nicely formatted, and human readable.', {128expect_false((labels$y) == 'pct_vaccinated')129expect_false((labels$x) == 'yr')130})131print("Success!")132}133134test_1.5 <- function(){135test_that('Did not create an object named polio', {136expect_true(exists("polio"))137})138test_that('The vaccine column in polio should only contain the polio vaccine.', {139expect_equal(unique(polio$vaccine), "polio")140})141test_that('polio does not contain the correct number of rows and/or columns.', {142expect_equal(dim(polio), c(228, 4))143})144test_that('Columns in polio contain incorrect values.', {145expect_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 test146})147print("Success!")148}149150test_1.6 <- function(){151properties <- c(polio_regions$layers[[1]]$mapping, polio_regions$mapping)152labels <- polio_regions$labels153test_that('Did not create a plot named polio_regions', {154expect_true(exists("polio_regions"))155})156test_that('year should be on the x-axis.', {157expect_true("yr" == rlang::get_expr(properties$x))158})159test_that('pct_vaccinated should be on the y-axis.', {160expect_true("pct_vaccinated" == rlang::get_expr(properties$y))161})162test_that('who_region should map to colour and shape.', {163expect_true("who_region" == rlang::get_expr(properties$colour))164})165test_that('who_region should map to shape and colour.', {166expect_true("who_region" == rlang::get_expr(properties$shape))167})168test_that('polio_regions should be a scatter plot.', {169expect_true("GeomPoint" %in% c(class(polio_regions$layers[[1]]$geom)))170})171test_that('Labels on the axes and legend should be descriptive and human readable.', {172expect_false((labels$y) == 'pct_vaccinated')173expect_false((labels$x) == 'yr')174})175print("Success!")176}177178179test_1.7.1 <- function(){180181properties <- c(polio_regions_line$layers[[1]]$mapping, polio_regions_line$mapping)182labels <- polio_regions_line$labels183184test_that('Did not create a plot named polio_regions_line', {185expect_true(exists("polio_regions_line"))186})187test_that('year should be on the x-axis.', {188expect_true("yr" == rlang::get_expr(properties$x))189})190test_that('pct_vaccinated should be on the y-axis.', {191expect_true("pct_vaccinated" == rlang::get_expr(properties$y))192})193test_that('who_region should map to colour.', {194expect_true("who_region" == rlang::get_expr(properties$colour))195})196197if (length(polio_regions_line$layers) == 2) {198test_that('who_region should map to colour.', {199expect_true("who_region" == rlang::get_expr(c(polio_regions_line$layers[[1]]$mapping)$colour) &200"who_region" == rlang::get_expr(c(polio_regions_line$layers[[2]]$mapping)$colour) |201"who_region" == rlang::get_expr(c(polio_regions_line$layers[[2]]$mapping)$colour) &202"who_region" == rlang::get_expr(c(polio_regions_line$layers[[1]]$mapping)$colour))203} )} else {204test_that('who_region should map to colour.', {205expect_true("who_region" == rlang::get_expr(properties$colour))206})207}208209if (length(polio_regions_line$layers) == 2) { # if there are 2 layers then check if the two layers are points and lines210test_that('polio_regions_line should be a line plot.', {211expect_true("GeomPoint" %in% c(class(polio_regions_line$layers[[1]]$geom)) &212"GeomLine" %in% c(class(polio_regions_line$layers[[2]]$geom)) |213"GeomPoint" %in% c(class(polio_regions_line$layers[[2]]$geom)) &214"GeomLine" %in% c(class(polio_regions_line$layers[[1]]$geom)))215} )} else {216test_that('polio_regions_line should be a line plot.', {217expect_true("GeomLine" %in% c(class(polio_regions_line$layers[[1]]$geom)))218})219}220test_that('Labels on the axes should be descriptive and human readable.', {221expect_false((labels$y) == 'pct_vaccinated')222expect_false((labels$x) == 'yr')223})224print("Success!")225}226227228test_1.7.2 <- function(){229properties <- c(polio_regions_line$layers[[1]]$mapping, polio_regions_line$mapping)230labels <- polio_regions_line$labels231test_that('Did not create a plot named polio_regions_line', {232expect_true(exists("polio_regions_line"))233})234test_that('year should be on the x-axis.', {235expect_true("yr" == rlang::get_expr(properties$x))236})237test_that('pct_vaccinated should be on the y-axis.', {238expect_true("pct_vaccinated" == rlang::get_expr(properties$y))239})240test_that('who_region should map to colour.', {241expect_true("who_region" == rlang::get_expr(properties$colour))242})243244if (length(polio_regions_line$layers) == 2) {245test_that('who_region should map to colour.', {246expect_true("who_region" == rlang::get_expr(c(polio_regions_line$layers[[1]]$mapping)$colour) &247"who_region" == rlang::get_expr(c(polio_regions_line$layers[[2]]$mapping)$colour) |248"who_region" == rlang::get_expr(c(polio_regions_line$layers[[2]]$mapping)$colour) &249"who_region" == rlang::get_expr(c(polio_regions_line$layers[[1]]$mapping)$colour))250} )} else {251test_that('who_region should map to colour.', {252expect_true("who_region" == rlang::get_expr(properties$colour))253})254}255256if (length(polio_regions_line$layers) == 2) { # if there are 2 layers then check if the two layers are points and lines257test_that('polio_regions_line should be a line plot.', {258expect_true("GeomPoint" %in% c(class(polio_regions_line$layers[[1]]$geom)) &259"GeomLine" %in% c(class(polio_regions_line$layers[[2]]$geom)) |260"GeomPoint" %in% c(class(polio_regions_line$layers[[2]]$geom)) &261"GeomLine" %in% c(class(polio_regions_line$layers[[1]]$geom)))262} )} else {263test_that('polio_regions_line should be a line plot.', {264expect_true("GeomLine" %in% c(class(polio_regions_line$layers[[1]]$geom)))265})266}267test_that('Labels on the axes and legend should be descriptive and human readable.', {268expect_false((labels$y) == 'pct_vaccinated')269expect_false((labels$x) == 'yr')270expect_false((labels$colour) == 'who_region')271})272print("Success!")273}274275276test_1.8 <- function(){277properties <- c(side_by_side_world$layers[[1]]$mapping, side_by_side_world$mapping)278labels <- side_by_side_world$labels279test_that('Did not create a plot named side_by_side_world', {280expect_true(exists("side_by_side_world"))281})282test_that('year should be on the x-axis.', {283expect_true("yr" == rlang::get_expr(properties$x))284})285test_that('pct_vaccinated should be on the y-axis.', {286expect_true("pct_vaccinated" == rlang::get_expr(properties$y))287})288test_that('side_by_side_world should be faceted by the vaccine column.', {289expect_true('FacetGrid' %in% class(rlang::get_expr(side_by_side_world$facet)))290})291test_that("side_by_side_world should be split horizontally", {292expect_true("vaccine" %in% names(rlang::get_expr(side_by_side_world$facet$params$cols)))293})294if (length(side_by_side_world$layers) == 2) {295test_that('who_region should map to colour.', {296expect_true("who_region" == rlang::get_expr(c(side_by_side_world$layers[[1]]$mapping)$colour) &297"who_region" == rlang::get_expr(c(side_by_side_world$layers[[2]]$mapping)$colour) |298"who_region" == rlang::get_expr(c(side_by_side_world$layers[[2]]$mapping)$colour) &299"who_region" == rlang::get_expr(c(side_by_side_world$layers[[1]]$mapping)$colour))300} )} else {301test_that('who_region should map to colour.', {302expect_true("who_region" == rlang::get_expr(properties$colour))303})304}305306if (length(side_by_side_world$layers) == 2) { # if there are 2 layers then check if the two layers are points and lines307test_that('side_by_side_world should be a line plot.', {308expect_true("GeomPoint" %in% c(class(side_by_side_world$layers[[1]]$geom)) &309"GeomLine" %in% c(class(side_by_side_world$layers[[2]]$geom)) |310"GeomPoint" %in% c(class(side_by_side_world$layers[[2]]$geom)) &311"GeomLine" %in% c(class(side_by_side_world$layers[[1]]$geom)))312} )} else {313test_that('side_by_side_world should be a line plot.', {314expect_true("GeomLine" %in% c(class(side_by_side_world$layers[[1]]$geom)))315})316}317test_that('Labels on the axes and legend should be descriptive and human readable.', {318expect_false((labels$y) == 'pct_vaccinated')319expect_false((labels$x) == 'yr')320expect_false((labels$colour) == 'who_region')321})322print("Success!")323}324325test_1.9.1 <- function(){326properties <- c(vertical_world$layers[[1]]$mapping, vertical_world$mapping)327labels <- vertical_world$labels328test_that('Did not create a plot named vertical_world', {329expect_true(exists("vertical_world"))330})331test_that('year should be on the x-axis.', {332expect_true("yr" == rlang::get_expr(properties$x))333})334test_that('pct_vaccinated should be on the y-axis.', {335expect_true("pct_vaccinated" == rlang::get_expr(properties$y))336})337test_that('vertical_world should be faceted by the vaccine column.', {338expect_true('FacetGrid' %in% class(rlang::get_expr(vertical_world$facet)))339})340test_that("vertical_world should be split vertically", {341expect_true("vaccine" %in% names(rlang::get_expr(vertical_world$facet$params$rows)))342})343if (length(vertical_world$layers) == 2) {344test_that('who_region should map to colour.', {345expect_true("who_region" == rlang::get_expr(c(vertical_world$layers[[1]]$mapping)$colour) &346"who_region" == rlang::get_expr(c(vertical_world$layers[[2]]$mapping)$colour) |347"who_region" == rlang::get_expr(c(vertical_world$layers[[2]]$mapping)$colour) &348"who_region" == rlang::get_expr(c(vertical_world$layers[[1]]$mapping)$colour))349} )} else {350test_that('who_region should map to colour.', {351expect_true("who_region" == rlang::get_expr(properties$colour))352})353}354355if (length(vertical_world$layers) == 2) { # if there are 2 layers then check if the two layers are points and lines356test_that('vertical_world should be a line plot.', {357expect_true("GeomPoint" %in% c(class(vertical_world$layers[[1]]$geom)) &358"GeomLine" %in% c(class(vertical_world$layers[[2]]$geom)) |359"GeomPoint" %in% c(class(vertical_world$layers[[2]]$geom)) &360"GeomLine" %in% c(class(vertical_world$layers[[1]]$geom)))361} )} else {362test_that('vertical_world should be a line plot.', {363expect_true("GeomLine" %in% c(class(vertical_world$layers[[1]]$geom)))364})365}366test_that('Labels on the axes and legend should be descriptive and human readable.', {367expect_false((labels$y) == 'pct_vaccinated')368expect_false((labels$x) == 'yr')369expect_false((labels$colour) == 'who_region')370})371print("Success!")372}373374test_1.9.2 <- function(){375test_that('Solution is incorrect', {376expect_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 test377})378print("Success!")379}380381test_2.1 <- function(){382test_that('Solution is incorrect', {383expect_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 test384})385print("Success!")386}387388test_2.2 <- function(){389test_that('Did not create an object named fast_food', {390expect_true(exists("fast_food"))391})392test_that('fast_food does not contain the correct number of rows and/or columns.', {393expect_equal(dim(fast_food), c(10000, 2))394})395test_that('Columns in fast_food contain incorrect values.', {396expect_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 test397expect_equal(digest(as.character(fast_food[[4,2]])), 'd599245d7d7e3f56863ba3a6112ca71b')398})399print("Success!")400}401402test_2.3 <- function(){403test_that('Did not create an object named top_restaurants', {404expect_true(exists("top_restaurants"))405})406test_that('top_restaurants does not contain the correct number of rows and/or columns.', {407expect_equal(dim(top_restaurants), c(9, 2))408})409test_that('Columns in fast_food contain incorrect values.', {410expect_equal(digest(sum(as.numeric(top_restaurants$n, na.rm = TRUE))), '4745bd90664c8cb9935cfb1a4cf51d77')411})412print("Success!")413}414415test_2.4 <- function(){416properties <- c(count_bar_chart$layers[[1]]$mapping, count_bar_chart$mapping)417labels <- count_bar_chart$labels418test_that('Did not create a plot named count_bar_chart', {419expect_true(exists("count_bar_chart"))420})421test_that('name should be on the x-axis.', {422expect_true("name" == rlang::get_expr(properties$x))423})424test_that('n should be on the y-axis.', {425expect_true("n" == rlang::get_expr(properties$y))426})427test_that('vertical_world should be a bar plot.', {428expect_true("GeomBar" %in% c(class(count_bar_chart$layers[[1]]$geom)))429})430test_that('Labels on the axes and legend should be descriptive and human readable.', {431expect_false((labels$y) == 'n')432expect_false((labels$x) == 'name')433})434print("Success!")435}436437test_2.5_A <- function(){438properties <- c(count_bar_chart_A$layers[[1]]$mapping, count_bar_chart_A$mapping)439labels <- count_bar_chart_A$labels440test_that('Did not create a plot named count_bar_chart_A', {441expect_true(exists("count_bar_chart_A"))442})443test_that('name should be on the x-axis.', {444expect_true("name" == rlang::get_expr(properties$x))445})446test_that('x-axis (bar) labels should be at an angle between 20 and 90 degrees.', {447expect_true(count_bar_chart_A$theme$axis.text.x$angle <= 90 & count_bar_chart_A$theme$axis.text.x$angle >= 20)448})449test_that('hjust should equal 1', {450expect_equal(digest(as.numeric(count_bar_chart_A$theme$axis.text.x$hjust)), '6717f2823d3202449301145073ab8719')451})452test_that('n should be on the y-axis.', {453expect_true("n" == rlang::get_expr(properties$y))454})455test_that('vertical_world should be a bar plot.', {456expect_true("GeomBar" %in% c(class(count_bar_chart_A$layers[[1]]$geom)))457})458test_that('Labels on the axes and legend should be descriptive and human readable.', {459expect_false((labels$y) == 'n')460expect_false((labels$x) == 'name')461})462print("Success!")463}464465test_2.5_B <- function(){466properties <- c(count_bar_chart_B$layers[[1]]$mapping, count_bar_chart_B$mapping)467labels <- count_bar_chart_B$labels468test_that('Did not create a plot named count_bar_chart_B', {469expect_true(exists("count_bar_chart_B"))470})471test_that('name should be on the x-axis.', {472expect_true("name" == rlang::get_expr(properties$x))473})474test_that('The coordinate axes should be flipped', {475expect_true("CoordFlip" %in% class(ggplot_build(count_bar_chart_B)$layout$coord))476})477test_that('n should be on the y-axis.', {478expect_true("n" == rlang::get_expr(properties$y))479})480test_that('vertical_world should be a bar plot.', {481expect_true("GeomBar" %in% c(class(count_bar_chart_B$layers[[1]]$geom)))482})483test_that('Labels on the axes and legend should be descriptive and human readable.', {484expect_false((labels$y) == 'n')485expect_false((labels$x) == 'name')486})487print("Success!")488}489490test_2.6 <- function(){491test_that('Solution is incorrect', {492expect_equal(digest(answer2.6), '948a9b527842ee791d4f18fb5594fbf7')493})494print("Success!")495}496497test_2.7 <- function(){498test_that('Did not create an object named state_counts', {499expect_true(exists("state_counts"))500})501test_that('The state column in state_counts should only contain CA, OR, and WA', {502expect_equal((state_counts$st), c("CA", "OR", "WA"))503})504test_that('state_counts does not contain the correct number of rows and/or columns.', {505expect_equal(dim(state_counts), c(3, 2))506})507test_that('Columns in state_counts contain incorrect values.', {508expect_equal(digest(sum(as.numeric(state_counts$n, na.rm = TRUE))), '4745bd90664c8cb9935cfb1a4cf51d77')509})510print("Success!")511}512513test_2.8 <- function(){514properties <- c(state_counts_plot$layers[[1]]$mapping, state_counts_plot$mapping)515labels <- state_counts_plot$labels516test_that('Did not create a plot named state_counts_plot', {517expect_true(exists("state_counts_plot"))518})519test_that('state should be on the x-axis.', {520expect_true("st" == rlang::get_expr(properties$x))521})522test_that('n should be on the y-axis.', {523expect_true("n" == rlang::get_expr(properties$y))524})525test_that('state_counts_plot should be a bar plot.', {526expect_true("GeomBar" %in% c(class(state_counts_plot$layers[[1]]$geom)))527})528test_that('state_counts_plot should not be filled.', {529expect_false("PositionFill" %in% class(state_counts_plot$layers[[1]]$position))530})531test_that('Labels on the axes and legend should be descriptive and human readable.', {532expect_false((labels$y) == 'n')533expect_false((labels$x) == 'st')534})535print("Success!")536}537538test_2.9.1 <- function(){539test_that('Solution is incorrect', {540expect_equal(digest(answer2.9.1), '2bedd54d48692762c119b27f5ec7a320')541})542print("Success!")543}544545test_2.9.2 <- function(){546test_that('Did not create an object named top_n_state', {547expect_true(exists("top_n_state"))548})549test_that('The state column in top_n_state should only contain CA, OR, and WA', {550expect_equal(digest(top_n_state$st), '8e6ddcfd9ebaf85379a6d46f7949bce0')551})552test_that('top_n_state does not contain the correct number of rows and/or columns.', {553expect_equal(dim(top_n_state), c(27, 3))554})555test_that('Columns in top_n_state contain incorrect values.', {556expect_equal(digest(sum(as.numeric(top_n_state$n, na.rm = TRUE))), '4745bd90664c8cb9935cfb1a4cf51d77')557})558print("Success!")559}560561test_2.9.3 <- function(){562properties <- c(top_n_state_plot$layers[[1]]$mapping, top_n_state_plot$mapping)563labels <- top_n_state_plot$labels564test_that('Did not create a plot named top_n_state_plot', {565expect_true(exists("top_n_state_plot"))566})567test_that('state should be on the x-axis.', {568expect_true("st" == rlang::get_expr(properties$x))569})570test_that('n should be on the y-axis.', {571expect_true("n" == rlang::get_expr(properties$y))572})573test_that('name should be used to determine bar fill colour.', {574expect_true("name" == rlang::get_expr(properties$fill))575})576test_that('top_n_state_plot should be a bar plot.', {577expect_true("GeomBar" %in% c(class(top_n_state_plot$layers[[1]]$geom)))578})579test_that('top_n_state_plot position should be dodge.', {580expect_true("PositionDodge" %in% class(top_n_state_plot$layers[[1]]$position))581})582test_that('Labels on the axes and legend should be descriptive and human readable.', {583expect_false((labels$y) == 'n')584expect_false((labels$x) == 'st')585expect_false((labels$fill) == 'name')586})587print("Success!")588}589590test_2.9.4 <- function(){591properties <- c(top_n_state_plot$layers[[1]]$mapping, top_n_state_plot$mapping)592labels <- top_n_state_plot$labels593test_that('Did not create a plot named top_n_state_plot', {594expect_true(exists("top_n_state_plot"))595})596test_that('state should be on the x-axis.', {597expect_true("st" == rlang::get_expr(properties$x))598})599test_that('n should be on the y-axis.', {600expect_true("n" == rlang::get_expr(properties$y))601})602test_that('name should be used to determine bar fill colour.', {603expect_true("name" == rlang::get_expr(properties$fill))604})605test_that('top_n_state_plot should be a bar plot.', {606expect_true("GeomBar" %in% c(class(top_n_state_plot$layers[[1]]$geom)))607})608test_that('top_n_state_plot position should be fill', {609expect_true("PositionFill" %in% class(top_n_state_plot$layers[[1]]$position))610})611test_that('Labels on the axes and legend should be descriptive and human readable.', {612expect_false((labels$y) == 'n')613expect_false((labels$x) == 'st')614expect_false((labels$x) == 'name')615})616print("Success!")617}618619test_2.9.5 <- function(){620test_that('Solution is incorrect', {621expect_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 test622})623print("Success!")624}625626