Skip to content

Commit 048362b

Browse files
committed
Add unit tests for code example in README
1 parent b1564f9 commit 048362b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Tests/LaserFocusTests/LaserFocusTests.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,42 @@ final class LaserFocusTests: XCTestCase {
133133
XCTAssertEqual(outputs.first { $0.id == "B2a1" }!.averageCategoryRawValue, 2.5, accuracy: 0.001)
134134
XCTAssertEqual(outputs.first { $0.id == "C" }!.averageCategoryRawValue, 3, accuracy: 0.001)
135135
}
136+
137+
func testReadmeExample() {
138+
let inputs: [ActionableInput] = [
139+
.init(id: "A", localCategory: .vital, children: [
140+
.init(id: "A1", localCategory: .vital, children: [
141+
.init(id: "A1x", localCategory: .vital, children: []),
142+
.init(id: "A1y", localCategory: .essential, children: []),
143+
.init(id: "A1z", localCategory: .completing, children: []),
144+
]
145+
),
146+
.init(id: "A2", localCategory: .essential, children: []),
147+
.init(id: "A3", localCategory: .completing, children: [
148+
.init(id: "A3x", localCategory: .vital, children: []),
149+
.init(id: "A3y", localCategory: .essential, children: []),
150+
.init(id: "A3z", localCategory: .completing, children: []),
151+
]
152+
),
153+
]
154+
),
155+
.init(id: "B", localCategory: .optional, children: [
156+
.init(id: "B1", localCategory: .vital, children: []),
157+
.init(id: "B2", localCategory: .essential, children: [
158+
.init(id: "B2x", localCategory: .vital, children: []),
159+
.init(id: "B2y", localCategory: .retracting, children: []),
160+
.init(id: "B2z", localCategory: .completing, children: []),
161+
]
162+
)
163+
]
164+
),
165+
.init(id: "C", localCategory: .completing, children: [])
166+
]
167+
168+
let sortedOutputs: [ActionableOutput] = LaserFocus.prioritizedAtoms(inputs: inputs).sorted()
169+
XCTAssertEqual(
170+
sortedOutputs.map(\.id),
171+
["A1x", "A1y", "A2", "A1z", "A3x", "A3y", "A3z", "C", "B2x", "B1", "B2z", "B2y"]
172+
)
173+
}
136174
}

0 commit comments

Comments
 (0)