Skip to content

Commit

Permalink
Add svmPoly test for ordering of facets' labels
Browse files Browse the repository at this point in the history
  • Loading branch information
m-dz committed Apr 12, 2017
1 parent 09c30cd commit 7967d20
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions pkg/caret/tests/testthat/test_ggplot.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
context("Test ggplot")

test_that("ggplot.train correctly orders factors", {
library(caret)
library(kernlab)
data(mtcars)
m <- train(mpg ~ cyl + disp,
data = mtcars,
method="svmRadial",
tuneGrid = expand.grid(C=1:2, sigma=c(0.0001, 0.01, 1)))
g <- ggplot(m, plotType="level")
m <- train(
mpg ~ cyl + disp,
data = mtcars,
method = "svmRadial",
tuneGrid = expand.grid(C = 1:2, sigma = c(0.0001, 0.01, 1))
)
g <- ggplot(m, plotType = "level")

# Test plot data
obj_sigma <- as.numeric(levels(g$data$sigma))
Expand All @@ -21,3 +25,37 @@ test_that("ggplot.train correctly orders factors", {
expect_equal(obj_x, sort(obj_x))
expect_equal(obj_y, sort(obj_y))
})

test_that("ggplot.train correctly orders facets' labels", {
library(caret)
library(kernlab)
data(mtcars)
m <- suppressWarnings(train(
mpg ~ cyl + disp,
data = mtcars,
method = "svmPoly",
tuneGrid = expand.grid(
degree = c(0.0001, 0.01, 1),
scale = c(0.0001, 0.01, 1),
C = c(0.0001, 0.01, 1)
)
))
g <- ggplot(m, plotType = "level", nameInStrip = TRUE)

# Test plot data
obj_C <- as.numeric(gsub(
'Cost: ',
'',
levels(g$data$C)
))
expect_equal(obj_C, sort(obj_C))

# Test axes' labels on a built plot
build <- ggplot2::ggplot_build(g)
obj_labels <- as.numeric(gsub(
'Cost: ',
'',
levels(build$layout$panel_layout$C)
))
expect_equal(obj_labels, sort(obj_labels))
})

0 comments on commit 7967d20

Please sign in to comment.