expect_equal_tables: Compares JASP tables in unit tests.

View source: R/testthat-helper-tables.R

expect_equal_tablesR Documentation

Compares JASP tables in unit tests.

Description

This function compares a stored list of table data, to the table that is created when the tests are run.

Usage

expect_equal_tables(test, ref, label = NULL)

Arguments

test

The table object.

ref

The reference table list created previously by applying makeTestTable to a JASP table returned from runAnalysis.

label

Used to customise failure messages.

Details

By default, numbers are compared using signif(round(x, digits = 4), digits = 4). A custom function to use for rounding numeric values can be passed by setting options("jaspRoundToPrecision"). This function should return numbers rounded to the desired accuracy.

Examples


options <- analysisOptions("BinomialTest")
options$variables <- "contBinom"
options$testValue <- 0.6
options$hypothesis <- "greaterThanTestValue"
options$confidenceInterval <- TRUE
options$VovkSellkeMPR <- TRUE
results <- runAnalysis("BinomialTest", "test.csv", options)
table <- results[["results"]][["binomialTable"]][["data"]]
expect_equal_tables(table,
                    list("TRUE", 1, 58, 0, 0.492841460660175, 0.696739870156555, 0.58, 100, 1, "contBinom",
                         "FALSE", 1, 42, 1, 0.336479745077558, 0.999903917924738, 0.42, 100, 1, "contBinom"))

# illustration of custom tolerance
expect_equal_tables(list(0.50001), list(0.50000))
try(expect_equal_tables(list(0.51), list(0.50)))

# increase tolerance
options("jaspRoundToPrecision" = function(x) signif(round(x, digits = 1), digits = 1))
expect_equal_tables(list(0.51), list(0.50))

# reset tolerance to default
options("jaspRoundToPrecision" = NULL) # reset default
try(expect_equal_tables(list(0.51), list(0.50)))


jasp-stats/JASPTools documentation built on April 24, 2024, 11:18 a.m.