animint2 icon indicating copy to clipboard operation
animint2 copied to clipboard

add-test-to-animint2

Open busttech opened this issue 1 year ago • 3 comments

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/

busttech avatar Dec 05 '24 10:12 busttech

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.

tdhock avatar Dec 05 '24 14:12 tdhock

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)
  })
})

busttech avatar Dec 26 '24 06:12 busttech

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

tdhock avatar Dec 29 '24 16:12 tdhock