diff options
Diffstat (limited to 'IO/GraphFile.cs')
-rw-r--r-- | IO/GraphFile.cs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/IO/GraphFile.cs b/IO/GraphFile.cs index 42a1b2b..2e00eef 100644 --- a/IO/GraphFile.cs +++ b/IO/GraphFile.cs @@ -3,13 +3,15 @@ using Interfaces; namespace Graph.IO { + using Graph = Graph<Vertex<Edge<double>, double>, Edge<double>, double>; + public static class GraphFile { // read a graph from file using IFileReader (i.e. Dependancy injection for unit testing) - public static Graph<double> Read(IFileReader reader) + public static Graph Read(IFileReader reader) { string[] lines = reader.Lines; - Graph<double> graph = new Graph<double>(); + Graph graph = new Graph(); foreach (string line in reader.Lines) { @@ -42,11 +44,11 @@ namespace Graph.IO } // write a graph to file using IFileWriter (i.e. Dependancy injection for unit testing) - public static void Print(Graph<double> graph, IFileWriter writer) + public static void Print(Graph graph, IFileWriter writer) { // create array of strings with a size equal to vertices string[] lines = new string[graph.Vertices.Count]; - + // add each vertex to it's parents output line graph.Vertices.ForEach(vertex => { @@ -57,7 +59,7 @@ namespace Graph.IO // for vertex & parent, create string if not already lines[vertex.Id] ??= $"{vertex.Id}"; lines[vertex.Parent] ??= $"{vertex.Parent}"; - + // add vertex + weight to parent's string & visa versa lines[vertex.Parent] += $" {vertex.Id} {vertex.Key.ToString("F1")}"; lines[vertex.Id] += $" {vertex.Parent} {vertex.Key.ToString("F1")}"; |