tests/test-basic.R

library(sssp)

v <- c(10, -1, 2, 3, 9, 0, -4, -8, 7, 6)
res <- sssp_project(v, c(3, 4, 3), r = 3, s = 6)
stopifnot(identical(as.integer(res$info$tuple), as.integer(c(1, 2, 3))))
stopifnot(identical(as.numeric(res$info$n_tuples), 13))
stopifnot(abs(res$info$objective - 14) < 1e-9)

groups <- list(c(1, 4), c(2, 3, 5, 8, 9, 10), c(6, 7, 11, 12))
v2 <- c(4, -3, 5, 2, -6, 1, 7, -8, 0.5, 9, -2, 3)
res2 <- sssp_project(v2, groups, r = 2, s = 5)
stopifnot(length(res2$info$selected_groups) <= 2)
stopifnot(length(res2$info$selected_indices) <= 5)

A <- matrix(c(1, 0, 0, 1, 1, 1), nrow = 2)
b <- c(1, 2)
fit <- sssp_solve(A, b, c(1, 1, 1), r = 2, s = 2, max_iter = 5)
stopifnot(is.list(fit), length(fit$x) == 3)

Try the sssp package in your browser

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

sssp documentation built on Sept. 5, 2026, 5:08 p.m.