Skip to content

Commit d2dfc3f

Browse files
authored
Graph.count is computed incorrectly. (#570)
`Graph.count` is computed with the `underestimatedCount` of its children, not the `count` of them, which results in a shallow sum. Oops. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent aff817e commit d2dfc3f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Sources/Testing/Support/Graph.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ extension Graph {
376376
/// - Complexity: O(*n*), where *n* is the number of nodes in the graph.
377377
var count: Int {
378378
1 + children.reduce(into: 0) { count, child in
379-
count += child.value.underestimatedCount
379+
count += child.value.count
380380
}
381381
}
382382
}

Tests/TestingTests/Support/GraphTests.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,15 @@ struct GraphTests {
223223
"C2": Graph(value: 13579),
224224
]),
225225
"C3": Graph(value: 789, children: [
226-
"C4": Graph(value: nil),
226+
"C4": Graph(value: nil, children: [
227+
"C5": Graph(value: nil, children: [
228+
"C6": Graph(value: nil)
229+
])
230+
]),
227231
]),
228232
])
229233
#expect(graph.underestimatedCount == 3)
230-
#expect(graph.count == 5)
234+
#expect(graph.count == 7)
231235
}
232236

233237
@Test("forEach(_:) function")

0 commit comments

Comments
 (0)