Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More coverage tests #60

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions tests/testthat/test-highlevel64.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,70 @@ test_that("match & %in% basics work", {
expect_identical(x %in% c(3.0, 4.0, 5.0, 6.0), c(FALSE, TRUE, TRUE, TRUE))
})

test_that("Different method= for match() and %in% work", {
x = as.integer64(2:5)
y = as.integer64(3:6)
expected = c(NA_integer_, 1:3)

expect_identical(match(x, y, method="hashpos"), expected)
expect_identical(match(x, y, method="hashrev"), expected)
expect_identical(match(x, y, method="sortorderpos"), expected)
# TODO(#58): Fix this, currently fails.
# expect_identical(match(x, y, method="orderpos"), expected)

# NB: %in% is quite a bit different; while there's a public API to
# `%in%.integer64`, likely, there shouldn't be (it's strange to export
# an S3 method like is currently done). The tests are designed to tickle
# the different methods through the public API only; this makes them
# prone to winding up testing something totally different later. I think
# that's fine; now that we have coverage tests up, any refactor that bumps
# around what exactly the following tests are covering, will show up in the PR.

# method="hashrin" used when x is "short" but table is "long"
x = as.integer64(seq_len(10L))
table = as.integer64(seq_len(2.0**16.0 * 2.0/3.0 + 10.0)) # invert condition for bx>=16, 10.0 arbitrary buffer
expect_identical(x %in% table, rep(TRUE, 10L))
})

# TODO(#59): Don't call table.integer64() directly.
test_that("duplicated, unique, table methods work", {
x = as.integer64(1:3)
expect_identical(duplicated(x), rep(FALSE, 3L))
expect_identical(unique(x), x)
expect_identical(table(x), table(x = 1:3))
expect_identical(table.integer64(x), table(x = 1:3))

x = as.integer64(rep(1L, 3L))
expect_identical(duplicated(x), c(FALSE, TRUE, TRUE))
expect_identical(unique(x), x[1L])
expect_identical(table(x), table(x = rep(1L, 3L)))
expect_identical(table.integer64(x), table(x = rep(1L, 3L)))

x = as.integer64(c(1L, 2L, 1L))
expect_identical(duplicated(x), c(FALSE, FALSE, TRUE))
expect_identical(unique(x), x[1:2])
expect_identical(table(x), table(x = c(1L, 2L, 1L)))
expect_identical(table.integer64(x), table(x = c(1L, 2L, 1L)))

x = as.integer64(c(1L, 1L, 2L))
expect_identical(duplicated(x), c(FALSE, TRUE, FALSE))
expect_identical(unique(x), x[c(1L, 3L)])
expect_identical(table(x), table(x = c(1L, 1L, 2L)))
expect_identical(table.integer64(x), table(x = c(1L, 1L, 2L)))
})

test_that("different method= for duplicated, unique work", {
x = as.integer64(c(1L, 2L, 1L))
exp_dup = c(FALSE, FALSE, TRUE)
exp_unq = x[1:2]

expect_identical(duplicated(x, method="hashdup"), exp_dup)
expect_identical(unique(x, method="hashmapuni"), exp_unq)
expect_identical(unique(x, method="hashuni"), exp_unq)

expect_identical(duplicated(x, method="sortorderdup"), exp_dup)
expect_identical(unique(x, method="sortorderuni"), exp_unq)
expect_identical(unique(x, method="sortuni"), exp_unq)

# TODO(#58): Fix this, currently fails.
# expect_identical(duplicated(x, method="orderdup"), exp_dup)
expect_identical(unique(x, method="orderuni"), exp_unq)
})

test_that("more coercion works", {
Expand Down
10 changes: 9 additions & 1 deletion tests/testthat/test-sort64.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
test_that("order basics work", {
expect_identical(order(as.integer64(c(2L, 4L, 3L))), c(1L, 3L, 2L))
x = as.integer64(c(2L, 4L, 3L))
expect_identical(order(x), c(1L, 3L, 2L))
expect_identical(order(x, decreasing=TRUE), c(2L, 3L, 1L))

x = c(x, NA_integer64_)
expect_identical(order(x), c(1L, 3L, 2L, 4L))
expect_identical(order(x, decreasing=TRUE), c(2L, 3L, 1L, 4L))
expect_identical(order(x, na.last=FALSE), c(4L, 1L, 3L, 2L))
expect_identical(order(x, na.last=FALSE, decreasing=TRUE), c(4L, 2L, 3L, 1L))
})
Loading