From fb8d97a300f9468b1b627746e546f90ff26ab874 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 9 Oct 2024 22:35:58 -0700 Subject: [PATCH] More coverage tests --- tests/testthat/test-highlevel64.R | 52 ++++++++++++++++++++++++++++--- tests/testthat/test-sort64.R | 10 +++++- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-highlevel64.R b/tests/testthat/test-highlevel64.R index f4b8739..05839fa 100644 --- a/tests/testthat/test-highlevel64.R +++ b/tests/testthat/test-highlevel64.R @@ -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", { diff --git a/tests/testthat/test-sort64.R b/tests/testthat/test-sort64.R index 0eda6f1..f378bdd 100644 --- a/tests/testthat/test-sort64.R +++ b/tests/testthat/test-sort64.R @@ -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)) })