Skip to content

Commit

Permalink
Merge pull request #69 from katilingban/dev
Browse files Browse the repository at this point in the history
add utils functions tests
  • Loading branch information
ernestguevarra authored Mar 12, 2024
2 parents f2c2998 + 404ffdc commit c2b1462
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
1 change: 1 addition & 0 deletions R/theme_acdc.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ theme_acdc_dark <- function(base_family = set_acdc_font(),
ticks = FALSE) {
theme_paleta(
base_family = base_family,
base_size = base_size,
plot_title_family = plot_title_family,
plot_title_colour = plot_title_colour,
subtitle_family = subtitle_family,
Expand Down
28 changes: 20 additions & 8 deletions R/theme_paleta.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,21 @@ theme_paleta <- function(base_family = set_paleta_font(),
if (inherits(grid, "character") | grid == TRUE) {
design <- design +
ggplot2::theme(
panel.grid = ggplot2::element_line(colour = grid_col, size = 0.2)
panel.grid = ggplot2::element_line(colour = grid_col, linewidth = 0.2)
)

design <- design +
ggplot2::theme(
panel.grid.major = ggplot2::element_line(colour = grid_col, size = 0.2)
panel.grid.major = ggplot2::element_line(
colour = grid_col, linewidth = 0.2
)
)

design <- design +
ggplot2::theme(
panel.grid.minor = ggplot2::element_line(colour = grid_col, size = 0.05)
panel.grid.minor = ggplot2::element_line(
colour = grid_col, linewidth = 0.05
)
)

if (inherits(grid, "character")) {
Expand Down Expand Up @@ -234,7 +238,7 @@ theme_paleta <- function(base_family = set_paleta_font(),
if (inherits(axis, "character") | axis == TRUE) {
design <- design +
ggplot2::theme(
axis.line = ggplot2::element_line(colour = axis_col, size = 0.15)
axis.line = ggplot2::element_line(colour = axis_col, linewidth = 0.15)
)

if (inherits(axis, "character")) {
Expand All @@ -246,7 +250,9 @@ theme_paleta <- function(base_family = set_paleta_font(),
} else {
design <- design +
ggplot2::theme(
axis.line.x = ggplot2::element_line(colour = axis_col, size = 0.15)
axis.line.x = ggplot2::element_line(
colour = axis_col, linewidth = 0.15
)
)
}

Expand All @@ -256,18 +262,24 @@ theme_paleta <- function(base_family = set_paleta_font(),
} else {
design <- design +
ggplot2::theme(
axis.line.y = ggplot2::element_line(colour = axis_col, size = 0.15)
axis.line.y = ggplot2::element_line(
colour = axis_col, linedwidth = 0.15
)
)
}
} else {
design <- design +
ggplot2::theme(
axis.line.x = ggplot2::element_line(colour = axis_col, size = 0.15)
axis.line.x = ggplot2::element_line(
colour = axis_col, linewidth = 0.15
)
)

design <- design +
ggplot2::theme(
axis.line.y = ggplot2::element_line(colour = axis_col, size = 0.15)
axis.line.y = ggplot2::element_line(
colour = axis_col, linewidth = 0.15
)
)
}
} else {
Expand Down
25 changes: 22 additions & 3 deletions tests/testthat/test-theme_paleta.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
# Test paleta ------------------------------------------------------------------

## Test paleta_fonts class
library(ggplot2)

## scatterplot
p <- ggplot(data = mtcars, mapping = aes(x = mpg, y = disp, colour = factor(cyl))) +
geom_point(size = 3) +
scale_colour_manual(
name = "Cylinders",
values = acdc_palettes$acdc_secondary
) +
labs(
title = "Light ACDC Theme",
subtitle = "Using the Africa CDC secondary palette",
)

## Test paleta_fonts class ----
testthat::expect_type(paleta_fonts, "list")

## Test length of paleta fonts
## Test length of paleta fonts ----
testthat::expect_equal(length(paleta_fonts), 3)

## Test output of set_paleta_font
## Test output of set_paleta_font ----
testthat::expect_type(set_paleta_font(), "character")
testthat::expect_equal(length(set_paleta_font()), 1)

## test theme_paleta() ----
testthat::expect_silent(p + theme_paleta())




10 changes: 10 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Tests for utility functions --------------------------------------------------

## Test print function ----
testthat::expect_silent(print(structure(acdc_palettes$acdc_primary, class = "palette")))

## Test get colours function ----
testthat::expect_equal(get_colours() |> length(), nrow(paleta_colours))
testthat::expect_equal(get_colour() |> length(), nrow(paleta_colours))
testthat::expect_type(get_colour(pattern = "Blue", named = TRUE), "character")
testthat::expect_gt(
get_colour(pattern = "Blue", named = TRUE) |> names() |> length(),
0
)
testthat::expect_type(get_colours(pattern = "Blue"), "character")
testthat::expect_type(get_colours(pattern = "Blue", named = TRUE), "character")

Expand Down

0 comments on commit c2b1462

Please sign in to comment.