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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
import Testing
@testable import WmapParser
@Test func shouldParseABasicComponent() {
let source = "Dominoes (0.9, 0.5)"
let result = WmapParser.parse(source)
#expect(result.components.count == 1)
#expect(
result.components.first
== WmapParser.Component(
label: "Dominoes", coordinates: WmapParser.MapPoint(xCoordinate: 0.9, yCoordinate: 0.5),
shape: .circle
)
)
}
@Test func shouldParseAComponentWithAShape() {
let source = "Database (0.33, 0.81) [Square]"
let result = WmapParser.parse(source)
#expect(result.components.count == 1)
#expect(
result.components.first
== WmapParser.Component(
label: "Database", coordinates: WmapParser.MapPoint(xCoordinate: 0.33, yCoordinate: 0.81),
shape: .square)
)
}
@Test func shouldParseAComponentWithXShape() {
let source = "API (0.5, 0.6) [x]"
let result = WmapParser.parse(source)
#expect(result.components.count == 1)
#expect(
result.components.first
== WmapParser.Component(
label: "API", coordinates: WmapParser.MapPoint(xCoordinate: 0.5, yCoordinate: 0.6),
shape: .xMark)
)
}
@Test func shouldParseAComponentWithTriangleShape() {
let source = "Service (0.4, 0.7) [Triangle]"
let result = WmapParser.parse(source)
#expect(result.components.count == 1)
#expect(
result.components.first
== WmapParser.Component(
label: "Service", coordinates: WmapParser.MapPoint(xCoordinate: 0.4, yCoordinate: 0.7),
shape: .triangle)
)
}
@Test func shouldParseAComponentWithCircleShape() {
let source = "Process (0.2, 0.9) [CIRCLE]"
let result = WmapParser.parse(source)
#expect(result.components.count == 1)
#expect(
result.components.first
== WmapParser.Component(
label: "Process", coordinates: WmapParser.MapPoint(xCoordinate: 0.2, yCoordinate: 0.9),
shape: .circle)
)
}
@Test func shouldDefaultShapeToCircleIfInvalid() {
let source = "Figures (0.12, 0.711) ["
let result = WmapParser.parse(source)
#expect(result.components.count == 1)
#expect(
result.components.first
== WmapParser.Component(
label: "Figures", coordinates: WmapParser.MapPoint(xCoordinate: 0.12, yCoordinate: 0.711),
shape: .circle)
)
}
@Test func shouldHandleDecimalNumbers() {
let source = "Item (.5, .123)"
let result = WmapParser.parse(source)
#expect(result.components.count == 1)
#expect(
result.components.first
== WmapParser.Component(
label: "Item", coordinates: WmapParser.MapPoint(xCoordinate: 0.5, yCoordinate: 0.123),
shape: .circle)
)
}
@Test func shouldHandleIntegersAsCoordinates() {
let source = "Item (1, 0)"
let result = WmapParser.parse(source)
#expect(result.components.count == 1)
#expect(
result.components.first
== WmapParser.Component(
label: "Item", coordinates: WmapParser.MapPoint(xCoordinate: 1.0, yCoordinate: 0.0),
shape: .circle)
)
}
@Test func shouldPreserveCaseInComponentLabels() {
let source = "RubberGaskets (0.5, 0.5)"
let result = WmapParser.parse(source)
#expect(result.components.count == 1)
#expect(
result.components.first
== WmapParser.Component(
label: "RubberGaskets",
coordinates: WmapParser.MapPoint(xCoordinate: 0.5, yCoordinate: 0.5),
shape: .circle)
)
}
@Test func shouldHandleComponentLabelsWithSpaces() {
let source = "Big Lawnmowers (0.5, 0.5)"
let result = WmapParser.parse(source)
#expect(result.components.count == 1)
#expect(
result.components.first
== WmapParser.Component(
label: "Big Lawnmowers",
coordinates: WmapParser.MapPoint(xCoordinate: 0.5, yCoordinate: 0.5),
shape: .circle)
)
}
@Test func shouldHandleWhitespaceAroundTokens() {
let source = " Outer Space ( 0.9 , 0.5 ) [ Square ] "
let result = WmapParser.parse(source)
#expect(result.components.count == 1)
#expect(
result.components.first
== WmapParser.Component(
label: "Outer Space", coordinates: WmapParser.MapPoint(xCoordinate: 0.9, yCoordinate: 0.5),
shape: .square)
)
}
|