Skip to content

Commit 2362021

Browse files
committed
Remove flag skip_on_os to skip these tests on Apple M1 architecture. Add new conditional tests to account for numeric precision on the Apple M1 architecture (.Machine$sizeof.longdouble = 8) in comparison with other architectures
1 parent f4e5182 commit 2362021

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

tests/testthat/test-smk-corTestDS.R

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
# Set up
1313
#
1414

15-
# Skip these tests on Apple M1 mac
16-
skip_on_os("mac", arch = "aarch64")
17-
1815
context("corTestDS::smk::setup")
1916

2017
#
@@ -201,7 +198,32 @@ test_that("simple corTestDS, some, with na, pearson", {
201198

202199
expect_equal(class(res$`Correlation test`$statistic), "numeric")
203200
expect_length(res$`Correlation test`$statistic, 1)
204-
expect_true(is.infinite(res$`Correlation test`$statistic[[1]]))
201+
202+
# extract information from the results
203+
t_stat <- res$`Correlation test`$statistic[[1]]
204+
df <- res$`Number of pairwise complete cases`
205+
# re-calculate the value for r (correlation)
206+
## t_stat <- sqrt(df) * r / sqrt(1 - r^2) # Equation 1
207+
## calculate intermediate coefficient, derived from Equation 1
208+
A <- t_stat / sqrt(df)
209+
## use the intermediate value to estimate the correlation value, r
210+
r <- sqrt(A^2 / (1 + A^2))
211+
212+
# if testing on Apple M1: due to numeric precision
213+
if (getElement(Sys.info(), "sysname") == "Darwin" &&
214+
getElement(R.version, "arch") == "aarch64") {
215+
# lower tolerance, expect failure, due to numeric precision
216+
expect_error(expect_equal(r, 1L, tolerance = 1E-16))
217+
# higher tolerance, expect success
218+
expect_equal(r, 1L, tolerance = 1E-8)
219+
}
220+
else { # other architectures
221+
expect_true(is.infinite(res$`Correlation test`$statistic[[1]]))
222+
# lower tolerance, expect success
223+
expect_equal(r, 1L, tolerance = 1E-16)
224+
# higher tolerance, expect success
225+
expect_equal(r, 1L, tolerance = 1E-8)
226+
}
205227

206228
expect_equal(class(res$`Correlation test`$parameter), "integer")
207229
expect_length(res$`Correlation test`$parameter, 1)
@@ -611,3 +633,4 @@ test_that("simple corTestDS, some, with na, spearman", {
611633
context("corTestDS::smk::shutdown")
612634

613635
context("corTestDS::smk::done")
636+

0 commit comments

Comments
 (0)