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

If and only if checks #76

Open
kinto-b opened this issue Jan 19, 2024 · 2 comments
Open

If and only if checks #76

kinto-b opened this issue Jan 19, 2024 · 2 comments
Labels
Effort: ⭐ Straightforward Task: Enhancement New feature or request

Comments

@kinto-b
Copy link
Contributor

kinto-b commented Jan 19, 2024

A relatively common formula is

expect_cond(foo, bar)
expect_cond(bar, foo)

This is a bit verbose, particularly so when foo and bar are complicated expressions. We should allow

expect_iff(foo, bar)

or something like

expect_cond(foo, bar, .cond="if")  # foo --> bar 
expect_cond(foo, bar, .cond="iff") # foo <-> bar
@kinto-b kinto-b added Task: Enhancement New feature or request Effort: ⭐ Straightforward labels Jan 19, 2024
@kinto-b
Copy link
Contributor Author

kinto-b commented Jan 19, 2024

Simplest implementation, but perhaps not the best due to generating up to two failures

expect_iff <- function(cond1, cond2, ...) {
  cond1 <- rlang::enquo(cond1)
  cond2 <- rlang::enquo(cond2)
  
  testdat::expect_cond(!!cond1, !!cond2, ...)
  testdat::expect_cond(!!cond2, !!cond1, ...)
}

@kinto-b
Copy link
Contributor Author

kinto-b commented Jan 19, 2024

Some other logical relationships we might want to support more directly:

# Not both (often used for not both blank)
expect_cond(foo, !bar)
expect_cond(bar, !foo)

# XOR (mostly covered by `expect_exclusive()`)
expect_cond(foo, !bar)
expect_cond(bar, !foo)
expect_cond(TRUE, foo | bar)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Effort: ⭐ Straightforward Task: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant