@@ -104,4 +104,101 @@ final class PermutationsTests: XCTestCase {
104
104
func testPermutationsLazy( ) {
105
105
XCTAssertLazySequence ( " ABCD " . lazy. permutations ( ofCount: 2 ) )
106
106
}
107
+
108
+ func testDocumentationExample1( ) {
109
+ // From Guides/Permutations.md
110
+ let numbers = [ 10 , 20 , 30 ]
111
+ let permutations = numbers. permutations ( )
112
+ XCTAssertEqualSequences ( permutations, [
113
+ [ 10 , 20 , 30 ] ,
114
+ [ 10 , 30 , 20 ] ,
115
+ [ 20 , 10 , 30 ] ,
116
+ [ 20 , 30 , 10 ] ,
117
+ [ 30 , 10 , 20 ] ,
118
+ [ 30 , 20 , 10 ] ,
119
+ ] )
120
+ }
121
+
122
+ func testDocumentationExample2( ) {
123
+ // From Guides/Permutations.md
124
+ let numbers = [ 10 , 20 , 30 ]
125
+ let permutations = numbers. permutations ( ofCount: 2 )
126
+ XCTAssertEqualSequences ( permutations, [
127
+ [ 10 , 20 ] ,
128
+ [ 10 , 30 ] ,
129
+ [ 20 , 10 ] ,
130
+ [ 20 , 30 ] ,
131
+ [ 30 , 10 ] ,
132
+ [ 30 , 20 ] ,
133
+ ] )
134
+ }
135
+
136
+ func testDocumentationExample3( ) {
137
+ // From Guides/Permutations.md
138
+ let numbers2 = [ 20 , 10 , 10 ]
139
+ let permutations = numbers2. permutations ( )
140
+ XCTAssertEqualSequences ( permutations, [
141
+ [ 20 , 10 , 10 ] ,
142
+ [ 20 , 10 , 10 ] ,
143
+ [ 10 , 20 , 10 ] ,
144
+ [ 10 , 10 , 20 ] ,
145
+ [ 10 , 20 , 10 ] ,
146
+ [ 10 , 10 , 20 ] ,
147
+ ] )
148
+ }
149
+
150
+ func testDocumentationExample4( ) {
151
+ // From Guides/Permutations.md
152
+ let numbers = [ 10 , 20 , 30 ]
153
+ let permutations = numbers. permutations ( ofCount: 0 ... )
154
+ XCTAssertEqualSequences ( permutations, [
155
+ [ ] ,
156
+ [ 10 ] ,
157
+ [ 20 ] ,
158
+ [ 30 ] ,
159
+ [ 10 , 20 ] ,
160
+ [ 10 , 30 ] ,
161
+ [ 20 , 10 ] ,
162
+ [ 20 , 30 ] ,
163
+ [ 30 , 10 ] ,
164
+ [ 30 , 20 ] ,
165
+ [ 10 , 20 , 30 ] ,
166
+ [ 10 , 30 , 20 ] ,
167
+ [ 20 , 10 , 30 ] ,
168
+ [ 20 , 30 , 10 ] ,
169
+ [ 30 , 10 , 20 ] ,
170
+ [ 30 , 20 , 10 ] ,
171
+ ] )
172
+ }
173
+
174
+ func testDocumentationExample5( ) {
175
+ // From Permutations.swift
176
+ let names = [ " Alex " , " Celeste " , " Davide " ]
177
+ let permutations = names. permutations ( ofCount: 2 )
178
+ XCTAssertEqualSequences ( permutations, [
179
+ [ " Alex " , " Celeste " ] ,
180
+ [ " Alex " , " Davide " ] ,
181
+ [ " Celeste " , " Alex " ] ,
182
+ [ " Celeste " , " Davide " ] ,
183
+ [ " Davide " , " Alex " ] ,
184
+ [ " Davide " , " Celeste " ] ,
185
+ ] )
186
+ }
187
+
188
+ func testDocumentationExample6( ) {
189
+ // From Permutations.swift
190
+ let names = [ " Alex " , " Celeste " , " Davide " ]
191
+ let permutations = names. permutations ( ofCount: 1 ... 2 )
192
+ XCTAssertEqualSequences ( permutations, [
193
+ [ " Alex " ] ,
194
+ [ " Celeste " ] ,
195
+ [ " Davide " ] ,
196
+ [ " Alex " , " Celeste " ] ,
197
+ [ " Alex " , " Davide " ] ,
198
+ [ " Celeste " , " Alex " ] ,
199
+ [ " Celeste " , " Davide " ] ,
200
+ [ " Davide " , " Alex " ] ,
201
+ [ " Davide " , " Celeste " ] ,
202
+ ] )
203
+ }
107
204
}
0 commit comments