From 2d3a5466dc75a838ab00eac5ffbde6599caaf410 Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 11 Apr 2019 23:31:14 -0400 Subject: [PATCH] Move Codable conformance to Graph and Edge protocols --- Sources/SwiftGraph/Constructors.swift | 4 +- Sources/SwiftGraph/Cycle.swift | 2 +- Sources/SwiftGraph/Edge.swift | 4 +- Sources/SwiftGraph/Graph.swift | 6 +-- Sources/SwiftGraph/MST.swift | 2 +- Sources/SwiftGraph/Queue.swift | 2 +- Sources/SwiftGraph/Search.swift | 2 +- Sources/SwiftGraph/Sort.swift | 2 +- Sources/SwiftGraph/Stack.swift | 2 +- Sources/SwiftGraph/SwiftPriorityQueue.swift | 2 +- Sources/SwiftGraph/UniqueElementsGraph.swift | 6 +-- Sources/SwiftGraph/UnweightedEdge.swift | 4 +- Sources/SwiftGraph/UnweightedGraph.swift | 38 +------------- Sources/SwiftGraph/WeightedEdge.swift | 6 +-- Sources/SwiftGraph/WeightedGraph.swift | 38 +------------- SwiftGraph.xcodeproj/project.pbxproj | 4 -- SwiftGraphSampleApp/AppDelegate.swift | 6 +-- .../ConstructorsPerformanceTests.swift | 2 +- .../SwiftGraphCodableTests.swift | 22 ++++---- .../UniqueElementsGraphInitTests.swift | 52 +++++++++---------- .../UniqueElementsGraphTests.swift | 26 +++++----- .../Utils/EquatableTypes.swift | 26 ---------- 22 files changed, 79 insertions(+), 179 deletions(-) delete mode 100644 Tests/SwiftGraphTests/Utils/EquatableTypes.swift diff --git a/Sources/SwiftGraph/Constructors.swift b/Sources/SwiftGraph/Constructors.swift index 94f3508..a1a98d4 100644 --- a/Sources/SwiftGraph/Constructors.swift +++ b/Sources/SwiftGraph/Constructors.swift @@ -18,7 +18,7 @@ /// A type used to construct an UnweightedGraph with vertices of type V that is isomorphic to a star graph. /// https://en.wikipedia.org/wiki/Star_(graph_theory) -public enum StarGraph { +public enum StarGraph { /// Constructs an undirected UnweightedGraph isomorphic to a star graph. /// @@ -41,7 +41,7 @@ public enum StarGraph { /// A type used to construct UnweightedGraph with vertices of type V that is isomorphic to a complete graph. /// https://en.wikipedia.org/wiki/Complete_graph -public enum CompleteGraph { +public enum CompleteGraph { /// Constructs an undirected UnweightedGraph isomorphic to a complete graph. /// diff --git a/Sources/SwiftGraph/Cycle.swift b/Sources/SwiftGraph/Cycle.swift index 92702c4..36d94f0 100644 --- a/Sources/SwiftGraph/Cycle.swift +++ b/Sources/SwiftGraph/Cycle.swift @@ -2,7 +2,7 @@ // Cycle.swift // SwiftGraph // -// Copyright (c) 2017 David Kopec +// Copyright (c) 2017-2019 David Kopec // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/Sources/SwiftGraph/Edge.swift b/Sources/SwiftGraph/Edge.swift index a6f203e..7a53944 100644 --- a/Sources/SwiftGraph/Edge.swift +++ b/Sources/SwiftGraph/Edge.swift @@ -2,7 +2,7 @@ // Edge.swift // SwiftGraph // -// Copyright (c) 2014-2016 David Kopec +// Copyright (c) 2014-2019 David Kopec // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ // limitations under the License. /// A protocol that all edges in a graph must conform to. -public protocol Edge: CustomStringConvertible { +public protocol Edge: CustomStringConvertible & Codable { /// The origin vertex of the edge var u: Int {get set} //made modifiable for changing when removing vertices /// The destination vertex of the edge diff --git a/Sources/SwiftGraph/Graph.swift b/Sources/SwiftGraph/Graph.swift index f0cd9d0..acce962 100644 --- a/Sources/SwiftGraph/Graph.swift +++ b/Sources/SwiftGraph/Graph.swift @@ -2,7 +2,7 @@ // Graph.swift // SwiftGraph // -// Copyright (c) 2014-2016 David Kopec +// Copyright (c) 2014-2019 David Kopec // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,8 +19,8 @@ /// The protocol for all graphs. /// You should generally use one of its two canonical class implementations, /// *UnweightedGraph* and *WeightedGraph* -public protocol Graph: class, CustomStringConvertible, Collection { - associatedtype V: Equatable +public protocol Graph: class, CustomStringConvertible, Collection, Codable { + associatedtype V: Equatable & Codable associatedtype E: Edge & Equatable var vertices: [V] { get set } var edges: [[E]] { get set } diff --git a/Sources/SwiftGraph/MST.swift b/Sources/SwiftGraph/MST.swift index 7d2af81..4754a4c 100644 --- a/Sources/SwiftGraph/MST.swift +++ b/Sources/SwiftGraph/MST.swift @@ -2,7 +2,7 @@ // MST.swift // SwiftGraph // -// Copyright (c) 2017 David Kopec +// Copyright (c) 2017-2019 David Kopec // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/Sources/SwiftGraph/Queue.swift b/Sources/SwiftGraph/Queue.swift index e71040d..45e2bac 100644 --- a/Sources/SwiftGraph/Queue.swift +++ b/Sources/SwiftGraph/Queue.swift @@ -2,7 +2,7 @@ // Queue.swift // SwiftGraph // -// Copyright (c) 2014-2016 David Kopec +// Copyright (c) 2014-2019 David Kopec // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/Sources/SwiftGraph/Search.swift b/Sources/SwiftGraph/Search.swift index c1052cb..4847c97 100644 --- a/Sources/SwiftGraph/Search.swift +++ b/Sources/SwiftGraph/Search.swift @@ -2,7 +2,7 @@ // Search.swift // SwiftGraph // -// Copyright (c) 2014-2016 David Kopec +// Copyright (c) 2014-2019 David Kopec // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/Sources/SwiftGraph/Sort.swift b/Sources/SwiftGraph/Sort.swift index 120f125..527cd0c 100644 --- a/Sources/SwiftGraph/Sort.swift +++ b/Sources/SwiftGraph/Sort.swift @@ -2,7 +2,7 @@ // Sort.swift // SwiftGraph // -// Copyright (c) 2016 David Kopec +// Copyright (c) 2016-2019 David Kopec // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/Sources/SwiftGraph/Stack.swift b/Sources/SwiftGraph/Stack.swift index b8114a8..9d09916 100644 --- a/Sources/SwiftGraph/Stack.swift +++ b/Sources/SwiftGraph/Stack.swift @@ -2,7 +2,7 @@ // Stack.swift // SwiftGraph // -// Copyright (c) 2014-2016 David Kopec +// Copyright (c) 2014-2019 David Kopec // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/Sources/SwiftGraph/SwiftPriorityQueue.swift b/Sources/SwiftGraph/SwiftPriorityQueue.swift index 1d44c86..7dbfefb 100644 --- a/Sources/SwiftGraph/SwiftPriorityQueue.swift +++ b/Sources/SwiftGraph/SwiftPriorityQueue.swift @@ -2,7 +2,7 @@ // SwiftPriorityQueue.swift // SwiftPriorityQueue // -// Copyright (c) 2015-2017 David Kopec +// Copyright (c) 2015-2019 David Kopec // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Sources/SwiftGraph/UniqueElementsGraph.swift b/Sources/SwiftGraph/UniqueElementsGraph.swift index d6b3161..4bdffd1 100644 --- a/Sources/SwiftGraph/UniqueElementsGraph.swift +++ b/Sources/SwiftGraph/UniqueElementsGraph.swift @@ -16,11 +16,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -public typealias UnweightedUniqueElementsGraph = UniqueElementsGraph -public typealias WeightedUniqueElementsGraph = UniqueElementsGraph> +public typealias UnweightedUniqueElementsGraph = UniqueElementsGraph +public typealias WeightedUniqueElementsGraph = UniqueElementsGraph> /// A subclass of UnweightedGraph that ensures there are no pairs of equal vertices and no repeated edges. -open class UniqueElementsGraph: Graph { +open class UniqueElementsGraph: Graph { public var vertices: [V] = [V]() public var edges: [[E]] = [[E]]() //adjacency lists diff --git a/Sources/SwiftGraph/UnweightedEdge.swift b/Sources/SwiftGraph/UnweightedEdge.swift index 5fbd49d..bc4fa68 100644 --- a/Sources/SwiftGraph/UnweightedEdge.swift +++ b/Sources/SwiftGraph/UnweightedEdge.swift @@ -2,7 +2,7 @@ // UnweightedEdge.swift // SwiftGraph // -// Copyright (c) 2014-2016 David Kopec +// Copyright (c) 2014-2019 David Kopec // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ // limitations under the License. /// A basic unweighted edge. -public struct UnweightedEdge: Edge, CustomStringConvertible, Codable, Equatable { +public struct UnweightedEdge: Edge, CustomStringConvertible, Equatable { public var u: Int public var v: Int public var directed: Bool diff --git a/Sources/SwiftGraph/UnweightedGraph.swift b/Sources/SwiftGraph/UnweightedGraph.swift index 8d2b59c..edb677e 100644 --- a/Sources/SwiftGraph/UnweightedGraph.swift +++ b/Sources/SwiftGraph/UnweightedGraph.swift @@ -2,7 +2,7 @@ // UnweightedGraph.swift // SwiftGraph // -// Copyright (c) 2014-2016 David Kopec +// Copyright (c) 2014-2019 David Kopec // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ // limitations under the License. /// A subclass of Graph with some convenience methods for adding and removing UnweightedEdges. WeightedEdges may be added to an UnweightedGraph but their weights will be ignored. -open class UnweightedGraph: Graph { +open class UnweightedGraph: Graph { public var vertices: [V] = [V]() public var edges: [[UnweightedEdge]] = [[UnweightedEdge]]() //adjacency lists @@ -131,37 +131,3 @@ extension Graph where E == UnweightedEdge { return false } } - -public final class CodableUnweightedGraph : UnweightedGraph, Codable { - enum CodingKeys: String, CodingKey { - case vertices = "vertices" - case edges = "edges" - } - - override public init() { - super.init() - } - - required public init(vertices: [V]) { - super.init(vertices: vertices) - } - - public convenience init(fromGraph g: UnweightedGraph) { - self.init() - vertices = g.vertices - edges = g.edges - } - - public required init(from decoder: Decoder) throws { - super.init() - let rootContainer = try decoder.container(keyedBy: CodingKeys.self) - self.vertices = try rootContainer.decode([V].self, forKey: CodingKeys.vertices) - self.edges = try rootContainer.decode([[E]].self, forKey: CodingKeys.edges) - } - - public func encode(to encoder: Encoder) throws { - var rootContainer = encoder.container(keyedBy: CodingKeys.self) - try rootContainer.encode(self.vertices, forKey: CodingKeys.vertices) - try rootContainer.encode(self.edges, forKey: CodingKeys.edges) - } -} diff --git a/Sources/SwiftGraph/WeightedEdge.swift b/Sources/SwiftGraph/WeightedEdge.swift index 19e7db5..6f77516 100644 --- a/Sources/SwiftGraph/WeightedEdge.swift +++ b/Sources/SwiftGraph/WeightedEdge.swift @@ -2,7 +2,7 @@ // WeightedEdge.swift // SwiftGraph // -// Copyright (c) 2014-2017 David Kopec +// Copyright (c) 2014-2019 David Kopec // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ extension WeightedEdge: WeightedEdgeProtocol { } /// A weighted edge, who's weight subscribes to Comparable. -public struct WeightedEdge: Edge, CustomStringConvertible, Equatable { +public struct WeightedEdge: Edge, CustomStringConvertible, Equatable { public var u: Int public var v: Int public var directed: Bool @@ -58,8 +58,6 @@ public struct WeightedEdge: Edge, CustomStringConvertible, Equatab } -extension WeightedEdge: Codable where W: Codable {} - extension WeightedEdge: Comparable where W: Comparable { static public func < (lhs: WeightedEdge, rhs: WeightedEdge) -> Bool { return lhs.weight < rhs.weight diff --git a/Sources/SwiftGraph/WeightedGraph.swift b/Sources/SwiftGraph/WeightedGraph.swift index ec1134b..a211f10 100644 --- a/Sources/SwiftGraph/WeightedGraph.swift +++ b/Sources/SwiftGraph/WeightedGraph.swift @@ -2,7 +2,7 @@ // WeightedGraph.swift // SwiftGraph // -// Copyright (c) 2014-2016 David Kopec +// Copyright (c) 2014-2019 David Kopec // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ // limitations under the License. /// A subclass of Graph that has convenience methods for adding and removing WeightedEdges. All added Edges should have the same generic Comparable type W as the WeightedGraph itself. -open class WeightedGraph: Graph { +open class WeightedGraph: Graph { public var vertices: [V] = [V]() public var edges: [[WeightedEdge]] = [[WeightedEdge]]() //adjacency lists @@ -154,37 +154,3 @@ extension Graph where E: WeightedEdgeProtocol { return d } } - -public final class CodableWeightedGraph : WeightedGraph, Codable { - enum CodingKeys: String, CodingKey { - case vertices = "vertices" - case edges = "edges" - } - - override public init() { - super.init() - } - - required public init(vertices: [V]) { - super.init(vertices: vertices) - } - - public convenience init(fromGraph g: WeightedGraph) { - self.init() - vertices = g.vertices - edges = g.edges - } - - public required init(from decoder: Decoder) throws { - super.init() - let rootContainer = try decoder.container(keyedBy: CodingKeys.self) - self.vertices = try rootContainer.decode([V].self, forKey: CodingKeys.vertices) - self.edges = try rootContainer.decode([[E]].self, forKey: CodingKeys.edges) - } - - public func encode(to encoder: Encoder) throws { - var rootContainer = encoder.container(keyedBy: CodingKeys.self) - try rootContainer.encode(self.vertices, forKey: CodingKeys.vertices) - try rootContainer.encode(self.edges, forKey: CodingKeys.edges) - } -} diff --git a/SwiftGraph.xcodeproj/project.pbxproj b/SwiftGraph.xcodeproj/project.pbxproj index 0a0fce8..1bd4349 100644 --- a/SwiftGraph.xcodeproj/project.pbxproj +++ b/SwiftGraph.xcodeproj/project.pbxproj @@ -49,7 +49,6 @@ B5EACB292172336900E527BD /* SearchPerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5DD6DA42171EEE1007EFF44 /* SearchPerformanceTests.swift */; }; B5EF143121791009008FCC5C /* UniqueElementsGraphInitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5EF143021791009008FCC5C /* UniqueElementsGraphInitTests.swift */; }; B5EF143321791348008FCC5C /* UniqueElementsGraphHashableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5EF143221791348008FCC5C /* UniqueElementsGraphHashableTests.swift */; }; - B5EF1437217913F1008FCC5C /* EquatableTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5EF1436217913F1008FCC5C /* EquatableTypes.swift */; }; B5F07B6B222EB43000824F08 /* ArraysHaveSameElements.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5F07B6A222EB43000824F08 /* ArraysHaveSameElements.swift */; }; B5F07B6D222EB4BD00824F08 /* WeightedGraphTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5F07B6C222EB4BD00824F08 /* WeightedGraphTests.swift */; }; B5FE1C212231DA0C008BACAA /* UnionPerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FE1C202231DA0C008BACAA /* UnionPerformanceTests.swift */; }; @@ -139,7 +138,6 @@ B5EACB222172315E00E527BD /* SwiftGraphPerformanceTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftGraphPerformanceTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; B5EF143021791009008FCC5C /* UniqueElementsGraphInitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UniqueElementsGraphInitTests.swift; sourceTree = ""; }; B5EF143221791348008FCC5C /* UniqueElementsGraphHashableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UniqueElementsGraphHashableTests.swift; sourceTree = ""; }; - B5EF1436217913F1008FCC5C /* EquatableTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EquatableTypes.swift; sourceTree = ""; }; B5F07B6A222EB43000824F08 /* ArraysHaveSameElements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArraysHaveSameElements.swift; sourceTree = ""; }; B5F07B6C222EB4BD00824F08 /* WeightedGraphTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeightedGraphTests.swift; sourceTree = ""; }; B5FE1C202231DA0C008BACAA /* UnionPerformanceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnionPerformanceTests.swift; sourceTree = ""; }; @@ -338,7 +336,6 @@ B5EF1435217913E0008FCC5C /* Utils */ = { isa = PBXGroup; children = ( - B5EF1436217913F1008FCC5C /* EquatableTypes.swift */, B5F07B6A222EB43000824F08 /* ArraysHaveSameElements.swift */, ); path = Utils; @@ -558,7 +555,6 @@ B518BAB72232E8A40059DCB8 /* WeightedUniqueElementsGraphTests.swift in Sources */, 55E784281ED2971E003899D0 /* MSTTests.swift in Sources */, B5100A4D208B97AA00C7A73A /* UnweightedGraphTests.swift in Sources */, - B5EF1437217913F1008FCC5C /* EquatableTypes.swift in Sources */, B5F07B6D222EB4BD00824F08 /* WeightedGraphTests.swift in Sources */, 7985B91D1E5A4FCB00C100E7 /* DijkstraGraphTests.swift in Sources */, 7985B91F1E5A4FCB00C100E7 /* SwiftGraphSortTests.swift in Sources */, diff --git a/SwiftGraphSampleApp/AppDelegate.swift b/SwiftGraphSampleApp/AppDelegate.swift index 0af8f2e..dab2eb4 100644 --- a/SwiftGraphSampleApp/AppDelegate.swift +++ b/SwiftGraphSampleApp/AppDelegate.swift @@ -2,7 +2,7 @@ // AppDelegate.swift // SwiftGraph // -// Copyright (c) 2014-2016 David Kopec +// Copyright (c) 2014-2019 David Kopec // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -86,7 +86,7 @@ class NineTailView: NSView { } } -enum Coin: String { +enum Coin: String, Codable { case Heads = "heads" case Tails = "tails" mutating func flip() { @@ -98,7 +98,7 @@ enum Coin: String { } } -struct NineTailPosition: Equatable { +struct NineTailPosition: Equatable, Codable { fileprivate var positionMatrix: [[Coin]] init(matrix: [[Coin]]) { positionMatrix = matrix diff --git a/Tests/SwiftGraphPerformanceTests/ConstructorsPerformanceTests.swift b/Tests/SwiftGraphPerformanceTests/ConstructorsPerformanceTests.swift index ca38c6e..e5603e0 100644 --- a/Tests/SwiftGraphPerformanceTests/ConstructorsPerformanceTests.swift +++ b/Tests/SwiftGraphPerformanceTests/ConstructorsPerformanceTests.swift @@ -21,7 +21,7 @@ import XCTest class ConstructorsPerformanceTests: XCTestCase { - struct AnyEquatable: Equatable { + struct AnyEquatable: Equatable, Codable { let value: T } diff --git a/Tests/SwiftGraphTests/SwiftGraphCodableTests.swift b/Tests/SwiftGraphTests/SwiftGraphCodableTests.swift index c1faefe..2ea07c5 100644 --- a/Tests/SwiftGraphTests/SwiftGraphCodableTests.swift +++ b/Tests/SwiftGraphTests/SwiftGraphCodableTests.swift @@ -20,8 +20,8 @@ import XCTest @testable import SwiftGraph class SwiftGraphCodableTests: XCTestCase { - var expectedUnweightedGraph: CodableUnweightedGraph { - let g: CodableUnweightedGraph = CodableUnweightedGraph() + var expectedUnweightedGraph: UnweightedGraph { + let g: UnweightedGraph = UnweightedGraph() _ = g.addVertex("Atlanta") _ = g.addVertex("New York") _ = g.addVertex("Miami") @@ -53,11 +53,11 @@ class SwiftGraphCodableTests: XCTestCase { return } - let g2: CodableUnweightedGraph + let g2: UnweightedGraph do { - g2 = try JSONDecoder().decode(CodableUnweightedGraph.self, from: jsonData2) + g2 = try JSONDecoder().decode(UnweightedGraph.self, from: jsonData2) } catch { - XCTFail("JSONDecoder().decode(CodableUnweightedGraph.self, from: jsonData) threw: \(error)") + XCTFail("JSONDecoder().decode(UnweightedGraph.self, from: jsonData) threw: \(error)") return } XCTAssertEqual(g2.neighborsForVertex("Miami")!, g2.neighborsForVertex(g.neighborsForVertex("New York")![0])!, "Miami and New York Connected bi-directionally") @@ -74,9 +74,9 @@ struct SwiftGraphCodableTests_Vertex: Equatable, Hashable, Decodable, Encodable } extension SwiftGraphCodableTests { - func cityGraph() -> CodableWeightedGraph { + func cityGraph() -> WeightedGraph { // pg 1016 Liang - let result = CodableWeightedGraph(vertices: [ + let result = WeightedGraph(vertices: [ SwiftGraphCodableTests_Vertex(int: 0, string: "Seattle"), SwiftGraphCodableTests_Vertex(int: 1, string: "San Francisco"), SwiftGraphCodableTests_Vertex(int: 2, string: "Los Angeles"), @@ -123,7 +123,7 @@ extension SwiftGraphCodableTests { } - func validateDijkstra1(cityGraph: CodableWeightedGraph) { + func validateDijkstra1(cityGraph: WeightedGraph) { let vertexWithName = { (name: String) -> SwiftGraphCodableTests_Vertex in return cityGraph.vertices.filter({ $0.string == name }).first! } @@ -224,11 +224,11 @@ extension SwiftGraphCodableTests { return } - let g2: CodableWeightedGraph + let g2: WeightedGraph do { - g2 = try JSONDecoder().decode(CodableWeightedGraph.self, from: jsonData2) + g2 = try JSONDecoder().decode(WeightedGraph.self, from: jsonData2) } catch { - XCTFail("JSONDecoder().decode(CodableWeightedGraph.self, from: jsonData) threw: \(error)") + XCTFail("JSONDecoder().decode(WeightedGraph.self, from: jsonData) threw: \(error)") return } self.validateDijkstra1(cityGraph: g2) diff --git a/Tests/SwiftGraphTests/UniqueElementsGraph/UniqueElementsGraphInitTests.swift b/Tests/SwiftGraphTests/UniqueElementsGraph/UniqueElementsGraphInitTests.swift index 2fc151c..678c393 100644 --- a/Tests/SwiftGraphTests/UniqueElementsGraph/UniqueElementsGraphInitTests.swift +++ b/Tests/SwiftGraphTests/UniqueElementsGraph/UniqueElementsGraphInitTests.swift @@ -22,21 +22,21 @@ import XCTest class UnweightedUniqueElementsGraphInitTests: XCTestCase { func testPathInitializerUndirected() { - let g0Path = UnweightedUniqueElementsGraph.withPath([]) + let g0Path = UnweightedUniqueElementsGraph.withPath([]) XCTAssertEqual(g0Path.vertexCount, 0, "g0Path: Expected empty graph") XCTAssertEqual(g0Path.edgeCount, 0, "g0Path: Expected empty graph") - let g1Path = UnweightedUniqueElementsGraph.withPath(["Atlanta"]) + let g1Path = UnweightedUniqueElementsGraph.withPath(["Atlanta"]) XCTAssertEqual(g1Path.vertices, ["Atlanta"], "g1Path: Expected only Atlanta vertex") XCTAssertEqual(g1Path.edgeCount, 0, "g1Path: Expected no edges") - let g2Path = UnweightedUniqueElementsGraph.withPath(["Atlanta", "Boston"]) + let g2Path = UnweightedUniqueElementsGraph.withPath(["Atlanta", "Boston"]) XCTAssertEqual(g2Path.vertices, ["Atlanta", "Boston"], "g2Path: Expected vertices to be Atlanta and Boston") XCTAssertEqual(g2Path.edgeCount, 2, "g2Path: Expected exactly 2 edges") XCTAssertTrue(g2Path.edgeExists(from: "Atlanta", to: "Boston"), "g2Path: Expected an edge from Atlanta to Boston") XCTAssertTrue(g2Path.edgeExists(from: "Boston", to: "Atlanta"), "g2Path: Expected an edge from Boston to Atlanta") - let g3Path = UnweightedUniqueElementsGraph.withPath(["Atlanta", "Boston", "Chicago"]) + let g3Path = UnweightedUniqueElementsGraph.withPath(["Atlanta", "Boston", "Chicago"]) XCTAssertEqual(g3Path.vertices, ["Atlanta", "Boston", "Chicago"], "g3Path: Expected vertices to be Atlanta, Boston and Chicago") XCTAssertEqual(g3Path.edgeCount, 4, "g3Path: Expected exactly 4 edges") XCTAssertTrue(g3Path.edgeExists(from: "Atlanta", to: "Boston"), "g3Path: Expected an edge from Atlanta to Boston") @@ -44,13 +44,13 @@ class UnweightedUniqueElementsGraphInitTests: XCTestCase { XCTAssertTrue(g3Path.edgeExists(from: "Boston", to: "Chicago"), "g3Path: Expected an edge from Boston to Chicago") XCTAssertTrue(g3Path.edgeExists(from: "Chicago", to: "Boston"), "g3Path: Expected an edge from Chicago to Boston") - let g4Path = UnweightedUniqueElementsGraph.withPath(["Atlanta", "Boston", "Atlanta"]) + let g4Path = UnweightedUniqueElementsGraph.withPath(["Atlanta", "Boston", "Atlanta"]) XCTAssertEqual(g4Path.vertices, ["Atlanta", "Boston"], "g4Path: Expected vertices to be Atlanta and Boston.") XCTAssertEqual(g4Path.edgeCount, 2, "g4Path: Expected exactly 2 edges") XCTAssertTrue(g4Path.edgeExists(from: "Atlanta", to: "Boston"), "g4Path: Expected an edge from Atlanta to Boston") XCTAssertTrue(g4Path.edgeExists(from: "Boston", to: "Atlanta"), "g4Path: Expected an edge from Boston to Atlanta") - let g5Path = UnweightedUniqueElementsGraph.withPath(["Atlanta", "Boston", "Chicago", "Atlanta", "Denver", "Chicago", "Atlanta"]) + let g5Path = UnweightedUniqueElementsGraph.withPath(["Atlanta", "Boston", "Chicago", "Atlanta", "Denver", "Chicago", "Atlanta"]) XCTAssertEqual(g5Path.vertices, ["Atlanta", "Boston", "Chicago", "Denver"], "g5Path: Expected vertices to be Atlanta, Boston, Chiicago and Denver.") XCTAssertEqual(g5Path.edgeCount, 10, "g5Path: Expected exactly 10 edges") XCTAssertTrue(g5Path.edgeExists(from: "Atlanta", to: "Boston"), "g5Path: Expected an edge from Atlanta to Boston") @@ -66,32 +66,32 @@ class UnweightedUniqueElementsGraphInitTests: XCTestCase { } func testPathInitializerDirected() { - let g0Path = UnweightedUniqueElementsGraph.withPath([], directed: true) + let g0Path = UnweightedUniqueElementsGraph.withPath([], directed: true) XCTAssertEqual(g0Path.vertexCount, 0, "g0Path: Expected empty graph") XCTAssertEqual(g0Path.edgeCount, 0, "g0Path: Expected empty graph") - let g1Path = UnweightedUniqueElementsGraph.withPath(["Atlanta"], directed: true) + let g1Path = UnweightedUniqueElementsGraph.withPath(["Atlanta"], directed: true) XCTAssertEqual(g1Path.vertices, ["Atlanta"], "g1Path: Expected only Atlanta vertex") XCTAssertEqual(g1Path.edgeCount, 0, "g1Path: Expected no edges") - let g2Path = UnweightedUniqueElementsGraph.withPath(["Atlanta", "Boston"], directed: true) + let g2Path = UnweightedUniqueElementsGraph.withPath(["Atlanta", "Boston"], directed: true) XCTAssertEqual(g2Path.vertices, ["Atlanta", "Boston"], "g2Path: Expected vertices to be Atlanta and Boston") XCTAssertEqual(g2Path.edgeCount, 1, "g2Path: Expected exactly 1 edges") XCTAssertTrue(g2Path.edgeExists(from: "Atlanta", to: "Boston"), "g2Path: Expected an edge from Atlanta to Boston") - let g3Path = UnweightedUniqueElementsGraph.withPath(["Atlanta", "Boston", "Chicago"], directed: true) + let g3Path = UnweightedUniqueElementsGraph.withPath(["Atlanta", "Boston", "Chicago"], directed: true) XCTAssertEqual(g3Path.vertices, ["Atlanta", "Boston", "Chicago"], "g3Path: Expected vertices to be Atlanta, Boston and Chicago") XCTAssertEqual(g3Path.edgeCount, 2, "g3Path: Expected exactly 2 edges") XCTAssertTrue(g3Path.edgeExists(from: "Atlanta", to: "Boston"), "g3Path: Expected an edge from Atlanta to Boston") XCTAssertTrue(g3Path.edgeExists(from: "Boston", to: "Chicago"), "g3Path: Expected an edge from Boston to Chicago") - let g4Path = UnweightedUniqueElementsGraph.withPath(["Atlanta", "Boston", "Atlanta"], directed: true) + let g4Path = UnweightedUniqueElementsGraph.withPath(["Atlanta", "Boston", "Atlanta"], directed: true) XCTAssertEqual(g4Path.vertices, ["Atlanta", "Boston"], "g4Path: Expected vertices to be Atlanta and Boston.") XCTAssertEqual(g4Path.edgeCount, 2, "g4Path: Expected exactly 2 edges") XCTAssertTrue(g4Path.edgeExists(from: "Atlanta", to: "Boston"), "g4Path: Expected an edge from Atlanta to Boston") XCTAssertTrue(g4Path.edgeExists(from: "Boston", to: "Atlanta"), "g4Path: Expected an edge from Boston to Atlanta") - let g5Path = UnweightedUniqueElementsGraph.withPath(["Atlanta", "Boston", "Chicago", "Atlanta", "Denver", "Chicago", "Atlanta"], directed: true) + let g5Path = UnweightedUniqueElementsGraph.withPath(["Atlanta", "Boston", "Chicago", "Atlanta", "Denver", "Chicago", "Atlanta"], directed: true) XCTAssertEqual(g5Path.vertices, ["Atlanta", "Boston", "Chicago", "Denver"], "g4Path: Expected vertices to be Atlanta, Boston, Chiicago and Denver.") XCTAssertEqual(g5Path.edgeCount, 5, "g5Path: Expected exactly 5 edges") XCTAssertTrue(g5Path.edgeExists(from: "Atlanta", to: "Boston"), "g5Path: Expected an edge from Atlanta to Boston") @@ -102,22 +102,22 @@ class UnweightedUniqueElementsGraphInitTests: XCTestCase { } func testCycleInitializerUndirected() { - let g0Cycle = UnweightedUniqueElementsGraph.withCycle([]) + let g0Cycle = UnweightedUniqueElementsGraph.withCycle([]) XCTAssertEqual(g0Cycle.vertexCount, 0, "g0Cycle: Expected empty graph") XCTAssertEqual(g0Cycle.edgeCount, 0, "g0Cycle: Expected empty graph") - let g1Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta"]) + let g1Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta"]) XCTAssertEqual(g1Cycle.vertices, ["Atlanta"], "g1Cycle: Expected only Atlanta vertex") XCTAssertEqual(g1Cycle.edgeCount, 1, "g1Cycle: Expected 1 edges") XCTAssertTrue(g1Cycle.edgeExists(from: "Atlanta", to: "Atlanta"), "g1Cycle: Expected an edge from Atlanta to Atlanta") - let g2Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston"]) + let g2Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston"]) XCTAssertEqual(g2Cycle.vertices, ["Atlanta", "Boston"], "g2Cycle: Expected vertices to be Atlanta and Boston") XCTAssertEqual(g2Cycle.edgeCount, 2, "g2Cycle: Expected exactly 2 edges") XCTAssertTrue(g2Cycle.edgeExists(from: "Atlanta", to: "Boston"), "g2Cycle: Expected an edge from Atlanta to Boston") XCTAssertTrue(g2Cycle.edgeExists(from: "Boston", to: "Atlanta"), "g2Cycle: Expected an edge from Boston to Atlanta") - let g3Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston", "Chicago"]) + let g3Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston", "Chicago"]) XCTAssertEqual(g3Cycle.vertices, ["Atlanta", "Boston", "Chicago"], "g3Cycle: Expected vertices to be Atlanta, Boston and Chicago") XCTAssertEqual(g3Cycle.edgeCount, 6, "g3Path: Expected exactly 6 edges") XCTAssertTrue(g3Cycle.edgeExists(from: "Atlanta", to: "Boston"), "g3Cycle: Expected an edge from Atlanta to Boston") @@ -127,14 +127,14 @@ class UnweightedUniqueElementsGraphInitTests: XCTestCase { XCTAssertTrue(g3Cycle.edgeExists(from: "Chicago", to: "Atlanta"), "g3Cycle: Expected an edge from Chicago to Atlanta") XCTAssertTrue(g3Cycle.edgeExists(from: "Atlanta", to: "Chicago"), "g3Cycle: Expected an edge from Atlanta to Chicago") - let g4Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston", "Atlanta"]) + let g4Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston", "Atlanta"]) XCTAssertEqual(g4Cycle.vertices, ["Atlanta", "Boston"], "g4Cycle: Expected vertices to be Atlanta and Boston.") XCTAssertEqual(g4Cycle.edgeCount, 3, "g4Cycle: Expected exactly 3 edges") XCTAssertTrue(g4Cycle.edgeExists(from: "Atlanta", to: "Boston"), "g4Cycle: Expected an edge from Atlanta to Boston") XCTAssertTrue(g4Cycle.edgeExists(from: "Boston", to: "Atlanta"), "g4Cycle: Expected an edge from Boston to Atlanta") XCTAssertTrue(g4Cycle.edgeExists(from: "Atlanta", to: "Atlanta"), "g4Cycle: Expected an edge from Atlanta to Boston") - let g5Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston", "Chicago", "Atlanta", "Denver", "Chicago", "Atlanta"]) + let g5Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston", "Chicago", "Atlanta", "Denver", "Chicago", "Atlanta"]) XCTAssertEqual(g5Cycle.vertices, ["Atlanta", "Boston", "Chicago", "Denver"], "g5Cycle: Expected vertices to be Atlanta, Boston, Chiicago and Denver.") XCTAssertEqual(g5Cycle.edgeCount, 11, "g5Path: Expected exactly 11 edges") XCTAssertTrue(g5Cycle.edgeExists(from: "Atlanta", to: "Boston"), "g5Cycle: Expected an edge from Atlanta to Boston") @@ -149,7 +149,7 @@ class UnweightedUniqueElementsGraphInitTests: XCTestCase { XCTAssertTrue(g5Cycle.edgeExists(from: "Chicago", to: "Denver"), "g5Cycle: Expected an edge from Chicago to Denver") XCTAssertTrue(g5Cycle.edgeExists(from: "Atlanta", to: "Atlanta"), "g5Cycle: Expected an edge from Atlanta to Boston") - let g6Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston", "Chicago", "Denver", "Boston", "Eugene"]) + let g6Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston", "Chicago", "Denver", "Boston", "Eugene"]) XCTAssertEqual(g6Cycle.vertices, ["Atlanta", "Boston", "Chicago", "Denver", "Eugene"], "g6Cycle: Expected vertices to be Atlanta, Boston, Chiicago and Denver.") XCTAssertEqual(g6Cycle.edgeCount, 12, "g6Cycle: Expected exactly 12 edges") XCTAssertTrue(g6Cycle.edgeExists(from: "Atlanta", to: "Boston"), "g6Cycle: Expected an edge from Atlanta to Boston") @@ -167,36 +167,36 @@ class UnweightedUniqueElementsGraphInitTests: XCTestCase { } func testCycleInitializerDirected() { - let g0Cycle = UnweightedUniqueElementsGraph.withCycle([], directed: true) + let g0Cycle = UnweightedUniqueElementsGraph.withCycle([], directed: true) XCTAssertEqual(g0Cycle.vertexCount, 0, "g0Cycle: Expected empty graph") XCTAssertEqual(g0Cycle.edgeCount, 0, "g0Cycle: Expected empty graph") - let g1Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta"], directed: true) + let g1Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta"], directed: true) XCTAssertEqual(g1Cycle.vertices, ["Atlanta"], "g1Cycle: Expected only Atlanta vertex") XCTAssertEqual(g1Cycle.edgeCount, 1, "g1Cycle: Expected 1 edge") XCTAssertTrue(g1Cycle.edgeExists(from: "Atlanta", to: "Atlanta"), "g1Cycle: Expected an edge from Atlanta to Atlanta") - let g2Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston"], directed: true) + let g2Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston"], directed: true) XCTAssertEqual(g2Cycle.vertices, ["Atlanta", "Boston"], "g2Cycle: Expected vertices to be Atlanta and Boston") XCTAssertEqual(g2Cycle.edgeCount, 2, "g2Cycle: Expected exactly 2 edges") XCTAssertTrue(g2Cycle.edgeExists(from: "Atlanta", to: "Boston"), "g2Cycle: Expected an edge from Atlanta to Boston") XCTAssertTrue(g2Cycle.edgeExists(from: "Boston", to: "Atlanta"), "g2Cycle: Expected an edge from Atlanta to Boston") - let g3Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston", "Chicago"], directed: true) + let g3Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston", "Chicago"], directed: true) XCTAssertEqual(g3Cycle.vertices, ["Atlanta", "Boston", "Chicago"], "g3Cycle: Expected vertices to be Atlanta, Boston and Chicago") XCTAssertEqual(g3Cycle.edgeCount, 3, "g3Cycle: Expected exactly 4 edges") XCTAssertTrue(g3Cycle.edgeExists(from: "Atlanta", to: "Boston"), "g3Cycle: Expected an edge from Atlanta to Boston") XCTAssertTrue(g3Cycle.edgeExists(from: "Boston", to: "Chicago"), "g3Cycle: Expected an edge from Boston to Chicago") XCTAssertTrue(g3Cycle.edgeExists(from: "Chicago", to: "Atlanta"), "g3Cycle: Expected an edge from Chicago to Atlanta") - let g4Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston", "Atlanta"], directed: true) + let g4Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston", "Atlanta"], directed: true) XCTAssertEqual(g4Cycle.vertices, ["Atlanta", "Boston"], "g4Cycle: Expected vertices to be Atlanta and Boston.") XCTAssertEqual(g4Cycle.edgeCount, 3, "g4Cycle: Expected exactly 3 edges") XCTAssertTrue(g4Cycle.edgeExists(from: "Atlanta", to: "Boston"), "g4Cycle: Expected an edge from Atlanta to Boston") XCTAssertTrue(g4Cycle.edgeExists(from: "Boston", to: "Atlanta"), "g4Cycle: Expected an edge from Boston to Atlanta") XCTAssertTrue(g4Cycle.edgeExists(from: "Atlanta", to: "Atlanta"), "g4Cycle: Expected an edge from Atlanta to Boston") - let g5Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston", "Chicago", "Atlanta", "Denver", "Chicago", "Atlanta"], directed: true) + let g5Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston", "Chicago", "Atlanta", "Denver", "Chicago", "Atlanta"], directed: true) XCTAssertEqual(g5Cycle.vertices, ["Atlanta", "Boston", "Chicago", "Denver"], "g5Cycle: Expected vertices to be Atlanta, Boston, Chiicago and Denver.") XCTAssertEqual(g5Cycle.edgeCount, 6, "g5Path: Expected exactly 6 edges") XCTAssertTrue(g5Cycle.edgeExists(from: "Atlanta", to: "Boston"), "g5Cycle: Expected an edge from Atlanta to Boston") @@ -206,7 +206,7 @@ class UnweightedUniqueElementsGraphInitTests: XCTestCase { XCTAssertTrue(g5Cycle.edgeExists(from: "Denver", to: "Chicago"), "g5Cycle: Expected an edge from Denver to Chicago") XCTAssertTrue(g5Cycle.edgeExists(from: "Atlanta", to: "Atlanta"), "g5Cycle: Expected an edge from Atlanta to Boston") - let g6Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston", "Chicago", "Denver", "Boston", "Eugene"], directed: true) + let g6Cycle = UnweightedUniqueElementsGraph.withCycle(["Atlanta", "Boston", "Chicago", "Denver", "Boston", "Eugene"], directed: true) XCTAssertEqual(g6Cycle.vertices, ["Atlanta", "Boston", "Chicago", "Denver", "Eugene"], "g6Cycle: Expected vertices to be Atlanta, Boston, Chiicago and Denver.") XCTAssertEqual(g6Cycle.edgeCount, 6, "g6Cycle: Expected exactly 6 edges") XCTAssertTrue(g6Cycle.edgeExists(from: "Atlanta", to: "Boston"), "g6Cycle: Expected an edge from Atlanta to Boston") diff --git a/Tests/SwiftGraphTests/UniqueElementsGraph/UniqueElementsGraphTests.swift b/Tests/SwiftGraphTests/UniqueElementsGraph/UniqueElementsGraphTests.swift index 8763376..cb2ccf4 100644 --- a/Tests/SwiftGraphTests/UniqueElementsGraph/UniqueElementsGraphTests.swift +++ b/Tests/SwiftGraphTests/UniqueElementsGraph/UniqueElementsGraphTests.swift @@ -32,12 +32,12 @@ class UnweightedUniqueElementsGraphHashableTests: XCTestCase { } func testUniqueVertexAfterInit() { - let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Atlanta"]) + let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Atlanta"]) XCTAssertEqual(g.vertices, ["Atlanta"], "Expected one vertex") } func testUniqueVertexAfterAddition() { - let g = UnweightedUniqueElementsGraph() + let g = UnweightedUniqueElementsGraph() _ = g.addVertex("Atlanta") XCTAssertEqual(g.vertices, ["Atlanta"], "Expected one vertex") @@ -46,7 +46,7 @@ class UnweightedUniqueElementsGraphHashableTests: XCTestCase { } func testUniqueUndirectedEdges() { - let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Chicago"]) + let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Chicago"]) g.addEdge(from: "Atlanta", to: "Chicago", directed: false) g.addEdge(from: "Atlanta", to: "Chicago", directed: false) XCTAssertTrue(g.edgeExists(from: "Atlanta", to: "Chicago"), "Expected an edge from Atlanta to Chicago") @@ -55,7 +55,7 @@ class UnweightedUniqueElementsGraphHashableTests: XCTestCase { } func testUniqueUndirectedEdges2() { - let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Boston", "Chicago"]) + let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Boston", "Chicago"]) g.addEdge(from: "Chicago", to: "Boston", directed: false) g.addEdge(from: "Atlanta", to: "Chicago", directed: false) XCTAssertTrue(g.edgeExists(from: "Atlanta", to: "Chicago"), "Expected an edge from Atlanta to Chicago") @@ -66,7 +66,7 @@ class UnweightedUniqueElementsGraphHashableTests: XCTestCase { } func testUniqueUndirectedLoop() { - let g = UnweightedUniqueElementsGraph(vertices:["Atlanta"]) + let g = UnweightedUniqueElementsGraph(vertices:["Atlanta"]) g.addEdge(from: "Atlanta", to: "Atlanta", directed: false) XCTAssertTrue(g.edgeExists(from: "Atlanta", to: "Atlanta"), "Expected an edge from Atlanta to Atlanta") XCTAssertEqual(g.edgeCount, 1, "Expect one edge") @@ -76,7 +76,7 @@ class UnweightedUniqueElementsGraphHashableTests: XCTestCase { } func testUniqueUndirectedLoop2() { - let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Boston"]) + let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Boston"]) g.addEdge(from: "Atlanta", to: "Boston", directed: false) g.addEdge(from: "Atlanta", to: "Atlanta", directed: false) XCTAssertTrue(g.edgeExists(from: "Atlanta", to: "Atlanta"), "Expected an edge from Atlanta to Atlanta") @@ -87,7 +87,7 @@ class UnweightedUniqueElementsGraphHashableTests: XCTestCase { } func testUniqueDirectedEdges() { - let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Chicago"]) + let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Chicago"]) g.addEdge(from: "Atlanta", to: "Chicago", directed: true) g.addEdge(from: "Atlanta", to: "Chicago", directed: true) XCTAssertTrue(g.edgeExists(from: "Atlanta", to: "Chicago"), "Expected an edge from Atlanta to Chicago") @@ -95,7 +95,7 @@ class UnweightedUniqueElementsGraphHashableTests: XCTestCase { } func testUniqueDirectedLoop() { - let g = UnweightedUniqueElementsGraph(vertices:["Atlanta"]) + let g = UnweightedUniqueElementsGraph(vertices:["Atlanta"]) g.addEdge(from: "Atlanta", to: "Atlanta", directed: true) XCTAssertTrue(g.edgeExists(from: "Atlanta", to: "Atlanta"), "Expected an edge from Atlanta to Atlanta") XCTAssertEqual(g.edgeCount, 1, "Expected one edges") @@ -105,7 +105,7 @@ class UnweightedUniqueElementsGraphHashableTests: XCTestCase { } func testUniqueDirectedLoop2() { - let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Boston"]) + let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Boston"]) g.addEdge(from: "Atlanta", to: "Boston", directed: true) g.addEdge(from: "Atlanta", to: "Atlanta", directed: true) XCTAssertTrue(g.edgeExists(from: "Atlanta", to: "Atlanta"), "Expected an edge from Atlanta to Atlanta") @@ -116,7 +116,7 @@ class UnweightedUniqueElementsGraphHashableTests: XCTestCase { } func testUniqueEdgesCombined1() { - let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Chicago"]) + let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Chicago"]) g.addEdge(from: "Atlanta", to: "Chicago", directed: true) g.addEdge(from: "Atlanta", to: "Chicago", directed: false) XCTAssertTrue(g.edgeExists(from: "Atlanta", to: "Chicago"), "Expected an edge from Atlanta to Chicago") @@ -125,7 +125,7 @@ class UnweightedUniqueElementsGraphHashableTests: XCTestCase { } func testUniqueEdgesCombined2() { - let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Chicago"]) + let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Chicago"]) g.addEdge(from: "Atlanta", to: "Chicago", directed: true) g.addEdge(from: "Chicago", to: "Atlanta", directed: false) XCTAssertTrue(g.edgeExists(from: "Atlanta", to: "Chicago"), "Expected an edge from Atlanta to Chicago") @@ -134,7 +134,7 @@ class UnweightedUniqueElementsGraphHashableTests: XCTestCase { } func testUniqueEdgesCombined3() { - let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Chicago"]) + let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Chicago"]) g.addEdge(from: "Atlanta", to: "Chicago", directed: false) g.addEdge(from: "Atlanta", to: "Chicago", directed: true) XCTAssertTrue(g.edgeExists(from: "Atlanta", to: "Chicago"), "Expected an edge from Atlanta to Chicago") @@ -143,7 +143,7 @@ class UnweightedUniqueElementsGraphHashableTests: XCTestCase { } func testUniqueEdgesCombined4() { - let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Chicago"]) + let g = UnweightedUniqueElementsGraph(vertices:["Atlanta", "Chicago"]) g.addEdge(from: "Atlanta", to: "Chicago", directed: false) g.addEdge(from: "Chicago", to: "Atlanta", directed: true) XCTAssertTrue(g.edgeExists(from: "Atlanta", to: "Chicago"), "Expected an edge from Atlanta to Chicago") diff --git a/Tests/SwiftGraphTests/Utils/EquatableTypes.swift b/Tests/SwiftGraphTests/Utils/EquatableTypes.swift deleted file mode 100644 index a97d737..0000000 --- a/Tests/SwiftGraphTests/Utils/EquatableTypes.swift +++ /dev/null @@ -1,26 +0,0 @@ -// -// EquatableTypes.swift -// SwiftGraphTests -// -// Copyright (c) 2018 Ferran Pujol Camins -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/// A wrapper around String but dropping Hashable conformance -struct EquatableString: ExpressibleByStringLiteral, Equatable { - init(stringLiteral: String) { - s = stringLiteral - } - - let s: String -}