Skip to content

Commit

Permalink
Add tests to ensure jnd2xyz() preserves distances
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisaloo committed Feb 7, 2025
1 parent 3ba158b commit bbfab5b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/testthat/test-jnd2xyz.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ test_that("JND space for dichromat", {

jnd_x <- jnd2xyz(cd.flowers, rotate = FALSE)

# 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"]],
tolerance = 1e-6
)

jnd_x_rot <- jnd2xyz(cd.flowers, rotate = TRUE)

expect_snapshot(jnd_x_rot)
Expand All @@ -27,6 +34,12 @@ test_that("JND space for trichromat", {

jnd_xy <- jnd2xyz(cd.flowers, rotate = FALSE)

# After conversion to coordinates, the distance should not be modified
expect_equal(

Check warning on line 38 in tests/testthat/test-jnd2xyz.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=tests/testthat/test-jnd2xyz.R,line=38,col=3,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=.
as.matrix(dist(jnd_xy, diag = TRUE, upper = TRUE)),
coldist2mat(cd.flowers)[["dS"]]
)

jnd_xy_rot <- jnd2xyz(cd.flowers, rotate = TRUE)

expect_snapshot(jnd_xy_rot)
Expand All @@ -47,6 +60,13 @@ test_that("JND space for tetrachromat", {

jnd_xyz <- jnd2xyz(cd.flowers, rotate = FALSE)

# 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"]],
tolerance = 1e-6
)

jnd_xyz_rot <- jnd2xyz(cd.flowers, rotate = TRUE)

expect_snapshot(jnd_xyz_rot)
Expand Down

0 comments on commit bbfab5b

Please sign in to comment.