This repository was archived by the owner on Nov 7, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathTestSupport.swift
More file actions
61 lines (56 loc) · 2.3 KB
/
Copy pathTestSupport.swift
File metadata and controls
61 lines (56 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import Foundation
import XCTest
import VisuStructCore
/// Beispieldiagramme im Repo-Ordner `VisuStruct-Dateien` (relativ zu dieser Datei aufgelöst).
enum ExampleFiles {
static let directory: URL = URL(fileURLWithPath: #filePath)
.deletingLastPathComponent() // VisuStructCoreTests
.deletingLastPathComponent() // Tests
.deletingLastPathComponent() // VisuStructCore
.deletingLastPathComponent() // VisuStruct-iOS
.deletingLastPathComponent() // Repo-Wurzel
.appendingPathComponent("VisuStruct-Dateien", isDirectory: true)
/// Alle `.visustruct`-Dateien, rekursiv, sortiert.
static func allDiagramURLs() throws -> [URL] {
guard let enumerator = FileManager.default.enumerator(at: directory, includingPropertiesForKeys: nil) else {
return []
}
return enumerator
.compactMap { $0 as? URL }
.filter { $0.pathExtension == "visustruct" }
.sorted { $0.path < $1.path }
}
static func document(named name: String) throws -> VisuStructDocument {
try VisuStructXMLCodec.decode(url: directory.appendingPathComponent(name))
}
static func text(named name: String) throws -> String {
try String(contentsOf: directory.appendingPathComponent(name), encoding: .utf8)
}
}
/// Lässt die Simulation bis zum Ende laufen und beantwortet `input:`-Anfragen der Reihe nach.
func runSimulation(
_ document: VisuStructDocument,
inputs: [String] = [],
maxSteps: Int = 10_000,
file: StaticString = #filePath,
line: UInt = #line
) -> VisuStructSimulationState {
var engine = VisuStructSimulationEngine(document: document)
var remainingInputs = inputs[...]
var stepsTaken = 0
while stepsTaken < maxSteps {
if engine.state.inputRequest != nil {
guard let next = remainingInputs.popFirst() else {
XCTFail("Simulation wartet auf Eingabe, aber es sind keine Eingaben mehr übrig.", file: file, line: line)
return engine.state
}
engine.provideInput(next)
continue
}
guard engine.canStep else { break }
engine.step()
stepsTaken += 1
}
XCTAssertLessThan(stepsTaken, maxSteps, "Simulation endet nicht.", file: file, line: line)
return engine.state
}