diff --git a/DESCRIPTION b/DESCRIPTION index 2d1a9a5..4eec4ce 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: ggpp Type: Package Title: Grammar Extensions to 'ggplot2' Version: 0.5.6.9001 -Date: 2024-03-04 +Date: 2024-04-18 Authors@R: c( person("Pedro J.", "Aphalo", email = "pedro.aphalo@helsinki.fi", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-3385-972X")), diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf index c9a5d03..f18ce1a 100644 Binary files a/tests/testthat/Rplots.pdf and b/tests/testthat/Rplots.pdf differ diff --git a/tests/testthat/test-compute_npc.R b/tests/testthat/test-compute_npc.R new file mode 100644 index 0000000..0ada33b --- /dev/null +++ b/tests/testthat/test-compute_npc.R @@ -0,0 +1,39 @@ +context("compute_npc") + +test_that("character input value returns correct numeric value", { + expect_equal(compute_npc("right"), 0.95) + expect_equal(compute_npc("left"), 0.05) + expect_equal(compute_npc(c("left", "right")), c(0.05, 0.95)) + expect_equal(compute_npc("centre"), 0.5) + expect_equal(compute_npc("center"), 0.5) + expect_equal(compute_npc("middle"), 0.5) + expect_equal(compute_npc("bottom"), 0.05) + expect_equal(compute_npc("top"), 0.95) +}) + +test_that("factor input values returns correct numeric value", { + x <- factor(c("right", "left")) + expect_equal(compute_npc(x), c(0.95, 0.05)) + +}) + +test_that("numeric input value returns the same value if + between 0 and 1", { + x <- c(0.5, 1) + expect_equal(compute_npc(x), x) +}) + +test_that("numeric input value + returns 0 if less than 0, + returns 1 if greater than 1", { + x <- c(-0.5, 2) + expect_equal(compute_npc(x), c(0,1)) + }) + +test_that("Value is returned 'AsIs'", { + expect_is(as_npc("right"), "AsIs") + expect_equal(as_npc("right"), I(0.95)) + expect_equal(as_npc("left"), I(0.05)) + expect_equal(as_npc("centre"), I(0.5)) + expect_equal(as_npc("center"), I(0.5)) +}) diff --git a/tests/testthat/test-compute_npcx.R b/tests/testthat/test-compute_npcx.R index 0be8df8..4d453c0 100644 --- a/tests/testthat/test-compute_npcx.R +++ b/tests/testthat/test-compute_npcx.R @@ -28,3 +28,11 @@ test_that("numeric input value x <- c(-0.5, 2) expect_equal(compute_npcx(x), c(0,1)) }) + +test_that("Value is returned 'AsIs'", { + expect_is(as_npcx("right"), "AsIs") + expect_equal(as_npcx("right"), I(0.95)) + expect_equal(as_npcx("left"), I(0.05)) + expect_equal(as_npcx("centre"), I(0.5)) + expect_equal(as_npcx("center"), I(0.5)) +}) diff --git a/tests/testthat/test-compute_npcy.R b/tests/testthat/test-compute_npcy.R index 676ae68..83d3e1b 100644 --- a/tests/testthat/test-compute_npcy.R +++ b/tests/testthat/test-compute_npcy.R @@ -29,3 +29,12 @@ test_that("numeric input values expect_equal(compute_npcy(y), c(0,1)) }) +test_that("Value is returned 'AsIs'", { + expect_is(as_npcy("top"), "AsIs") + expect_equal(as_npcy("top"), I(0.95)) + expect_equal(as_npcy("bottom"), I(0.05)) + expect_equal(as_npcy("middle"), I(0.5)) + expect_equal(as_npcx("center"), I(0.5)) + expect_equal(as_npcx("centre"), I(0.5)) +}) + diff --git a/tests/testthat/test-geom-text.R b/tests/testthat/test-geom-text.R index c3b3711..881e61e 100644 --- a/tests/testthat/test-geom-text.R +++ b/tests/testthat/test-geom-text.R @@ -25,5 +25,24 @@ test_that("multiple_rows_tb", { geom_text_npc(data = df, mapping = aes(npcx = x, npcy = y, label = to.parse), parse = TRUE)) + expect_error( + ggplot(data = mtcars) + + geom_point(mapping = aes(wt, mpg)) + + geom_text_npc(data = df, + mapping = aes(npcx = x, npcy = y, label = to.parse), + parse = TRUE, + nudge_y = 0.1, + position = "stack") + ) + + expect_no_error( + ggplot(data = mtcars) + + geom_point(mapping = aes(wt, mpg)) + + geom_text_npc(data = df, + mapping = aes(npcx = x, npcy = y, label = to.parse), + parse = TRUE, + nudge_x = 0.1, + position = "identity") + ) })