-
Notifications
You must be signed in to change notification settings - Fork 104
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
179 - more graph operations #230
Draft
lypoluz
wants to merge
10
commits into
ogdf:master
Choose a base branch
from
lypoluz:179-more-graph-operations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5c0ec87
basic operation functionality
lypoluz 21666e9
self loops and direction option for complemtent
lypoluz 77fe131
adapted operations
lypoluz d46d087
shadowed variable fix
lypoluz 76bf106
using NodeSet in intersection
lypoluz d596544
dealing with adjEntries for self loops
lypoluz e4717b2
basic functionality tests for complement
lypoluz 17b92c4
adapted for new implementation of Graph::insert()
lypoluz 9e13ba1
removed unused variable
lypoluz ea5557b
rebase and safe loop
lypoluz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,9 @@ | |
#include <ogdf/basic/graph_generators/operations.h> | ||
#include <ogdf/basic/simple_graph_alg.h> | ||
|
||
#include <bandit/assertion_frameworks/snowhouse/assert.h> | ||
#include <bandit/assertion_frameworks/snowhouse/constraints/equalsconstraint.h> | ||
#include <bandit/grammar.h> | ||
#include <graphs.h> | ||
#include <testing.h> | ||
|
||
|
@@ -216,5 +219,108 @@ go_bandit([] { | |
}, | ||
[](int n1, int m1, int n2, int m2) { return m1 + m2 * n1; }); | ||
}); | ||
|
||
describe("tests for creating graph complement", []() { | ||
// Tests for basic functionality | ||
Graph G; | ||
node n1, n2; | ||
before_each([&]() { | ||
G.clear(); | ||
n1 = G.newNode(); | ||
n2 = G.newNode(); | ||
}); | ||
describe("tests in a simple graph", [&]() { | ||
it("creates an edge where there was none", [&]() { | ||
complement(G, false, false); | ||
edge edge12 = G.searchEdge(n1, n2); | ||
AssertThat(edge12, Is().Not().Null()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's also |
||
}); | ||
it("removes an edge where there was one", [&]() { | ||
G.newEdge(n1, n2); | ||
complement(G, false, false); | ||
edge edge12 = G.searchEdge(n1, n2); | ||
AssertThat(edge12, IsNull()); | ||
}); | ||
}); | ||
describe("tests in a directed graph", [&]() { | ||
it("reverses an existing edge", [&]() { | ||
G.newEdge(n1, n2); | ||
complement(G, true, false); | ||
edge edge12 = G.searchEdge(n1, n2, true); | ||
edge edge21 = G.searchEdge(n2, n1, true); | ||
AssertThat(edge12, IsNull()); | ||
AssertThat(edge21, Is().Not().Null()); | ||
}); | ||
it("creates two edges where there were none", [&]() { | ||
complement(G, true, false); | ||
edge edge12 = G.searchEdge(n1, n2, true); | ||
edge edge21 = G.searchEdge(n2, n1, true); | ||
AssertThat(edge12, Is().Not().Null()); | ||
AssertThat(edge21, Is().Not().Null()); | ||
}); | ||
it("removes both edges between two nodes", [&]() { | ||
G.newEdge(n1, n2); | ||
G.newEdge(n2, n1); | ||
complement(G, true, false); | ||
edge edge12 = G.searchEdge(n1, n2, true); | ||
edge edge21 = G.searchEdge(n2, n1, true); | ||
AssertThat(edge12, IsNull()); | ||
AssertThat(edge21, IsNull()); | ||
}); | ||
}); | ||
describe("tests in a graph with self loops", [&]() { | ||
it("creates a self loop where there was none", [&]() { | ||
complement(G, false, true); | ||
edge edge11 = G.searchEdge(n1, n1); | ||
AssertThat(edge11, Is().Not().Null()); | ||
}); | ||
it("removes a self loop where there was one", [&]() { | ||
G.newEdge(n1, n1); | ||
complement(G, false, true); | ||
edge edge11 = G.searchEdge(n1, n1); | ||
AssertThat(edge11, IsNull()); | ||
}); | ||
}); | ||
}); | ||
describe("tests for joining two graphs", []() { | ||
Graph G1, G2; | ||
node n1a, n1b, n2a, n2b; | ||
NodeArray<node> nodeMap; | ||
before_each([&]() { | ||
G1.clear(); | ||
n1a = G1.newNode(); | ||
n1b = G1.newNode(); | ||
G2.clear(); | ||
n2a = G2.newNode(); | ||
n2b = G2.newNode(); | ||
nodeMap = NodeArray<node>(G2); | ||
}); | ||
it("joins two edgeless graphs without association", [&]() { | ||
join(G1, G2, nodeMap); | ||
AssertThat(G1.numberOfNodes(), Equals(4)); | ||
AssertThat(G1.numberOfEdges(), Equals(4)); | ||
}); | ||
it("joins two edgeless graphs with associated nodes", [&]() { | ||
nodeMap[n2a] = n1a; | ||
join(G1, G2, nodeMap); | ||
AssertThat(G1.numberOfNodes(), Equals(3)); | ||
AssertThat(G1.numberOfEdges(), Equals(3)); | ||
}); | ||
it("joins two graphs without association", [&]() { | ||
G1.newEdge(n1a, n1b); | ||
G2.newEdge(n2a, n2b); | ||
join(G1, G2, nodeMap); | ||
AssertThat(G1.numberOfNodes(), Equals(4)); | ||
AssertThat(G1.numberOfEdges(), Equals(6)); | ||
}); | ||
it("joins two graphs with associated nodes", [&]() { | ||
G1.newEdge(n1a, n1b); | ||
G2.newEdge(n2a, n2b); | ||
nodeMap[n2a] = n1a; | ||
join(G1, G2, nodeMap); | ||
AssertThat(G1.numberOfNodes(), Equals(3)); | ||
AssertThat(G1.numberOfEdges(), Equals(3)); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of (or maybe in addition to)
valid()
I'd rather checkmapping.graphOf() == &G2