Skip to content

Commit

Permalink
Still more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbosak01 committed Oct 29, 2023
1 parent 02d061c commit f7a326e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
20 changes: 10 additions & 10 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -550,22 +550,22 @@ split_strings <- function(strng, width, units, multiplier = 1.03) {

strwdth <- Vectorize(function(wrd, un) {

if (is.na(wrd)) {
ret <- 0
} else {

ret <- strwidth("a", units = un) * nchar(wrd)

}
if (is.na(wrd)) {
ret <- 0
} else {

tryCatch({
ret <- tryCatch({

ret <- suppressWarnings(strwidth(wrd, units = un))
suppressWarnings(strwidth(wrd, units = un))



}, error = function(cond) {


suppressWarnings(strwidth("a", units = un)) * nchar(wrd)

})
}

return(ret)
}, USE.NAMES = FALSE, SIMPLIFY = TRUE)
Expand Down
35 changes: 22 additions & 13 deletions tests/testthat/test-utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -663,14 +663,14 @@ test_that("utils31: strwdth() works as expected.", {



pdf(NULL)
par(family = 'mono', ps = 10)

res <- strwdth(strngs, un = "inches")

dev.off()
# pdf(NULL)
# par(family = 'mono', ps = 10)
#
# res <- strwidth(strngs, un = "inches")
#
# dev.off()

res
res <- c(0.4166667, 0.5833333, 1.5000000)



Expand All @@ -683,24 +683,33 @@ test_that("utils31: strwdth() works as expected.", {

res1

expect_equal(all(res == res1), TRUE)
expect_equal(all(res == round(res1, 7)), TRUE)


# pdf(NULL)
# par(family = 'sans', ps = 10)
#
# res3 <- strwidth(strngs, un = "inches")
#
# dev.off()

res3 <- c(0.2933333, 0.5272222, 1.1733333)

pdf(NULL)
par(family = 'sans', ps = 10)

res2 <- strwdth(strngs, un = "inches")
res4 <- strwdth(strngs, un = "inches")

dev.off()

res2
res4

# print(res1)
# print(res2)

expect_equal(all(res1 != res2) , TRUE)


expect_equal(all(res != res4), TRUE)
expect_equal(res3[1] == round(res4[1], 7), TRUE)
expect_equal(res3[2] == round(res4[2], 7), TRUE)

})

Expand Down

0 comments on commit f7a326e

Please sign in to comment.