From e86fd7c738838108e11d912c5db0f0156a21b4f8 Mon Sep 17 00:00:00 2001 From: Tarun Date: Thu, 5 Dec 2024 10:49:55 +0530 Subject: [PATCH] add-test-to-animint2 --- tests/mytests.r | 15 ++++++ .../test-renderer3-TestWorldBankTwoLayers.r | 46 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tests/mytests.r create mode 100644 tests/testthat/test-renderer3-TestWorldBankTwoLayers.r diff --git a/tests/mytests.r b/tests/mytests.r new file mode 100644 index 00000000..4877f871 --- /dev/null +++ b/tests/mytests.r @@ -0,0 +1,15 @@ +library("testthat") +library("animint2") +library("RSelenium") +library("XML") +source("helper-functions.R") +source("helper-HTML.R") +source("helper-plot-data.r") + +tests_init() +tests_run(filter="renderer3-TestWorldBankTwoLayers") +tests_exit() + +tests_init("firefox") +tests_run(filter="renderer3-TestWorldBankTwoLayers") +tests_exit() \ No newline at end of file diff --git a/tests/testthat/test-renderer3-TestWorldBankTwoLayers.r b/tests/testthat/test-renderer3-TestWorldBankTwoLayers.r new file mode 100644 index 00000000..f2671d4d --- /dev/null +++ b/tests/testthat/test-renderer3-TestWorldBankTwoLayers.r @@ -0,0 +1,46 @@ +acontext("TestWorldBankTwoLayers") + +data(WorldBank, package="animint2") + +# Filter the data for specific years +WorldBank1975 <- subset(WorldBank, year == 1975) +WorldBankBefore1975 <- subset(WorldBank, 1970 <= year & year <= 1975) + +# Define income levels and colors +income.colors <- c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#FFFF33") +WorldBank$income <- factor(WorldBank$income, + levels = c("High income: nonOECD", "High income: OECD", + "Upper middle income", "Lower middle income", + "Low income", "Not classified")) +names(income.colors) <- levels(WorldBank$income) + +# Create the scatter plot with one layer +scatter <- ggplot() + + scale_color_manual(values = income.colors) + + geom_point( + mapping = aes(x = life.expectancy, y = fertility.rate, color = income), + data = WorldBank1975 + ) + +# Add the second layer for paths +two.layers <- scatter + + geom_path( + aes( + x = life.expectancy, + y = fertility.rate, + color = income, + group = country + ), + data = WorldBankBefore1975 + ) + +# Create an interactive plot +scatter_plot <- list(plot = two.layers) +animint(scatter_plot) + +# Test that the visualization generates without warnings or errors +test_that("worldbank two-layers visualization generated without any warnings or errors", { + expect_no_warning({ + info <- animint2HTML(scatter_plot) + }) +}) \ No newline at end of file