Skip to content

Commit

Permalink
Fixing tests for plot_scatter and checking EPV/xT calc (#94)
Browse files Browse the repository at this point in the history
Fixed plot_scatter tests by going through all the arguments.

Changes were made to calculate_epv() to fix EPV calculations

Closes Issue #44 and closes Issue #58
  • Loading branch information
abhiamishra authored Jul 12, 2022
1 parent 6bd6c75 commit 5856274
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 13 deletions.
22 changes: 11 additions & 11 deletions R/calculate_epv.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,41 +64,41 @@ calculate_epv <- function(data, type = "opta") {
row <- 0
col <- 0
if (a %% 2 == 0) {
if (b %% 3.225 == 0) {
if (b %% 3.125 == 0) {
col <- as.integer(a / 2)
row <- as.integer(b / 3.225)
row <- as.integer(b / 3.125)

} else {
col <- as.integer(a / 2)
if (as.integer(b / 3.225) + 1 > 31) {
row <- as.integer(b / 3.225)
if (as.integer(b / 3.125) + 1 > 32) {
row <- as.integer(b / 3.125)
} else {
row <- as.integer(b / 3.225) + 1
row <- as.integer(b / 3.125) + 1
}
}
} else {
if (b %% 3.225 == 0) {
if (b %% 3.125 == 0) {
if (as.integer(a / 2) + 1 > 50) {
col <- as.integer(a / 2)
} else {
col <- as.integer(a / 2) + 1
}
row <- as.integer(b / 3.225)
row <- as.integer(b / 3.125)
} else {
if (as.integer(a / 2) + 1 > 50) {
col <- as.integer(a / 2)
} else {
col <- as.integer(a / 2) + 1
}

if (as.integer(b / 3.225) + 1 > 31) {
row <- as.integer(b / 3.225)
if (as.integer(b / 3.125) + 1 > 32) {
row <- as.integer(b / 3.125)
} else {
row <- as.integer(b / 3.225) + 1
row <- as.integer(b / 3.125) + 1
}
}
}
return(EPVGrid[row, col])
return(EPVGrid[(33-row), col])
}

parsing$EPVStart <- mapply(assign_epv, parsing$x, parsing$y)
Expand Down
233 changes: 231 additions & 2 deletions tests/testthat/test_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test_that("Plotting scatterplots: ", {
x = "xA",
y = "yA",
set_size_var = "size_scat"
))
), "Please input a data.frame into the 'data' argument.")

# Testing for using wrong/nonexistent column names
p <- plot_scatter(
Expand All @@ -53,7 +53,236 @@ test_that("Plotting scatterplots: ", {
y = "y",
set_color_var = "col_scat",
set_size_var = "size_scat"
))
), "Please input columns for the 'x' and/or 'y' arguments.")

# testing for themes
p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
set_color_var = "col_scat",
set_size_var = "size_scat"
)
expect_true(is.ggplot(p)) # theme = dark (classic)

p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
set_color_var = "col_scat",
set_size_var = "size_scat",
theme = "minimal"
)
expect_true(is.ggplot(p)) # theme = minimal

p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
set_color_var = "col_scat",
set_size_var = "size_scat",
theme = "grey"
)
expect_true(is.ggplot(p)) # theme = grey

p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
set_color_var = "col_scat",
set_size_var = "size_scat",
theme = "bw"
)
expect_true(is.ggplot(p)) # theme = bw

# Testing captions
p <- plot_scatter(
data = df,
x = "xA",
y = "yA"
)
expect_true(is.ggplot(p)) # caption = "" (default)

p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
caption = "This is testing"
)
expect_true(is.ggplot(p)) # caption = "This is testing"
expect_identical(p$labels$caption, "This is testing")

# Testing caption size
p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
caption = "This is testing"
)
expect_true(is.ggplot(p)) # caption_size = 10 (default)

p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
caption = "This is testing",
caption_size = 40
)
expect_true(is.ggplot(p)) # caption_size = 40

# Testing subtitles
p <- plot_scatter(
data = df,
x = "xA",
y = "yA"
)
expect_true(is.ggplot(p)) # subtitle = "" (default)

p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
subtitle = "Made by ggshakeR"
)
expect_true(is.ggplot(p)) # subtitle = "Made by ggshakeR"
expect_identical(p$labels$subtitle, "Made by ggshakeR")

# testing subtitle size
p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
subtitle = "Made by ggshakeR"
)
expect_true(is.ggplot(p)) # subtitle_size = 15 (default)

p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
subtitle = "Made by ggshakeR",
subtitle_size = 25
)
expect_true(is.ggplot(p)) # subtitle_size = 25


# Testing titles
p <- plot_scatter(
data = df,
x = "xA",
y = "yA"
)
expect_true(is.ggplot(p)) # title = "" (default)

p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
title = "Plot One"
)
expect_true(is.ggplot(p)) # subtitle = "Plot One"
expect_identical(p$labels$title, "Plot One")

# testing title size
p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
title = "Made by ggshakeR"
)
expect_true(is.ggplot(p)) # title_size = 25 (default)

p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
title = "Made by ggshakeR",
title_size = 45
)
expect_true(is.ggplot(p)) # subtitle_size = 45

# testing coloring in scatter plot with constant color
p <- plot_scatter(
data = df,
x = "xA",
y = "yA"
)
expect_true(is.ggplot(p)) # set_color_num = "red" (default)

p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
set_color_num = "blue"
)
expect_true(is.ggplot(p)) # set_color_num = "blue" (default)

# testing coloring in scatter plot with different color
p <- plot_scatter(
data = df,
x = "xA",
y = "yA"
)
expect_true(is.ggplot(p)) # set_color_var = "" (default)

p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
set_color_var = "xA"
)
expect_true(is.ggplot(p)) # set_color_var = "xA"
expect_identical(p$labels$colour, "xA")

# testing sizing in scatter plot with constant size
p <- plot_scatter(
data = df,
x = "xA",
y = "yA"
)
expect_true(is.ggplot(p)) # set_size_num = 5 (default)

p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
set_size_num = 10
)
expect_true(is.ggplot(p)) # set_color_num = 10

# testing sizing in scatter plot with different size
p <- plot_scatter(
data = df,
x = "xA",
y = "yA"
)
expect_true(is.ggplot(p)) # set_size_var = "" (default)

p <- plot_scatter(
data = df,
x = "xA",
y = "yA",
set_size_var = "col_scat"
)
expect_true(is.ggplot(p)) # set_color_var = "col_scat"
expect_identical(p$labels$size, "col_scat")

# testing labels
p <- plot_scatter(
data = df,
x = "xA",
y = "yA"
)
expect_true(is.ggplot(p)) # label = "" (default)

p <- plot_scatter(
data = df %>% filter(xA <= 10),
x = "xA",
y = "yA",
label = "xA"
)
expect_true(is.ggplot(p)) # label = "xA"

})


Expand Down

0 comments on commit 5856274

Please sign in to comment.