From a665ef53e9094227b4d5385170f90c28d932e793 Mon Sep 17 00:00:00 2001 From: Hugo Gruson Date: Sun, 10 Dec 2023 15:21:02 +0100 Subject: [PATCH] Use expect_identical() rather than expect_equal() --- tests/testthat/test-regression.R | 66 ++++++++++++++++---------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/tests/testthat/test-regression.R b/tests/testthat/test-regression.R index ecf4aedc..258e2cbf 100644 --- a/tests/testthat/test-regression.R +++ b/tests/testthat/test-regression.R @@ -9,18 +9,18 @@ test_that("coldist", { jnd.flowers <- jnd2xyz(cd.flowers) result1 <- jndrot(jnd2xyz(coldist(vismodel(flowers, achromatic = "bt.dc", relative = FALSE), achromatic = TRUE))) - expect_equal(dim(result1), c(36, 4)) - expect_equal(round(mean(unlist(result1)^3), 3), -132.915) + expect_identical(dim(result1), c(36L, 4L)) + expect_equal(round(mean(unlist(result1)^3), 3), -132.915) # nolint: https://github.com/r-lib/lintr/issues/2410 # Output result2 <- coldist(colspace(vismodel(flowers, visual = "canis", achromatic = "ml")), achromatic = TRUE) - expect_equal(dim(result2), c(630, 4)) + expect_identical(dim(result2), c(630L, 4L)) expect_equal(round(mean(unlist(result2[, 3:4])), 4), 0.8693) result3 <- coldist(colspace(vismodel(flowers, visual = "canis", achromatic = "all")), n = c(1, 2), achromatic = TRUE, subset = "Hibbertia_acicularis" ) - expect_equal(dim(result3), c(35, 4)) + expect_identical(dim(result3), c(35L, 4L)) expect_equal(round(mean(unlist(result3[, 3:4])), 4), 0.5388) result4 <- coldist( @@ -30,11 +30,11 @@ test_that("coldist", { ), space = "hexagon"), n = c(1, 2), achromatic = TRUE, subset = c("Hibbertia_acicularis", "Grevillea_buxifolia") ) - expect_equal(dim(result4), c(1, 4)) + expect_identical(dim(result4), c(1L, 4L)) expect_equal(round(mean(unlist(result4[, 3:4])), 4), 0.464) result5 <- coldist(colspace(vismodel(flowers, visual = "segment")), achromatic = TRUE) - expect_equal(dim(result5), c(630, 4)) + expect_identical(dim(result5), c(630L, 4L)) expect_equal(round(mean(unlist(result5[, 3:4])), 4), 0.2685) result6 <- coldist(colspace(vismodel(flowers, @@ -43,11 +43,11 @@ test_that("coldist", { vonkries = TRUE, relative = FALSE ), "cielab")) - expect_equal(dim(result6), c(630, 4)) + expect_identical(dim(result6), c(630L, 4L)) expect_equal(round(mean(unlist(result6[, 3])), 4), 28.7164) result7 <- coldist(as.matrix(vismodel(flowers, achro = "bt.dc")), qcatch = "Qi", achromatic = TRUE) - expect_equal(dim(result7), c(630, 4)) + expect_identical(dim(result7), c(630L, 4L)) expect_equal(round(mean(unlist(result7[, 3])), 4), 11.7606) }) @@ -72,27 +72,27 @@ test_that("bootcoldist", { test_that("special_colspace", { # Dispace result8 <- colspace(vismodel(flowers, visual = "canis", achromatic = "all")) - expect_equal(dim(result8), c(36, 5)) + expect_identical(dim(result8), c(36L, 5L)) expect_equal(round(mean(unlist(result8)), 4), 0.4061) # Trispace result9 <- colspace(vismodel(flowers, visual = "apis", achromatic = "l")) - expect_equal(dim(result9), c(36, 8)) + expect_identical(dim(result9), c(36L, 8L)) expect_equal(round(mean(unlist(result9)), 4), 0.0876) # tcs result10 <- colspace(vismodel(flowers, visual = "bluetit", achromatic = "ch.dc")) - expect_equal(dim(result10), c(36, 17)) + expect_identical(dim(result10), c(36L, 17L)) expect_equal(round(mean(unlist(result10)), 4), 0.0923) # categorical result11 <- colspace(vismodel(flowers, visual = "musca", achro = "md.r1"), space = "categorical") - expect_equal(dim(result11), c(36, 10)) - expect_equal(round(mean(unlist(result11[, -7])), 4), -0.0949) + expect_identical(dim(result11), c(36L, 10L)) + expect_equal(round(mean(unlist(result11[, -7])), 4), -0.0949) # nolint: https://github.com/r-lib/lintr/issues/2410 # segment result12 <- colspace(vismodel(flowers, visual = "segment", achromatic = "bt.dc"), space = "segment") - expect_equal(dim(result12), c(36, 9)) + expect_identical(dim(result12), c(36L, 9L)) expect_equal(round(mean(unlist(result12)), 4), 20.4668) # coc @@ -100,7 +100,7 @@ test_that("special_colspace", { visual = "apis", relative = FALSE, qcatch = "Ei", vonkries = TRUE, achromatic = "l" ), space = "coc") - expect_equal(dim(result13), c(36, 7)) + expect_identical(dim(result13), c(36L, 7L)) expect_equal(round(mean(unlist(result13)), 4), 0.5304) # hexagon @@ -108,22 +108,22 @@ test_that("special_colspace", { visual = "apis", qcatch = "Ei", vonkries = TRUE, relative = FALSE, achromatic = "l" ), space = "hexagon") - expect_equal(dim(result14), c(36, 10)) + expect_identical(dim(result14), c(36L, 10L)) expect_equal(round(mean(unlist(result14[-9])), 4), 20.3489) # ciezyx result15 <- colspace(vismodel(flowers, visual = "cie10"), space = "ciexyz") - expect_equal(dim(result15), c(36, 6)) + expect_identical(dim(result15), c(36L, 6L)) expect_equal(round(mean(unlist(result15)), 4), 0.3596) # cielab result16 <- colspace(vismodel(flowers, visual = "cie10"), space = "cielab") - expect_equal(dim(result16), c(36, 6)) + expect_identical(dim(result16), c(36L, 6L)) expect_equal(round(mean(unlist(result16)), 4), 9.5446) # cielch result17 <- colspace(vismodel(flowers, visual = "cie10"), space = "cielch") - expect_equal(dim(result17), c(36, 8)) + expect_identical(dim(result17), c(36L, 8L)) expect_equal(round(mean(unlist(result17)), 4), 26.2162) }) @@ -140,33 +140,33 @@ test_that("voloverlap()", { test_that("processing & general", { # Sensdata result18 <- sensdata(illum = "all", bkg = "all", trans = "all") - expect_equal(dim(result18), c(401, 7)) + expect_identical(dim(result18), c(401L, 7L)) expect_equal(round(mean(unlist(result18)), 4), 72.8731) # Peakshape result19 <- peakshape(flowers, absolute.min = TRUE) - expect_equal(dim(result19), c(36, 7)) + expect_identical(dim(result19), c(36L, 7L)) expect_equal(round(mean(unlist(result19[, 2:6]), na.rm = TRUE), 4), 287.7377) # Simulate # Ideal result20 <- summary(simulate_spec(ylim = c(0, 50))) - expect_equal(dim(result20), c(1, 23)) + expect_identical(dim(result20), c(1L, 23L)) expect_equal(round(mean(unlist(result20)), 4), 928.3311) # Sigmoidd low-high result21 <- summary(simulate_spec(wl_inflect = 550)) - expect_equal(dim(result21), c(1, 23)) + expect_identical(dim(result21), c(1L, 23L)) expect_equal(round(mean(unlist(subset(result21, select = -c(S2))), na.rm = TRUE), 4), 1479.6564) # Sigmoid high-low result22 <- summary(simulate_spec(wl_inflect = 550, ylim = c(100, 0))) - expect_equal(dim(result22), c(1, 23)) + expect_identical(dim(result22), c(1L, 23L)) expect_equal(round(mean(unlist(subset(result22, select = -c(S2, S9))), na.rm = TRUE), 4), 1885.9745) # Gaussian result23 <- summary(simulate_spec(wl_peak = 400)) - expect_equal(dim(result23), c(1, 23)) + expect_identical(dim(result23), c(1L, 23L)) expect_equal(round(mean(unlist(subset(result23, select = -c(S2, S9))), na.rm = TRUE), 4), 694.4126) # Merge @@ -191,35 +191,35 @@ test_that("images", { snakes <- getimg(system.file("testdata", "images", "snakes", package = "pavo")) - expect_equal(unlist(unname(summary(papilio))), "papilio") - expect_equal(unlist(unname(summary(snakes))), c("snake_01", "snake_02")) + expect_identical(unlist(unname(summary(papilio))), "papilio") + expect_identical(unlist(unname(summary(snakes))), c("snake_01", "snake_02")) }) test_that("vismodel", { result24 <- vismodel(flowers, visual = "canis", achromatic = "all", illum = "bluesky") - expect_equal(dim(result24), c(36, 3)) + expect_identical(dim(result24), c(36L, 3L)) expect_equal(round(mean(unlist(result24)), 4), 0.4572) result25 <- vismodel(flowers, visual = "apis", qcatch = "fi", achromatic = "ml", scale = 10000) - expect_equal(dim(result25), c(36, 4)) + expect_identical(dim(result25), c(36L, 4L)) expect_equal(round(mean(unlist(result25)), 4), 2.3597) result26 <- vismodel(flowers, visual = "bluetit", achromatic = "ch.dc", trans = "bluetit") - expect_equal(dim(result26), c(36, 5)) + expect_identical(dim(result26), c(36L, 5L)) expect_equal(round(mean(unlist(result26)), 4), 0.2832) result27 <- vismodel(flowers, visual = "musca", achromatic = "md.r1", relative = FALSE) - expect_equal(dim(result27), c(36, 5)) + expect_identical(dim(result27), c(36L, 5L)) expect_equal(round(mean(unlist(result27)), 4), 0.1904) result28 <- vismodel(flowers, visual = "apis", relative = FALSE, qcatch = "Ei", bkg = "green", vonkries = TRUE, achromatic = "l" ) - expect_equal(dim(result28), c(36, 4)) + expect_identical(dim(result28), c(36L, 4L)) expect_equal(round(mean(unlist(result28)), 4), 0.5457) result29 <- vismodel(flowers, visual = "cie10") - expect_equal(dim(result29), c(36, 4)) + expect_identical(dim(result29), c(36L, 4L)) expect_equal(round(mean(unlist(result29), na.rm = TRUE), 4), 0.3859) })