From a291856ca27f36e751e86b67a8bb9a7c1813d897 Mon Sep 17 00:00:00 2001 From: Hugo Gruson <10783929+Bisaloo@users.noreply.github.com> Date: Thu, 11 Jul 2024 09:32:24 +0200 Subject: [PATCH] Create stricter tests for jnd2xyz() --- tests/testthat/_snaps/jnd2xyz.md | 129 +++++++++++++++++++++++++++++++ tests/testthat/test-jnd2xyz.R | 58 ++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 tests/testthat/_snaps/jnd2xyz.md create mode 100644 tests/testthat/test-jnd2xyz.R diff --git a/tests/testthat/_snaps/jnd2xyz.md b/tests/testthat/_snaps/jnd2xyz.md new file mode 100644 index 00000000..93daeb4e --- /dev/null +++ b/tests/testthat/_snaps/jnd2xyz.md @@ -0,0 +1,129 @@ +# JND space for dichromat + + Code + jnd_x + Output + x + Goodenia_heterophylla 6.98369053 + Goodenia_geniculata -1.45997294 + Goodenia_gracilis -22.34338359 + Xyris_operculata 3.11283493 + Eucalyptus_sp 3.46473171 + Faradaya_splendida -2.33062092 + Gaultheria_hispida 4.72952144 + Geitonoplesium_cymosum 2.46663805 + Euryomyrtus_ramosissima 0.58130781 + Genista_linifolia -0.07539070 + Genista_monspessulana 1.38400959 + Geranium_sp 6.69750041 + Glycine_clandestina 0.66799975 + Gompholobium_ecostatum_1 4.32203875 + Gompholobium_ecostatum_2 -0.09562108 + Gompholobium_grandiflorum -8.14561399 + Gompholobium_huegelii 4.25424086 + Gompholobium_virgatum 4.39580028 + Gonocarpus_humilis 2.34104837 + Gonocarpus_teucrioides 1.90381923 + Hibbertia_obtusifolia -0.59574803 + Zieria_arborescens -1.97634591 + Goodenia_lanata -13.23191155 + Goodenia_ovata -0.23345509 + Goodenia_rotundifolia 8.28959951 + Grevillea_buxifolia 5.29685040 + Grevillea_steiglitziana -8.04880987 + Grevillea_oleoides 0.61375449 + Gymnostachys_anceps -17.24608243 + Hakea_actites 7.59808360 + Hardenbergia_violaceae -4.00015785 + Hibbertia_acicularis 3.10619660 + Hibbertia_bracteata 7.27905645 + Hibbertia_empetrifolia -0.98725246 + Hibbertia_procumbens 2.66926650 + Hibbertia_linearis -1.38762284 + +# JND space for trichromat + + Code + jnd_xy + Output + x y + Goodenia_heterophylla -5.8139336 -3.8104493 + Goodenia_geniculata 7.1499498 -1.7123766 + Goodenia_gracilis 25.7768653 9.4103644 + Xyris_operculata 4.7321625 -5.5785095 + Eucalyptus_sp -1.0415170 -2.5698479 + Faradaya_splendida 3.3043499 1.0955158 + Gaultheria_hispida 2.6858502 -5.8029217 + Geitonoplesium_cymosum -9.6761678 -6.6471800 + Euryomyrtus_ramosissima -4.3479914 1.9961234 + Genista_linifolia 4.2630936 -1.6089380 + Genista_monspessulana 4.5300608 -3.1836422 + Geranium_sp -21.1570067 1.9121661 + Glycine_clandestina 5.7640601 -3.0969398 + Gompholobium_ecostatum_1 -8.9311597 -0.2066356 + Gompholobium_ecostatum_2 8.8641700 -3.8045102 + Gompholobium_grandiflorum 11.6625064 3.0647146 + Gompholobium_huegelii -6.9074732 -0.7750245 + Gompholobium_virgatum -8.4654418 -0.2941027 + Gonocarpus_humilis 5.3370839 -4.4953444 + Gonocarpus_teucrioides -0.9286454 -1.1307096 + Hibbertia_obtusifolia 1.5441127 0.1394303 + Zieria_arborescens -15.1001300 10.1503656 + Goodenia_lanata 19.9820873 4.2490206 + Goodenia_ovata -16.8819036 8.8572191 + Goodenia_rotundifolia -6.1698619 -4.9955380 + Grevillea_buxifolia 0.2018946 -5.2391734 + Grevillea_steiglitziana 0.3340598 8.7444919 + Grevillea_oleoides 4.4013554 -2.4093187 + Gymnostachys_anceps 11.9188189 11.7352668 + Hakea_actites -8.1559042 -3.2308351 + Hardenbergia_violaceae 3.5062933 2.6158679 + Hibbertia_acicularis -2.0367621 -1.7502035 + Hibbertia_bracteata -4.8211507 -5.4300211 + Hibbertia_empetrifolia -15.3914244 9.1550134 + Hibbertia_procumbens 2.7498869 -3.5956816 + Hibbertia_linearis 7.1178120 -1.7576563 + +# JND space for tetrachromat + + Code + jnd_xyz + Output + x y z + Goodenia_heterophylla 1.312355137 -5.3667601 6.8629524 + Goodenia_geniculata -0.648798700 -2.5312331 -6.5456726 + Goodenia_gracilis -4.834850372 10.6831212 -22.9236622 + Xyris_operculata 3.150779009 -1.0781817 -2.8997962 + Eucalyptus_sp -0.082973918 -3.1963203 3.1550303 + Faradaya_splendida -1.266831951 0.4892355 -2.8528294 + Gaultheria_hispida 2.274592892 -3.9525120 -1.1742262 + Geitonoplesium_cymosum 8.033650770 -6.9198494 8.2932612 + Euryomyrtus_ramosissima -2.010687966 -0.3710342 4.6922247 + Genista_linifolia -0.617218669 -1.7069294 -2.1501789 + Genista_monspessulana -0.202733928 -3.0304197 -2.4820412 + Geranium_sp 7.705016804 6.7723067 10.8297259 + Glycine_clandestina -0.172096284 -2.6365121 -4.2701064 + Gompholobium_ecostatum_1 2.342604074 0.1315023 5.5688334 + Gompholobium_ecostatum_2 -0.394030123 -2.0067259 -5.3306567 + Gompholobium_grandiflorum -3.043177182 4.4548815 -6.5433920 + Gompholobium_huegelii 0.731726587 -1.7597445 6.1230907 + Gompholobium_virgatum 1.595663823 -1.1755990 5.9025137 + Gonocarpus_humilis 0.047486608 -3.7116414 -2.6939291 + Gonocarpus_teucrioides -0.143737261 -2.1236747 2.1280934 + Hibbertia_obtusifolia -0.546715949 -1.3648630 -2.0026397 + Zieria_arborescens -4.374219169 8.9888446 8.7021306 + Goodenia_lanata -4.221201078 7.4641726 -12.6997701 + Goodenia_ovata -3.131626826 10.5294641 9.6861976 + Goodenia_rotundifolia 2.743882379 -6.2826784 6.1909786 + Grevillea_buxifolia 2.422158828 -3.4693196 1.9123426 + Grevillea_steiglitziana -4.435969376 5.1580526 -1.1327863 + Grevillea_oleoides -0.165755432 -3.0178116 -4.1570956 + Gymnostachys_anceps -4.457785440 9.9350339 -9.8694685 + Hakea_actites 1.020732338 -6.3835620 8.4297774 + Hardenbergia_violaceae -1.543741054 0.4977253 -3.4332417 + Hibbertia_acicularis -0.009957462 -3.4147937 1.9458170 + Hibbertia_bracteata 7.213297113 -2.2921695 1.6605064 + Hibbertia_empetrifolia -3.739762049 8.0698186 8.8247528 + Hibbertia_procumbens 0.056155445 -3.3090457 -0.3154626 + Hibbertia_linearis -0.606231617 -2.0727778 -7.4312733 + diff --git a/tests/testthat/test-jnd2xyz.R b/tests/testthat/test-jnd2xyz.R new file mode 100644 index 00000000..6766022a --- /dev/null +++ b/tests/testthat/test-jnd2xyz.R @@ -0,0 +1,58 @@ +data(flowers) + +test_that("JND space for dichromat", { + + canis.flowers <- vismodel(flowers, visual = "canis") + cd.flowers <- coldist(canis.flowers, n = c(1,1)) + + jnd_x <- jnd2xyz(cd.flowers) + + expect_snapshot(jnd_x) + + # After conversion to coordinates, the distance should not be modified + expect_equal( + as.matrix(dist(jnd_x, diag = TRUE, upper = TRUE)), + coldist2mat(cd.flowers)[["dS"]] + ) + + # Rotate has no effect in 2D + expect_identical( + jnd2xyz(cd.flowers), + jnd2xyz(cd.flowers, rotate = FALSE) + ) + +}) + +test_that("JND space for trichromat", { + + apis.flowers <- vismodel(flowers, visual = "apis") + cd.flowers <- coldist(apis.flowers, n = c(1,1,1)) + + jnd_xy <- jnd2xyz(cd.flowers) + + expect_snapshot(jnd_xy) + + # After conversion to coordinates, the distance should not be modified + expect_equal( + as.matrix(dist(jnd_xy, diag = TRUE, upper = TRUE)), + coldist2mat(cd.flowers)[["dS"]] + ) + +}) + +test_that("JND space for tetrachromat", { + + bluetit.flowers <- vismodel(flowers, visual = "bluetit") + cd.flowers <- coldist(bluetit.flowers) + + jnd_xyz <- jnd2xyz(cd.flowers) + + expect_snapshot(jnd_xyz) + + # After conversion to coordinates, the distance should not be modified + expect_equal( + as.matrix(dist(jnd_xyz, diag = TRUE, upper = TRUE)), + coldist2mat(cd.flowers)[["dS"]] + ) + +})