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

test: merged and refactored flow.R tests #1675

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

schochastics
Copy link
Contributor

All tests related to functions in the file flow.R were moved to test-flow.R and refactored to fit https://masalmon.eu/2024/05/23/refactoring-tests/.

Some additional tests were added and code cleaned in flow.R

cc @maelle keeping this on draft, would like to get your opinion on the structure 😁

Copy link
Contributor

aviator-app bot commented Feb 8, 2025

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This pull request is currently open (not queued).

How to merge

To merge this PR, comment /aviator merge or add the mergequeue label.


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

@schochastics schochastics marked this pull request as ready for review February 12, 2025 18:15
Copy link
Contributor

@maelle maelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

is.null(target) && !is.null(source)) {
stop("Please give both source and target or neither")

if (xor(is.null(source), is.null(target))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG I did not know about xor()! 🤯

Could you explain why we should use it instead of the operator directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason I had to switch to it was that it is shorter and expresses what we want more clearly.

xor
#> function (x, y) 
#> {
#>     (x | y) & !(x & y)
#> }
#> <bytecode: 0x10697add8>
#> <environment: namespace:base>

But now I am note sure if it is 100% ok to use, given that it uses single | and &? Could this be an issue? I think not

R/flow.R Outdated Show resolved Hide resolved
R/flow.R Outdated Show resolved Hide resolved
R/flow.R Outdated Show resolved Hide resolved
}
}

#' @rdname edge_connectivity
#' @export
edge_disjoint_paths <- function(graph, source, target) {
edge_disjoint_paths <- function(graph, source = NULL, target = NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change the default value especially if the code won't work with it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it to align it with the function below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this was just to align the code with the rest. But I don't mind changing it back if you think it is better to leave it untouched

tests/testthat/test-flow.R Outdated Show resolved Hide resolved
tests/testthat/test-flow.R Outdated Show resolved Hide resolved
tests/testthat/test-flow.R Outdated Show resolved Hide resolved
tests/testthat/test-flow.R Outdated Show resolved Hide resolved
is <- sapply(msts, is_separator, graph = g_zachary)
expect_equal(unique(is), TRUE)

## TODO: check that it is minimal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this hard / still valid?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

library(igraph)
g_zachary <- make_graph("Zachary")
msts <- min_st_separators(g_zachary)
sapply(msts, is_min_separator, graph = g_zachary)
#>  [1]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [13]  TRUE  TRUE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE
#> [25] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE
#> [37] FALSE FALSE FALSE

@szhorvat not too familiar with the topic. Is the output problematic? shouldnt all be TRUE?

Copy link
Member

@szhorvat szhorvat Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not verified all of this but it should be correct.

This is indeed tricky and a bit confusing.

All of these are separators in the sense that their removal makes some vertex u unreachable from some vertex v.

"Minimal" in general means that we can't shrink the set while maintaining its property. We do indeed need to remove all these vertices to separate parts of the graph. But here's a quirk:

msts[[4]] is 1,3,14,20,31. You drop any of 3, 14, 20 and 31 and this would still be a separator, so it's not a "minimal separator". This is why is_min_separator() returns false. But it is a "minimal s-t separator" because there exists a vertex pair which can only be separated by removing all these vertices. An example is 2 and 33.

See the docs here for an example: https://igraph.org/c/html/latest/igraph-Separators.html#igraph_all_minimal_st_separators

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks for the clarification! Missed the part that they are minimal for some vertex pair. I got it now!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants