# unit test for eq_clean_data function
test_that("eq_clean_data does not work",
{
raw_noaa <- readr::read_delim(system.file("/extdata/signif.txt",
package="CapstoneSubmit"),
delim="\t")
processed_noaa <- eq_clean_data(raw_noaa)
expect_equal("DATE" %in% colnames(processed_noaa), TRUE)
expect_equal(lubridate::is.Date(processed_noaa$DATE), TRUE)
expect_equal(any(is.na(processed_noaa$MONTH)), FALSE)
expect_equal(any(is.na(processed_noaa$DAY)), FALSE)
expect_equal(is.numeric(processed_noaa$LATITUDE), TRUE)
expect_equal(is.numeric(processed_noaa$LONGITUDE), TRUE)
expect_equal(is.numeric(processed_noaa$SECOND), TRUE)
expect_equal(is.numeric(processed_noaa$EQ_PRIMARY), TRUE)
expect_equal(is.numeric(processed_noaa$EQ_MAG_MW), TRUE)
expect_equal(is.numeric(processed_noaa$EQ_MAG_MS), TRUE)
expect_equal(is.numeric(processed_noaa$EQ_MAG_MB), TRUE)
expect_equal(is.numeric(processed_noaa$EQ_MAG_ML), TRUE)
expect_equal(is.numeric(processed_noaa$EQ_MAG_MFA), TRUE)
expect_equal(is.numeric(processed_noaa$EQ_MAG_UNK), TRUE)
expect_equal(is.numeric(processed_noaa$DEATHS), TRUE)
expect_equal(is.numeric(processed_noaa$MISSING), TRUE)
expect_equal(is.numeric(processed_noaa$INJURIES), TRUE)
expect_equal(is.numeric(processed_noaa$DAMAGE_MILLIONS_DOLLARS), TRUE)
expect_equal(is.numeric(processed_noaa$TOTAL_DEATHS), TRUE)
expect_equal(is.numeric(processed_noaa$TOTAL_MISSING), TRUE)
expect_equal(is.numeric(processed_noaa$TOTAL_MISSING_DESCRIPTION), TRUE)
expect_equal(is.numeric(processed_noaa$TOTAL_DAMAGE_MILLIONS_DOLLARS), TRUE)
})
# unit test for eq_location_clean function
test_that("eq_location_clean does not work",
{
raw_noaa <- readr::read_delim(system.file("/extdata/signif.txt",
package="CapstoneSubmit"),
delim="\t")
processed_noaa <- eq_location_clean(raw_noaa)
should_be <- c("Bab-a-Daraa,al-Karak", "Ugarit", "w",
"Thera Island (Santorini)", "Ariha (Jericho)",
"Lacus Cimini")
actual <- processed_noaa$LOCATION_NAME[1:6]
expect_equal(actual, should_be)
})
# unit test for eq_create_label function
test_that("eq_create_label does not work",
{
raw_noaa <- readr::read_delim(system.file("/extdata/signif.txt",
package="CapstoneSubmit"),
delim="\t")
processed <- eq_create_label(raw_noaa)
should_be <- c("<b>Location: </b> JORDAN: BAB-A-DARAA,AL-KARAK <br /> <b>Magnitude: </b> 7.3 <br /> ",
"<b>Location: </b> SYRIA: UGARIT <br /> " ,
"<b>Location: </b> TURKMENISTAN: W <br /> <b>Magnitude: </b> 7.1 <br /> <b>Total Deaths: </b> 1" ,
"<b>Location: </b> GREECE: THERA ISLAND (SANTORINI) <br /> ",
"<b>Location: </b> ISRAEL: ARIHA (JERICHO) <br /> ",
"<b>Location: </b> ITALY: LACUS CIMINI <br /> ",
"<b>Location: </b> SYRIAN COASTS <br /> ",
"<b>Location: </b> ISRAEL: ARIHA (JERICHO) <br /> <b>Magnitude: </b> 6.5 <br /> ",
"<b>Location: </b> JORDAN: SW: TIMNA COPPER MINES <br /> <b>Magnitude: </b> 6.2 <br /> ",
"<b>Location: </b> ISRAEL: JERUSALEM <br /> ")
actual <- processed[1:10]
expect_equal(actual, should_be)
})
# unit test for geom_timeline function
test_that("geom_timeline does not work",
{
noaa <- readr::read_delim(system.file("/extdata/signif.txt", package="CapstoneSubmit"), delim="\t")
noaa <- noaa %>% eq_clean_data %>% eq_location_clean()
actual <- ggplot(noaa[noaa$COUNTRY=="CHINA", ] ,
aes(DATE, COUNTRY, size=EQ_MAG_MW, colour=DEATHS)) +
geom_timeline(xmin="-1000-01-01", xmax="1000-01-01")
expect_is(actual, "ggplot")
expect_is(actual$layers[[1]], "ggproto")
})
# unit test for geom_timeline_label function
test_that("geom_timeline_label does not work",
{
noaa <- readr::read_delim(system.file("/extdata/signif.txt", package="CapstoneSubmit"), delim="\t")
noaa <- noaa %>% eq_clean_data %>% eq_location_clean()
actual <- ggplot(noaa[noaa$COUNTRY=="CHINA", ] ,
aes(DATE, COUNTRY, size=EQ_MAG_MW, colour=DEATHS)) +
geom_timeline_label(aes(label=LOCATION_NAME), n_max=10,xmin="-1000-01-01", xmax="1000-01-01")
expect_is(actual, "ggplot")
expect_is(actual$layers[[1]], "ggproto")
})
# unit test for eq_map function
test_that("eq_map does not work",
{
noaa <- readr::read_delim(system.file("/extdata/signif.txt", package="CapstoneSubmit"), delim="\t")
actual <- noaa %>%
eq_clean_data() %>% eq_location_clean() %>%
dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) >= 2000) %>%
eq_map(annot_col = "DATE")
expect_is(actual, "htmlwidget")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.