Skip to content

Commit c1952ec

Browse files
JaapWijnenvincentngo
authored andcommitted
finalize migration tests (#381)
* finalize migration tests * fix * fixes * test fixes * fix bounded priority queue
1 parent 7cee0b6 commit c1952ec

File tree

26 files changed

+202
-130
lines changed

26 files changed

+202
-130
lines changed

.travis.yml

+11-12
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,29 @@ script:
1515
- xcodebuild test -project ./Boyer-Moore/Tests/Tests.xcodeproj -scheme Tests
1616
- xcodebuild test -project ./Binary\ Search\ Tree/Solution\ 1/Tests/Tests.xcodeproj -scheme Tests
1717
- xcodebuild test -project ./Bloom\ Filter/Tests/Tests.xcodeproj -scheme Tests
18-
# - xcodebuild test -project ./Bounded\ Priority\ Queue/Tests/Tests.xcodeproj -scheme Tests
19-
# - xcodebuild test -project ./Breadth-First\ Search/Tests/Tests.xcodeproj -scheme Tests
18+
- xcodebuild test -project ./Bounded\ Priority\ Queue/Tests/Tests.xcodeproj -scheme Tests
19+
- xcodebuild test -project ./Breadth-First\ Search/Tests/Tests.xcodeproj -scheme Tests
2020
- xcodebuild test -project ./Bucket\ Sort/Tests/Tests.xcodeproj -scheme Tests
2121
- xcodebuild test -project ./B-Tree/Tests/Tests.xcodeproj -scheme Tests
2222
- xcodebuild test -project ./Comb\ Sort/Tests/Tests.xcodeproj -scheme Tests
23-
# - xcodebuild test -project ./Counting\ Sort/Tests/Tests.xcodeproj -scheme Tests
24-
# - xcodebuild test -project ./Depth-First\ Search/Tests/Tests.xcodeproj -scheme Tests
25-
# - xcodebuild test -project ./Graph/Graph.xcodeproj -scheme GraphTests
26-
# - xcodebuild test -project ./Heap/Tests/Tests.xcodeproj -scheme Tests
23+
- xcodebuild test -project ./Counting\ Sort/Tests/Tests.xcodeproj -scheme Tests
24+
- xcodebuild test -project ./Depth-First\ Search/Tests/Tests.xcodeproj -scheme Tests
25+
- xcodebuild test -project ./Graph/Graph.xcodeproj -scheme GraphTests
26+
- xcodebuild test -project ./Heap/Tests/Tests.xcodeproj -scheme Tests
2727
- xcodebuild test -project ./Heap\ Sort/Tests/Tests.xcodeproj -scheme Tests
2828
- xcodebuild test -project ./Insertion\ Sort/Tests/Tests.xcodeproj -scheme Tests
2929
- xcodebuild test -project ./K-Means/Tests/Tests.xcodeproj -scheme Tests
30-
# - xcodebuild test -project ./Linked\ List/Tests/Tests.xcodeproj -scheme Tests
30+
- xcodebuild test -project ./Linked\ List/Tests/Tests.xcodeproj -scheme Tests
3131
- xcodebuild test -project ./Longest\ Common\ Subsequence/Tests/Tests.xcodeproj -scheme Tests
3232
- xcodebuild test -project ./Minimum\ Spanning\ Tree\ \(Unweighted\)/Tests/Tests.xcodeproj -scheme Tests
33-
# - xcodebuild test -project ./Priority\ Queue/Tests/Tests.xcodeproj -scheme Tests
33+
- xcodebuild test -project ./Priority\ Queue/Tests/Tests.xcodeproj -scheme Tests
3434
- xcodebuild test -project ./Queue/Tests/Tests.xcodeproj -scheme Tests
35-
# - xcodebuild test -project ./Quicksort/Tests/Tests.xcodeproj -scheme Tests
35+
- xcodebuild test -project ./Quicksort/Tests/Tests.xcodeproj -scheme Tests
3636
- xcodebuild test -project ./Radix\ Sort/Tests/Tests.xcodeproj -scheme Tests
3737
- xcodebuild test -project ./Rootish\ Array\ Stack/Tests/Tests.xcodeproj -scheme Tests
38-
# - xcodebuild test -project ./Run-Length\ Encoding/Tests/Tests.xcodeproj -scheme Tests
39-
# - xcodebuild test -project ./Select\ Minimum\ Maximum/Tests/Tests.xcodeproj -scheme Tests
38+
- xcodebuild test -project ./Select\ Minimum\ Maximum/Tests/Tests.xcodeproj -scheme Tests
4039
- xcodebuild test -project ./Selection\ Sort/Tests/Tests.xcodeproj -scheme Tests
41-
# - xcodebuild test -project ./Shell\ Sort/Tests/Tests.xcodeproj -scheme Tests
40+
- xcodebuild test -project ./Shell\ Sort/Tests/Tests.xcodeproj -scheme Tests
4241
- xcodebuild test -project ./Shortest\ Path\ \(Unweighted\)/Tests/Tests.xcodeproj -scheme Tests
4342
- xcodebuild test -project ./Single-Source\ Shortest\ Paths\ \(Weighted\)/SSSP.xcodeproj -scheme SSSPTests
4443
- xcodebuild test -project ./Stack/Tests/Tests.xcodeproj -scheme Tests

Bounded Priority Queue/BoundedPriorityQueue.playground/Sources/BoundedPriorityQueue.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class LinkedListNode<T: Comparable> {
99
}
1010

1111
public class BoundedPriorityQueue<T: Comparable> {
12-
private typealias Node = LinkedListNode<T>
12+
fileprivate typealias Node = LinkedListNode<T>
1313

1414
private(set) public var count = 0
1515
fileprivate var head: Node?

Bounded Priority Queue/BoundedPriorityQueue.swift

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
public class LinkedListNode<T: Comparable> {
1+
open class LinkedListNode<T: Comparable> {
22
var value: T
33
var next: LinkedListNode?
44
var previous: LinkedListNode?
@@ -8,27 +8,27 @@ public class LinkedListNode<T: Comparable> {
88
}
99
}
1010

11-
public class BoundedPriorityQueue<T: Comparable> {
12-
private typealias Node = LinkedListNode<T>
11+
open class BoundedPriorityQueue<T: Comparable> {
12+
fileprivate typealias Node = LinkedListNode<T>
1313

14-
private(set) public var count = 0
15-
private var head: Node?
16-
private var tail: Node?
17-
private var maxElements: Int
14+
fileprivate(set) open var count = 0
15+
fileprivate var head: Node?
16+
fileprivate var tail: Node?
17+
fileprivate var maxElements: Int
1818

1919
public init(maxElements: Int) {
2020
self.maxElements = maxElements
2121
}
2222

23-
public var isEmpty: Bool {
23+
open var isEmpty: Bool {
2424
return count == 0
2525
}
2626

27-
public func peek() -> T? {
27+
open func peek() -> T? {
2828
return head?.value
2929
}
3030

31-
public func enqueue(value: T) {
31+
open func enqueue(_ value: T) {
3232
if let node = insert(value, after: findInsertionPoint(value)) {
3333
// If the newly inserted node is the last one in the list, then update
3434
// the tail pointer.
@@ -44,7 +44,7 @@ public class BoundedPriorityQueue<T: Comparable> {
4444
}
4545
}
4646

47-
private func insert(value: T, after: Node?) -> Node? {
47+
fileprivate func insert(_ value: T, after: Node?) -> Node? {
4848
if let previous = after {
4949

5050
// If the queue is full and we have to insert at the end of the list,
@@ -78,18 +78,18 @@ public class BoundedPriorityQueue<T: Comparable> {
7878

7979
/* Find the node after which to insert the new value. If this returns nil,
8080
the new value should be inserted at the head of the list. */
81-
private func findInsertionPoint(value: T) -> Node? {
81+
fileprivate func findInsertionPoint(_ value: T) -> Node? {
8282
var node = head
8383
var prev: Node? = nil
8484

85-
while let current = node where value < current.value {
85+
while let current = node, value < current.value {
8686
prev = node
8787
node = current.next
8888
}
8989
return prev
9090
}
9191

92-
private func removeLeastImportantElement() {
92+
fileprivate func removeLeastImportantElement() {
9393
if let last = tail {
9494
tail = last.previous
9595
tail?.next = nil
@@ -101,7 +101,7 @@ public class BoundedPriorityQueue<T: Comparable> {
101101
// this is much slower on large lists.
102102
}
103103

104-
public func dequeue() -> T? {
104+
open func dequeue() -> T? {
105105
if let first = head {
106106
count -= 1
107107
if count == 0 {

Bounded Priority Queue/Tests/Tests.xcodeproj/project.pbxproj

+41-1
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@
8282
isa = PBXProject;
8383
attributes = {
8484
LastSwiftUpdateCheck = 0720;
85-
LastUpgradeCheck = 0720;
85+
LastUpgradeCheck = 0820;
8686
TargetAttributes = {
8787
B80004B21C83E342001FE2D7 = {
8888
CreatedOnToolsVersion = 7.2.1;
89+
LastSwiftMigration = 0820;
8990
};
9091
};
9192
};
@@ -132,12 +133,49 @@
132133
B80004AD1C83E324001FE2D7 /* Debug */ = {
133134
isa = XCBuildConfiguration;
134135
buildSettings = {
136+
CLANG_WARN_BOOL_CONVERSION = YES;
137+
CLANG_WARN_CONSTANT_CONVERSION = YES;
138+
CLANG_WARN_EMPTY_BODY = YES;
139+
CLANG_WARN_ENUM_CONVERSION = YES;
140+
CLANG_WARN_INFINITE_RECURSION = YES;
141+
CLANG_WARN_INT_CONVERSION = YES;
142+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
143+
CLANG_WARN_UNREACHABLE_CODE = YES;
144+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
145+
ENABLE_STRICT_OBJC_MSGSEND = YES;
146+
ENABLE_TESTABILITY = YES;
147+
GCC_NO_COMMON_BLOCKS = YES;
148+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
149+
GCC_WARN_ABOUT_RETURN_TYPE = YES;
150+
GCC_WARN_UNDECLARED_SELECTOR = YES;
151+
GCC_WARN_UNINITIALIZED_AUTOS = YES;
152+
GCC_WARN_UNUSED_FUNCTION = YES;
153+
GCC_WARN_UNUSED_VARIABLE = YES;
154+
ONLY_ACTIVE_ARCH = YES;
135155
};
136156
name = Debug;
137157
};
138158
B80004AE1C83E324001FE2D7 /* Release */ = {
139159
isa = XCBuildConfiguration;
140160
buildSettings = {
161+
CLANG_WARN_BOOL_CONVERSION = YES;
162+
CLANG_WARN_CONSTANT_CONVERSION = YES;
163+
CLANG_WARN_EMPTY_BODY = YES;
164+
CLANG_WARN_ENUM_CONVERSION = YES;
165+
CLANG_WARN_INFINITE_RECURSION = YES;
166+
CLANG_WARN_INT_CONVERSION = YES;
167+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
168+
CLANG_WARN_UNREACHABLE_CODE = YES;
169+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
170+
ENABLE_STRICT_OBJC_MSGSEND = YES;
171+
GCC_NO_COMMON_BLOCKS = YES;
172+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
173+
GCC_WARN_ABOUT_RETURN_TYPE = YES;
174+
GCC_WARN_UNDECLARED_SELECTOR = YES;
175+
GCC_WARN_UNINITIALIZED_AUTOS = YES;
176+
GCC_WARN_UNUSED_FUNCTION = YES;
177+
GCC_WARN_UNUSED_VARIABLE = YES;
178+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
141179
};
142180
name = Release;
143181
};
@@ -188,6 +226,7 @@
188226
SDKROOT = macosx;
189227
SWIFT_OBJC_BRIDGING_HEADER = "";
190228
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
229+
SWIFT_VERSION = 3.0;
191230
};
192231
name = Debug;
193232
};
@@ -230,6 +269,7 @@
230269
PRODUCT_NAME = "$(TARGET_NAME)";
231270
SDKROOT = macosx;
232271
SWIFT_OBJC_BRIDGING_HEADER = "";
272+
SWIFT_VERSION = 3.0;
233273
};
234274
name = Release;
235275
};

Bounded Priority Queue/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0730"
3+
LastUpgradeVersion = "0820"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Counting Sort/CountingSort.swift

+32-34
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,39 @@
66
// Copyright © 2016 Ali Hafizji. All rights reserved.
77
//
88

9-
import Foundation
10-
119
enum CountingSortError: Error {
12-
case arrayEmpty
10+
case arrayEmpty
1311
}
1412

15-
func countingSort(array: [Int]) throws -> [Int] {
16-
guard array.count > 0 else {
17-
throw CountingSortError.arrayEmpty
18-
}
19-
20-
// Step 1
21-
// Create an array to store the count of each element
22-
let maxElement = array.max() ?? 0
23-
24-
var countArray = [Int](repeating: 0, count: Int(maxElement + 1))
25-
for element in array {
26-
countArray[element] += 1
27-
}
28-
29-
// Step 2
30-
// Set each value to be the sum of the previous two values
31-
for index in 1 ..< countArray.count {
32-
let sum = countArray[index] + countArray[index - 1]
33-
countArray[index] = sum
34-
}
35-
36-
print(countArray)
37-
38-
// Step 3
39-
// Place the element in the final array as per the number of elements before it
40-
var sortedArray = [Int](repeating: 0, count: array.count)
41-
for element in array {
42-
countArray[element] -= 1
43-
sortedArray[countArray[element]] = element
44-
}
45-
return sortedArray
13+
func countingSort(_ array: [Int]) throws -> [Int] {
14+
guard array.count > 0 else {
15+
throw CountingSortError.arrayEmpty
16+
}
17+
18+
// Step 1
19+
// Create an array to store the count of each element
20+
let maxElement = array.max() ?? 0
21+
22+
var countArray = [Int](repeating: 0, count: Int(maxElement + 1))
23+
for element in array {
24+
countArray[element] += 1
25+
}
26+
27+
// Step 2
28+
// Set each value to be the sum of the previous two values
29+
for index in 1 ..< countArray.count {
30+
let sum = countArray[index] + countArray[index - 1]
31+
countArray[index] = sum
32+
}
33+
34+
print(countArray)
35+
36+
// Step 3
37+
// Place the element in the final array as per the number of elements before it
38+
var sortedArray = [Int](repeating: 0, count: array.count)
39+
for element in array {
40+
countArray[element] -= 1
41+
sortedArray[countArray[element]] = element
42+
}
43+
return sortedArray
4644
}

Counting Sort/Tests/Tests.xcodeproj/project.pbxproj

+9-1
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@
8383
isa = PBXProject;
8484
attributes = {
8585
LastSwiftUpdateCheck = 0720;
86-
LastUpgradeCheck = 0720;
86+
LastUpgradeCheck = 0820;
8787
ORGANIZATIONNAME = "Swift Algorithm Club";
8888
TargetAttributes = {
8989
7B2BBC7F1C779D720067B71D = {
9090
CreatedOnToolsVersion = 7.2;
91+
LastSwiftMigration = 0820;
9192
};
9293
};
9394
};
@@ -145,8 +146,10 @@
145146
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
146147
CLANG_WARN_EMPTY_BODY = YES;
147148
CLANG_WARN_ENUM_CONVERSION = YES;
149+
CLANG_WARN_INFINITE_RECURSION = YES;
148150
CLANG_WARN_INT_CONVERSION = YES;
149151
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
152+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
150153
CLANG_WARN_UNREACHABLE_CODE = YES;
151154
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
152155
CODE_SIGN_IDENTITY = "-";
@@ -189,8 +192,10 @@
189192
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
190193
CLANG_WARN_EMPTY_BODY = YES;
191194
CLANG_WARN_ENUM_CONVERSION = YES;
195+
CLANG_WARN_INFINITE_RECURSION = YES;
192196
CLANG_WARN_INT_CONVERSION = YES;
193197
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
198+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
194199
CLANG_WARN_UNREACHABLE_CODE = YES;
195200
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
196201
CODE_SIGN_IDENTITY = "-";
@@ -209,6 +214,7 @@
209214
MACOSX_DEPLOYMENT_TARGET = 10.11;
210215
MTL_ENABLE_DEBUG_INFO = NO;
211216
SDKROOT = macosx;
217+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
212218
};
213219
name = Release;
214220
};
@@ -220,6 +226,7 @@
220226
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
221227
PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests;
222228
PRODUCT_NAME = "$(TARGET_NAME)";
229+
SWIFT_VERSION = 3.0;
223230
};
224231
name = Debug;
225232
};
@@ -231,6 +238,7 @@
231238
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
232239
PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests;
233240
PRODUCT_NAME = "$(TARGET_NAME)";
241+
SWIFT_VERSION = 3.0;
234242
};
235243
name = Release;
236244
};

Counting Sort/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0720"
3+
LastUpgradeVersion = "0820"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

0 commit comments

Comments
 (0)