"expects valid input: relation_schemas is a relation_schema"
"expects valid input: unique schema names"
"expects valid input: non-empty schema names"
"expects valid input: reference attributes are within referrer's attributes, make one of referee's keys"
"returns the relation_schema, with the additional attributes unmodified"
"expects a database_schema value for subset re-assignment"
"^value must also be a database_schema object$"
"is made unique to a valid database schema"
"concatenates to a valid database schema"
"is composed of its attrs(), keys(), names(), attrs_order(), and references()"
"is composed of its subschemas() and references()"
"database schema with 0 relation schemas"
"database schema with 2 relation schemas"
"schema b: b, c\\n  key 1: b\\n  key 2: c"

database_schema: concatenates without losing attribute orderings, if consistent

Falsifiable after 1 tests, and 100 shrinks
<simpleError in expect_all_true(mapply(identical, lapply(lst, attrs_order), lapply(lst,     function(x) intersect(attrs_order(res), attrs_order(x))))): could not find function "expect_all_true">
Counterexample:
[[1]]
database schema with 0 relation schemas
0 attributes
no references

[[2]]
database schema with 0 relation schemas
2 attributes: b, f
no references

Falsifiable after 1 tests, and 0 shrinks
<simpleError in expect_all_true(mapply(identical, lapply(lst, attrs_order), lapply(lst,     function(x) intersect(attrs_order(res), attrs_order(x))))): could not find function "expect_all_true">
Counterexample:
[[1]]
0 functional dependencies
1 attribute: c

[[2]]
0 functional dependencies
1 attribute: d

gen.fd <- function(x, from, to, unique = TRUE) {
functional_dependency(lst[[1]], lst[[2]], unique = unique)
it("expects valid input: FD elements correct lengths, contain characters of valid lengths", {
"^FDs elements must have length two: element 1$"
"^FD determinant sets must be characters: element 1$"
"^FD dependants must be length-one characters: element 1$"
it("expects valid input: no duplicate determinants", {
functional_dependency(list(list(c("a", "a"), "b")), c("a", "b")),
"^attributes in determinant sets must be unique: element 1$"
it("expects valid input: all attributes given in attrs_order", {
"^attributes in FDs must be present in attrs_order: element 1$"
it("expects valid input: no duplicates in attrs_order", {
"^attrs_order must be unique: duplicated a$"
it("returns a set, i.e. no duplicated FD elements", {
it("orders attributes in each determinant set with respect to order in attrs_order", {
with_args(match, table = attrs_order(fds)) %>>%
"\\A1 functional dependency\\n2 attributes: a, b\\na -> b\\Z",
it("is subsetted to a valid functional dependency object, follows usual subsetting rules", {
gen.sample_resampleable(c(FALSE, TRUE), of = length(fd))
tryCatch(fd[[ineg]], error = function(e) e$message),
tryCatch(fd[[ints[[ineg]]]], error = function(e) e$message)
it("can be subsetted while preserving attributes", {
x <- functional_dependency(list(list("a", "b")), letters[1:5])
gen.fd(letters[1:6], 0, 8, unique = FALSE),
unique %>>% class %>>% with_args(expect_identical, "functional_dependency")
gen.fd(letters[1:6], 0, 8) |> gen.list(from = 1, to = 10),
it("concatenates with duplicates removed", {
it("concatenates without losing attributes", {
gen.with(sort %>>% with_args(functional_dependency, FDs = list())) |>
# sort determinant sets to keep test independent from that for
it("is composed of its detset() and dependant() outputs, with attrs_order() attribute", {
expect_no_error(tb <- data.frame(id = 1:2, fd = fds))
it("ignores attrs_order/header when comparing for equality", {
it("recycles when comparing for equality", {
expect_identical(fds == fds[1], c(TRUE, FALSE))
expect_true(all(c(fds, fds, unique = FALSE) == fds))