Skip to content

Commit

Permalink
Can't count on the second axis to be in the second spot of the list.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldecicco-USGS committed Mar 27, 2017
1 parent 775c0e2 commit 102876a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tests/testthat/tests-date_axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_that("two axis calls added to side 1", {

test_that("axis ticks in the right location", {
gs <- gsplot() %>%
points(seq(as.Date("2013-01-01"), as.Date("2013-12-31"), "days"), 1:31) %>%
points(seq(as.Date("2013-01-01"), as.Date("2013-12-31"), "days"), 1:365) %>%
date_axis(side=1, lab.pos = "interval", tick.int="month", "snap.to"="month")

ticks <- lazy_eval(gs$side.1$axis$at, data=list(object=gs))
Expand All @@ -24,7 +24,9 @@ test_that("axis labels centered on interval", {
points(seq(as.Date("2013-01-01"), as.Date("2013-12-31"), "days"), 1:365) %>%
date_axis(side=1, lab.pos = "interval", tick.int="month", "snap.to"="month")

labels <- lazyeval::lazy_eval(gs$side.1[[2]]$at, data=list(object=gs))
second.axis <- gs$side.1
which.axis <- which(names(second.axis)== 'axis')
labels <- lazyeval::lazy_eval(gs$side.1[[which.axis[2]]]$at, data=list(object=gs))
expect_true(all.equal(labels[1], as.Date("2013-01-15"), tolerance=0.01))
expect_true(all.equal(labels[7], as.Date("2013-07-15"), tolerance=0.01))
expect_true(all.equal(labels[12], as.Date("2013-12-15"), tolerance=0.01))
Expand All @@ -35,7 +37,10 @@ test_that("axis labels centered on ticks", {
points(seq(as.Date("2013-01-01"), as.Date("2013-01-31"), "days"), 1:31) %>%
date_axis(side=1, lab.pos = "tick", tick.int="day", "snap.to"="month")

labels <- lazy_eval(gs$side.1[[2]]$at, data=list(object=gs))
second.axis <- gs$side.1
which.axis <- which(names(second.axis)== 'axis')

labels <- lazy_eval(gs$side.1[[which.axis[2]]]$at, data=list(object=gs))
expect_equal(labels[1], as.Date("2013-01-01"))
expect_equal(labels[7], as.Date("2013-01-07"))
expect_equal(labels[22], as.Date("2013-01-22"))
Expand Down

0 comments on commit 102876a

Please sign in to comment.