# Test that eq_clean_data() returns data frame with DATE column
test_that("eq_clean_data returns data frame with DATE column", {
load("helper_data.rda")
a<-data %>%
eq_clean_data()
b<-a$DATE
expect_that(a, is_a("data.frame"))
expect_that(b, is_a("Date"))
})
# Test that eq_location_clean() returns data frame with LOCATION_NAME column
test_that("eq_location_clean() returns data frame with countries removed from LOCATION_NAME", {
load("helper_data.rda")
a<-data %>%
eq_location_clean()
b<-a$LOCATION_NAME
expect_that(a, is_a("data.frame"))
expect_that(b, is_a("character"))
})
# Test that geom_timeline() works
test_that("geom_timeline() works", {
load("helper_data.rda")
data2<-data %>%
filter(COUNTRY %in% c("USA", "CHINA"))
a<-ggplot(data2, aes(x=DATE, y=COUNTRY, size=EQ_PRIMARY,
color=DEATHS, label=LOCATION_NAME,
magnitude=EQ_PRIMARY)) +
geom_timeline(alpha=0.3,
xmin=as.Date("2000-01-01"),
xmax=as.Date("2017-01-01")) +
theme(axis.line.x = element_line(colour="black", size=1),
axis.title.y=element_blank(),
legend.position="bottom",
panel.background=element_blank())+
labs(size="Richter scale value",
color="# deaths")
expect_that(a, is_a("ggplot"))
})
# Test that geom_timeline_label() works
test_that("geom_timeline_label() works", {
load("helper_data.rda")
data2<-data %>%
filter(COUNTRY %in% c("USA", "CHINA"))
a<-ggplot(data2, aes(x=DATE, y=COUNTRY, size=EQ_PRIMARY,
color=DEATHS, label=LOCATION_NAME,
magnitude=EQ_PRIMARY)) +
geom_timeline(alpha=0.3,
xmin=as.Date("2000-01-01"),
xmax=as.Date("2017-01-01")) +
geom_timeline_label(xmin=as.Date("2000-01-01"),
xmax=as.Date("2015-01-01"),
n_max=5)+
theme(axis.line.x = element_line(colour="black", size=1),
axis.title.y=element_blank(),
legend.position="bottom",
panel.background=element_blank())+
labs(size="Richter scale value",
color="# deaths")
expect_that(a, is_a("ggplot"))
})
# Test that eq_map() produces an object of class "leaflet"
test_that("eq_map returns a leaflet object", {
load("helper_data.rda")
a<-data %>%
eq_clean_data() %>%
dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) >= 2000) %>%
eq_map(annot_col = "DATE")
expect_that(a, is_a("leaflet"))
})
# Test that the eq_create_label returns a character vector
test_that("eq_create_label returns a character vector", {
load("helper_data.rda")
a<-data %>%
eq_clean_data() %>%
dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) >= 2000) %>%
eq_create_label()
expect_that(a, is_a("character"))
})
# Test that eq_map() and eq_create_label() work well together
test_that("eq_map + eq_create_label return a leaflet object", {
load("helper_data.rda")
a<-data %>%
eq_clean_data() %>%
dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) >= 2000) %>%
dplyr::mutate(popup_text = eq_create_label(.)) %>%
eq_map(annot_col = "popup_text")
expect_that(a, is_a("leaflet"))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.