Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add-test-to-animint2 #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add-test-to-animint2 #176

wants to merge 1 commit into from

Conversation

busttech
Copy link

@busttech busttech commented Dec 5, 2024

This solution of the hard-test(gsoc)
video = https://www.youtube.com/watch?v=Gog2Sv7t_cE
The visualization I used for testing --> https://busttech.github.io/deploy/

tests_init()
tests_run(filter="renderer3-TestWorldBankTwoLayers")
tests_exit()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove mytests.r file

# 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test does not use the renderer. please show that you understand how to inspect the output of the chromote renderer, and simulate interaction.

  • first add an expectation about info$html (maybe all of the regions are shown by default at first?)
  • then please use clickID() to simulate interaction (maybe with your legend?),
  • and then use getHTML() to get the HTML after the simulated interaction,
  • and then finally use another expectation about what the HTML looks like after interaction.

also this world bank data viz is not a very interesting test case, because you have no clickSelects/showSelected here. Instead can you write a test based on the animation example you created? https://busttech.github.io/deploy2/

@tdhock
Copy link
Collaborator

tdhock commented Dec 5, 2024

also for the video can you please narrate next time? use your voice to explain what you are doing, what you observe after executing each command, etc.

@busttech
Copy link
Author

busttech commented Dec 26, 2024

Sir I was not able to fullfill the changes that you given but I changed the test case to the animation example that I created https://busttech.github.io/deploy2/ .Can you please provide any manual or previous test cases so I can fullfill the other changes also.

faces <- c("Head", "Tail", "Stand")
prob <- c(0.45, 0.45, 0.1)
n_tosses <- 100

flips <- sample(faces, size = n_tosses, replace = TRUE, prob = prob)
flip_data <- data.frame(
  toss = seq_len(n_tosses),
  result = flips
)

flip_data <- flip_data %>% 
  mutate(HEAD = cumsum(result == "Head"),
         TAIL = cumsum(result == "Tail"),
         STAND = cumsum(result == "Stand"))

flip_data_long <- flip_data %>% 
  pivot_longer(cols = c("HEAD", "TAIL", "STAND"), 
               names_to = "outcome", 
               values_to = "count") %>% 
  mutate(outcome = factor(outcome, levels = c("HEAD", "TAIL", "STAND"))) 

flip_data$result <- factor(flip_data$result, levels = c("Head", "Tail", "Stand"))

bar_plot <- ggplot(flip_data_long) +
  geom_bar(aes(x = outcome, y = count, fill = outcome), 
           stat = "identity", 
           position = "identity", 
           showSelected = "toss") +
  geom_text(aes(x = outcome, y = count, label = count), 
            vjust = 0, 
            showSelected = "toss") +
  labs(title = "Coin Flip Frequencies (Interactive)", 
       x = "Face", 
       y = "Count") +
  scale_x_discrete(labels = c("Head", "Tail", "Stand")) +
  scale_fill_manual(values = c("HEAD" = "red", 
                               "TAIL" = "green", 
                               "STAND" = "blue")) +
  guides(fill = "none")



line_plot <- ggplot(flip_data, aes(x = toss)) +
  geom_line(aes(y = HEAD / toss, color = result, group = result), size = 1) +
  geom_point(aes(y = HEAD / toss, color = result), size = 2, showSelected = "toss") +
  geom_tallrect(aes(xmin = toss - 0.5, xmax = toss + 0.5), alpha = 0.2, clickSelects = "toss") +
  labs(title = "Cumulative Frequency Over Tosses (Interactive)", 
       x = "Toss Number", 
       y = "Cumulative Frequency") +
  scale_color_manual(values = c("Head" = "red", 
                                "Tail" = "green", 
                                "Stand" = "blue"))



plots <- list(
  frequency = bar_plot,         
  cumulative = line_plot,       
  time = list(variable = "toss", ms = 200)
)


animint(plots)

# Test that the visualization generates without warnings or errors
test_that("Flip-coin animation generated without any warnings or errors", {
  expect_no_warning({
    info <- animint2HTML(plots)
  })
})

@tdhock
Copy link
Collaborator

tdhock commented Dec 29, 2024

please grep tests/testthat/test-renderer-* files for "clickID" to see examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants