Skip to content

Commit

Permalink
Focus tests on rotation for now
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisaloo committed Oct 25, 2024
1 parent 615dc7c commit 33dbddb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 39 deletions.
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/jnd2xyz.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# JND space for dichromat

Code
jnd_x
jnd_x_rot
Output
x
Goodenia_heterophylla 6.98369053
Expand Down Expand Up @@ -44,7 +44,7 @@
# JND space for trichromat

Code
jnd_xy
jnd_xy_rot
Output
x y
Goodenia_heterophylla 6.3480194 -2.8326663
Expand Down Expand Up @@ -87,7 +87,7 @@
# JND space for tetrachromat

Code
jnd_xyz
jnd_xyz_rot
Output
x y z
Goodenia_heterophylla 1.312355137 -5.3667601 6.8629524
Expand Down
55 changes: 19 additions & 36 deletions tests/testthat/test-jnd2xyz.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@ 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"]]
)

# Including after rotation
jnd_x <- jnd2xyz(cd.flowers, rotate = TRUE)
jnd_x_rot <- jnd2xyz(cd.flowers, rotate = TRUE)

expect_snapshot(jnd_x)
expect_snapshot(jnd_x_rot)

# Rotation doesn't change the distances
expect_equal(
as.matrix(dist(jnd_x, diag = TRUE, upper = TRUE)),
coldist2mat(cd.flowers)[["dS"]]
dist(jnd_x),
dist(jnd_x_rot),
ignore_attr = "call"
)

})
Expand All @@ -32,46 +27,34 @@ 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(
as.matrix(dist(jnd_xy, diag = TRUE, upper = TRUE)),
coldist2mat(cd.flowers)[["dS"]]
)

# Including after rotation
jnd_xy <- jnd2xyz(cd.flowers, rotate = TRUE)
jnd_xy_rot <- jnd2xyz(cd.flowers, rotate = TRUE)

expect_snapshot(jnd_xy)
expect_snapshot(jnd_xy_rot)

# Rotation doesn't change the distances
expect_equal(
as.matrix(dist(jnd_xy, diag = TRUE, upper = TRUE)),
coldist2mat(cd.flowers)[["dS"]]
dist(jnd_xy),
dist(jnd_xy_rot),
ignore_attr = "call"
)


})

test_that("JND space for tetrachromat", {

bluetit.flowers <- vismodel(flowers, visual = "bluetit")
cd.flowers <- coldist(bluetit.flowers)

jnd_xyz <- jnd2xyz(cd.flowers)
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"]]
)
jnd_xyz_rot <- jnd2xyz(cd.flowers, rotate = TRUE)

# Including after rotation
jnd_xyz <- jnd2xyz(cd.flowers, rotate = TRUE)

expect_snapshot(jnd_xyz)
expect_snapshot(jnd_xyz_rot)

# Rotation doesn't change the distances
expect_equal(
as.matrix(dist(jnd_xyz, diag = TRUE, upper = TRUE)),
coldist2mat(cd.flowers)[["dS"]]
dist(jnd_xyz),
dist(jnd_xyz_rot),
ignore_attr = "call"
)

})

0 comments on commit 33dbddb

Please sign in to comment.