Skip to content

Commit f2d715e

Browse files
committed
Add test for sub graph
1 parent 80cb252 commit f2d715e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Tests/SwiftNodesTests.swift

+26
Original file line numberDiff line numberDiff line change
@@ -179,5 +179,31 @@ class SwiftNodesTests: XCTestCase {
179179
XCTAssertNil(meg.edge(from: "id1", to: "id3"))
180180
}
181181

182+
func testSubGraph() {
183+
var graph = Graph<Int, Int>()
184+
185+
for value in 0 ... 20
186+
{
187+
graph.insert(value)
188+
}
189+
190+
for value in 0 ... 19
191+
{
192+
graph.addEdge(from: value, to: value + 1)
193+
}
194+
195+
XCTAssertEqual(graph.edges.count, 20)
196+
XCTAssertNotNil(graph.edge(from: 12, to: 13))
197+
198+
let subsetOfNodeIDs: Set<Int> = [0, 3, 6, 9, 12, 13, 14, 15]
199+
let subGraph = graph.subGraph(nodeIDs: subsetOfNodeIDs)
200+
201+
XCTAssertEqual(graph.edges.count, 20)
202+
XCTAssertNotNil(graph.edge(from: 9, to: 10))
203+
204+
XCTAssertEqual(subGraph.edges.count, 3)
205+
XCTAssertNil(subGraph.edge(from: 9, to: 10))
206+
}
207+
182208
// TODO: Test more algorithms
183209
}

0 commit comments

Comments
 (0)