tests/match.R

library(flint)

n <- 10L
x. <- seq_len(n); y. <- rev(x.); z. <- integer(length(x.))
b. <- c(2L, 5L, 8L)

g1 <- expand.grid(rightmost.closed = c(FALSE, TRUE),
                  all.inside = c(FALSE, TRUE),
                  left.open = c(FALSE, TRUE))
g2 <- g1 |>
    transform(include.lowest = rightmost.closed,
              right = left.open) |>
    subset(!all.inside, c(include.lowest, right))

f1 <- lapply(.mapply(findInterval, g1, list(x = x., vec = b.)),
             as, "ulong")
f2 <- f1[!g1$all.inside]

for (.cl in c("ulong", "slong", "fmpz", "fmpq", "mag", "arf", "acf",
              "arb", "acb")) {
    x <- new(.cl, x = x.); y <- new(.cl, x = y.); z <- new(.cl, x = z.)
    stopifnot(identical(mtfrm(x), format(x, base = 62L, digits = 0L)),
              identical(match(x, x, 0L), x.),
              identical(match(x, y, 0L), y.),
              identical(match(x, z, 0L), z.),
              identical(anyDuplicated(x), 0L),
              identical(anyDuplicated(x, fromLast = TRUE), 0L),
              identical(anyDuplicated(z), 2L),
              identical(anyDuplicated(z, fromLast = TRUE), n - 1L),
              identical(anyDuplicated(z, incomparables = 0L), 0L),
              identical(duplicated(x), logical(n)),
              identical(duplicated(x, fromLast = TRUE), logical(n)),
              identical(duplicated(z), !replace(logical(n), 1L, TRUE)),
              identical(duplicated(z, fromLast = TRUE), !replace(logical(n), n, TRUE)),
              identical(duplicated(z, incomparables = 0L), logical(n)),
              flintIdentical(unique(x), x),
              flintIdentical(unique(z), z[1L]),
              flintIdentical(unique(z, incomparables = 0L), z))
    switch(.cl,
           "acf" =, "arb" =, "acb" = NULL,
           {
               b <- new(.cl, x = b.)
               stopifnot(all(mapply(flintIdentical, f1, .mapply(findInterval, g1, list(x = x,    vec = b)))),
                         all(mapply(flintIdentical, f2, .mapply(         cut, g2, list(x = x, breaks = b)))))
           })
}

Try the flint package in your browser

Any scripts or data that you put into this service are public.

flint documentation built on June 8, 2025, 1:27 p.m.