Skip to content

Commit 6eed979

Browse files
committed
Updated with XCTest Swift3 syntax for shortest path
XCTest Success
1 parent 6aab620 commit 6eed979

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

Shortest Path (Unweighted)/ShortestPath.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ func breadthFirstSearchShortestPath(graph: Graph, source: Node) -> Graph {
22
let shortestPathGraph = graph.duplicate()
33

44
var queue = Queue<Node>()
5-
let sourceInShortestPathsGraph = shortestPathGraph.findNodeWithLabel(source.label)
6-
queue.enqueue(sourceInShortestPathsGraph)
5+
let sourceInShortestPathsGraph = shortestPathGraph.findNodeWithLabel(label: source.label)
6+
queue.enqueue(element: sourceInShortestPathsGraph)
77
sourceInShortestPathsGraph.distance = 0
88

99
while let current = queue.dequeue() {

Shortest Path (Unweighted)/Tests/Graph.swift

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// MARK: - Edge
22

3-
public class Edge: Equatable {
4-
public var neighbor: Node
3+
open class Edge: Equatable {
4+
open var neighbor: Node
55

66
public init(neighbor: Node) {
77
self.neighbor = neighbor
@@ -15,31 +15,31 @@ public func == (lhs: Edge, rhs: Edge) -> Bool {
1515

1616
// MARK: - Node
1717

18-
public class Node: CustomStringConvertible, Equatable {
19-
public var neighbors: [Edge]
18+
open class Node: CustomStringConvertible, Equatable {
19+
open var neighbors: [Edge]
2020

21-
public private(set) var label: String
22-
public var distance: Int?
23-
public var visited: Bool
21+
open fileprivate(set) var label: String
22+
open var distance: Int?
23+
open var visited: Bool
2424

2525
public init(label: String) {
2626
self.label = label
2727
neighbors = []
2828
visited = false
2929
}
3030

31-
public var description: String {
31+
open var description: String {
3232
if let distance = distance {
3333
return "Node(label: \(label), distance: \(distance))"
3434
}
3535
return "Node(label: \(label), distance: infinity)"
3636
}
3737

38-
public var hasDistance: Bool {
38+
open var hasDistance: Bool {
3939
return distance != nil
4040
}
4141

42-
public func remove(edge: Edge) {
42+
open func remove(_ edge: Edge) {
4343
neighbors.remove(at: neighbors.index { $0 === edge }!)
4444
}
4545
}
@@ -50,25 +50,25 @@ public func == (lhs: Node, rhs: Node) -> Bool {
5050

5151
// MARK: - Graph
5252

53-
public class Graph: CustomStringConvertible, Equatable {
54-
public private(set) var nodes: [Node]
53+
open class Graph: CustomStringConvertible, Equatable {
54+
open fileprivate(set) var nodes: [Node]
5555

5656
public init() {
5757
self.nodes = []
5858
}
5959

60-
public func addNode(label: String) -> Node {
60+
open func addNode(label: String) -> Node {
6161
let node = Node(label: label)
6262
nodes.append(node)
6363
return node
6464
}
6565

66-
public func addEdge(_ source: Node, neighbor: Node) {
66+
open func addEdge(_ source: Node, neighbor: Node) {
6767
let edge = Edge(neighbor: neighbor)
6868
source.neighbors.append(edge)
6969
}
7070

71-
public var description: String {
71+
open var description: String {
7272
var description = ""
7373

7474
for node in nodes {
@@ -79,11 +79,11 @@ public class Graph: CustomStringConvertible, Equatable {
7979
return description
8080
}
8181

82-
public func findNodeWithLabel(label: String) -> Node {
82+
open func findNodeWithLabel(label: String) -> Node {
8383
return nodes.filter { $0.label == label }.first!
8484
}
8585

86-
public func duplicate() -> Graph {
86+
open func duplicate() -> Graph {
8787
let duplicated = Graph()
8888

8989
for node in nodes {

Shortest Path (Unweighted)/Tests/Queue.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
public struct Queue<T> {
2-
private var array: [T]
2+
fileprivate var array: [T]
33

44
public init() {
55
array = []

Shortest Path (Unweighted)/Tests/Tests.xcodeproj/project.pbxproj

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
TargetAttributes = {
9595
7B2BBC7F1C779D720067B71D = {
9696
CreatedOnToolsVersion = 7.2;
97+
LastSwiftMigration = 0820;
9798
};
9899
};
99100
};
@@ -230,6 +231,7 @@
230231
PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests;
231232
PRODUCT_NAME = "$(TARGET_NAME)";
232233
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
234+
SWIFT_VERSION = 3.0;
233235
};
234236
name = Debug;
235237
};
@@ -242,6 +244,7 @@
242244
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
243245
PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests;
244246
PRODUCT_NAME = "$(TARGET_NAME)";
247+
SWIFT_VERSION = 3.0;
245248
};
246249
name = Release;
247250
};

0 commit comments

Comments
 (0)