-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ui tests for assumptiopns, correlations, statisticla tests, tte…
…st and visualisation
- Loading branch information
1 parent
fc35c5b
commit a78557e
Showing
5 changed files
with
551 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
library(shinytest2) | ||
library(tinytest) | ||
app <- bs::app() | ||
app <- shiny::shinyApp(app$ui, app$server) | ||
app <- AppDriver$new(app) | ||
app$upload_file( | ||
file = system.file("/test_data/CO2.csv", package = "bs") | ||
) | ||
app$set_inputs(conditionedPanels = "Assumption") | ||
app$set_window_size(width = 2259, height = 1326) | ||
app$click("ASS-open_formula_editor") | ||
app$set_inputs(`FO-colnames-dropdown_0` = "uptake") | ||
app$click("FO-colnames_Treatment_0") | ||
app$click("FO-create_formula") | ||
app$run_js("$('.modal-footer button:contains(\"Close\")').click();") | ||
app$click("ASS-shapiro") | ||
res <- app$get_values()$export | ||
expected <- rbind( | ||
broom::tidy(shapiro.test(CO2[CO2$Treatment == "nonchilled", "uptake"])), | ||
broom::tidy(shapiro.test(CO2[CO2$Treatment == "chilled", "uptake"])) | ||
) | ||
expected$variable <- c("nonchilled", "chilled") | ||
expected$`Normal distributed` <- expected$p.value > 0.05 | ||
expected | ||
tinytest::expect_equal(res[[1]], expected) | ||
|
||
# Update output value | ||
app$click("ASS-shapiroResiduals") | ||
res <- app$get_values()$export | ||
fit <- lm(uptake ~ Treatment, data = CO2) | ||
r <- resid(fit) | ||
expected <- broom::tidy(shapiro.test(r)) | ||
expected$`Residuals normal distributed` <- expected$p.value > 0.05 | ||
tinytest::expect_equal(res[[1]], expected) | ||
|
||
# Update output value | ||
app$click("ASS-levene") | ||
res <- app$get_values()$export | ||
expected <- broom::tidy(car::leveneTest(uptake ~ Treatment, | ||
data = CO2, center = "mean")) | ||
expected$`Variance homogenity` <- expected$p.value > 0.05 | ||
tinytest::expect_equal(res[[1]], expected) | ||
|
||
# Update output value | ||
app$click("ASS-DiagnosticPlot") | ||
res <- app$get_values()$export | ||
tinytest::expect_equal(inherits(res[[1]], "ggplot"), TRUE) | ||
# TODO: add internal backend test for diagnostic plot functions | ||
|
||
app$stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
library(shinytest2) | ||
library(tinytest) | ||
app <- bs::app() | ||
app <- shiny::shinyApp(app$ui, app$server) | ||
app <- AppDriver$new(app) | ||
app$upload_file( | ||
file = system.file("/test_data/CO2.csv", package = "bs") | ||
) | ||
app$set_window_size(width = 2259, height = 1326) | ||
app$set_inputs(conditionedPanels = "Correlation") | ||
app$click("CORR-open_formula_editor") | ||
app$set_inputs(`FO-colnames-dropdown_0` = "uptake") | ||
app$click("FO-colnames_conc_0") | ||
app$click("FO-create_formula") | ||
app$run_js("$('.modal-footer button:contains(\"Close\")').click();") | ||
app$click("CORR-pear") | ||
res <- app$get_values()$export | ||
expected <- cor.test(CO2$uptake, CO2$conc, method = "pearson") | ||
expected <- broom::tidy(expected) | ||
tinytest::expect_equal(res[[1]], expected) | ||
app$click("CORR-spear") | ||
res <- app$get_values()$export | ||
expected <- cor.test(CO2$uptake, CO2$conc, method = "spearman") | ||
expected <- broom::tidy(expected) | ||
tinytest::expect_equal(res[[1]], expected) | ||
app$click("CORR-kendall") | ||
res <- app$get_values()$export | ||
expected <- cor.test(CO2$uptake, CO2$conc, method = "kendall") | ||
expected <- broom::tidy(expected) | ||
tinytest::expect_equal(res[[1]], expected) | ||
app$stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
library(shinytest2) | ||
library(tinytest) | ||
app <- bs::app() | ||
app <- shiny::shinyApp(app$ui, app$server) | ||
app <- AppDriver$new(app) | ||
app$upload_file( | ||
file = system.file("/test_data/CO2.csv", package = "bs") | ||
) | ||
app$set_window_size(width = 2259, height = 1326) | ||
app$set_inputs(conditionedPanels = "Tests") | ||
|
||
# Define formula | ||
app$click("TESTS-open_formula_editor") | ||
app$set_inputs(`FO-colnames-dropdown_0` = "uptake") | ||
app$set_inputs(`FO-editable_code` = "conc * Treatment + Type") | ||
app$click("FO-create_formula") | ||
app$run_js("$('.modal-footer button:contains(\"Close\")').click();") | ||
|
||
# ANOVA | ||
app$set_inputs(TestsConditionedPanels = "More than two groups") | ||
app$click("TESTS-aovTest") | ||
res <- app$get_values()$export | ||
CO2$Treatment <- as.character(CO2$Treatment) | ||
CO2$Type <- as.character(CO2$Type) | ||
expected <- broom::tidy(aov(uptake ~ conc*Treatment + Type, data = CO2)) | ||
expected <- cbind(expected, row.names(expected)) | ||
names(expected)[ncol(expected)] <- paste0("conc * Treatment + Type", collapse = ".") | ||
tinytest::expect_equal(res[[1]], expected) | ||
|
||
# Kruskal-Wallis | ||
app$click("TESTS-open_formula_editor") | ||
app$set_inputs(`FO-colnames-dropdown_0` = "uptake") | ||
app$set_inputs(`FO-editable_code` = "conc") | ||
app$click("FO-create_formula") | ||
app$run_js("$('.modal-footer button:contains(\"Close\")').click();") | ||
|
||
app$click("TESTS-kruskalTest") | ||
res <- app$get_values()$export | ||
CO2$Treatment <- as.character(CO2$Treatment) | ||
expected <- broom::tidy(kruskal.test(uptake ~conc, data = CO2)) | ||
expected <- cbind(expected, row.names(expected)) | ||
names(expected)[ncol(expected)] <- paste0("conc", collapse = ".") | ||
tinytest::expect_equal(res[[1]], expected) | ||
|
||
# PostHoc tests | ||
# TukeyHSD | ||
app$set_inputs(TestsConditionedPanels = "Posthoc tests") | ||
app$set_inputs(`TESTS-PostHocTests` = "HSD") | ||
app$click("TESTS-PostHocTest") | ||
res <- app$get_values()$export | ||
fit <- aov(uptake ~ conc, data = CO2) | ||
fit <- agricolae::HSD.test(fit, | ||
trt = "conc", | ||
alpha = 0.05, group = TRUE, unbalanced = TRUE | ||
)$groups | ||
expected <- cbind(fit, row.names(fit)) | ||
names(expected)[ncol(expected)] <- paste0("conc", collapse = ".") | ||
tinytest::expect_equal(res[[1]], expected) | ||
|
||
app$set_inputs(TestsConditionedPanels = "Posthoc tests") | ||
app$set_inputs(`TESTS-PostHocTests` = "HSD") | ||
app$set_inputs(`TESTS-design` = "ub") | ||
app$click("TESTS-PostHocTest") | ||
res <- app$get_values()$export | ||
fit <- aov(uptake ~ conc, data = CO2) | ||
fit <- agricolae::HSD.test(fit, | ||
trt = "conc", | ||
alpha = 0.05, group = TRUE, unbalanced = FALSE | ||
)$groups | ||
expected <- cbind(fit, row.names(fit)) | ||
names(expected)[ncol(expected)] <- paste0("conc", collapse = ".") | ||
tinytest::expect_equal(res[[1]], expected) | ||
|
||
# Kruskal-Wallis test | ||
app$set_inputs(`TESTS-PostHocTests` = "kruskalTest") | ||
app$click("TESTS-PostHocTest") | ||
res <- app$get_values()$export | ||
df <- CO2 | ||
dep <- "uptake" | ||
fit <- with(df, agricolae::kruskal(df[, dep],df[, "conc"]), | ||
alpha = 0.05, p.adj = 0.05, group = TRUE | ||
)$groups | ||
expected <- cbind(fit, row.names(fit)) | ||
names(expected)[ncol(expected)] <- paste0("conc", collapse = ".") | ||
tinytest::expect_equal(res[[1]], expected) | ||
|
||
# LSD | ||
|
||
|
||
# scheffe | ||
|
||
|
||
# REGW | ||
|
||
app$view() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
library(shinytest2) | ||
library(tinytest) | ||
app <- bs::app() | ||
app <- shiny::shinyApp(app$ui, app$server) | ||
app <- AppDriver$new(app) | ||
app$upload_file( | ||
file = system.file("/test_data/CO2.csv", package = "bs") | ||
) | ||
app$set_window_size(width = 2259, height = 1326) | ||
app$set_inputs(conditionedPanels = "Tests") | ||
app$click("TESTS-open_formula_editor") | ||
app$set_inputs(`FO-colnames-dropdown_0` = "uptake") | ||
app$click("FO-colnames_Treatment_0") | ||
app$click("FO-create_formula") | ||
app$run_js("$('.modal-footer button:contains(\"Close\")').click();") | ||
|
||
app$click("TESTS-tTest") | ||
res <- app$get_values()$export | ||
CO2$Treatment <- as.character(CO2$Treatment) | ||
expected <- broom::tidy( | ||
t.test( | ||
uptake ~ Treatment, data = CO2, | ||
var.equal = TRUE, conf.level = 0.95, | ||
alternative = "two.sided" | ||
) | ||
) | ||
tinytest::expect_equal(res[[1]], expected) | ||
# Update output value | ||
app$set_inputs(`TESTS-altHyp` = "less") | ||
app$click("TESTS-tTest") | ||
res <- app$get_values()$export | ||
expected <- broom::tidy( | ||
t.test( | ||
uptake ~ Treatment, data = CO2, | ||
var.equal = TRUE, conf.level = 0.95, | ||
alternative = "less" | ||
) | ||
) | ||
tinytest::expect_equal(res[[1]], expected) | ||
# Update output value | ||
app$set_inputs(`TESTS-altHyp` = "greater") | ||
app$click("TESTS-tTest") | ||
res <- app$get_values()$export | ||
expected <- broom::tidy( | ||
t.test( | ||
uptake ~ Treatment, data = CO2, | ||
var.equal = TRUE, conf.level = 0.95, | ||
alternative = "greater" | ||
) | ||
) | ||
tinytest::expect_equal(res[[1]], expected) | ||
# Update output value | ||
app$set_inputs(`TESTS-varEq` = "noeq") | ||
app$click("TESTS-tTest") | ||
res <- app$get_values()$export | ||
expected <- broom::tidy( | ||
t.test( | ||
uptake ~ Treatment, data = CO2, | ||
var.equal = FALSE, conf.level = 0.95, | ||
alternative = "greater" | ||
) | ||
) | ||
tinytest::expect_equal(res[[1]], expected) | ||
app$stop() |
Oops, something went wrong.