Skip to content

Commit

Permalink
Update tests for 1-based indices
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed May 28, 2018
1 parent a5ca72e commit 366b600
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tests/testthat/test-arrange.r
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ test_that("arrange keeps the grouping structure (#605)", {
res <- dat %>% group_by(g) %>% arrange(x)
expect_is(res, "grouped_df")
expect_equal(res$x, 1:4)
expect_equal(group_rows(res), list(c(1, 3), c(0, 2)))
expect_equal(group_rows(res), list(c(2, 4), c(1, 3)))
})

test_that("arrange handles complex vectors", {
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-group_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ context("group_data")

test_that("group_rows works for 3 most important subclasses (#3489)", {
df <- data.frame(x=c(1,1,2,2))
expect_equal(group_rows(df), list(0:3))
expect_equal(group_rows(group_by(df,x)), list(0:1, 2:3))
expect_equal(group_rows(rowwise(df)), as.list(0:3))
expect_equal(group_rows(df), list(1:4))
expect_equal(group_rows(group_by(df,x)), list(1:2, 3:4))
expect_equal(group_rows(rowwise(df)), as.list(1:4))
})

test_that("group_data returns a tidy tibble (#3489)", {
df <- tibble(x = c(1,1,2,2))

expect_identical(
group_data(df),
tibble(.rows=list(0:3))
tibble(.rows=list(1:4))
)

expect_identical(
group_by(df,x) %>% group_data(),
tibble(x = c(1,2), .rows = list(0:1, 2:3))
tibble(x = c(1,2), .rows = list(1:2, 3:4))
)

expect_identical(
rowwise(df) %>% group_data(),
tibble(.rows = as.list(0:3))
tibble(.rows = as.list(1:4))
)
})

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-sets.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ test_that("set operations reconstruct grouping metadata (#3587)", {
df1 <- tibble(x = 1:4, g = rep(1:2, each = 2)) %>% group_by(g)
df2 <- tibble(x = 3:6, g = rep(2:3, each = 2))

expect_equal( setdiff(df1, df2) %>% group_rows(), list(0:1))
expect_equal( intersect(df1, df2) %>% group_rows(), list(0:1))
expect_equal( union(df1, df2) %>% group_rows(), list(4:5, 2:3, 0:1))
expect_equal( setdiff(df1, df2) %>% group_rows(), list(1:2))
expect_equal( intersect(df1, df2) %>% group_rows(), list(1:2))
expect_equal( union(df1, df2) %>% group_rows(), list(5:6, 3:4, 1:2))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-slice.r
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ test_that("slice works fine if n > nrow(df) (#1269)", {
test_that("slice strips grouped indices (#1405)", {
res <- mtcars %>% group_by(cyl) %>% slice(1) %>% mutate(mpgplus = mpg + 1)
expect_equal(nrow(res), 3L)
expect_equal(group_rows(res), as.list(0:2))
expect_equal(group_rows(res), as.list(1:3))
})

test_that("slice works with zero-column data frames (#2490)", {
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-summarise.r
Original file line number Diff line number Diff line change
Expand Up @@ -1057,5 +1057,4 @@ test_that("hybrid sum handles NA correctly (#3528)",{
expect_equal( summarise(d, x = sum(x, na.rm = TRUE)), tibble(x = 1L))
expect_equal( summarise(d, x = sum(x, na.rm = FALSE)), tibble(x = NA_integer_))
expect_equal( summarise(d, x = sum(x)), tibble(x = NA_integer_))

})

0 comments on commit 366b600

Please sign in to comment.