diff --git a/LoggingKata.Test/LoggingKata.Test.sln b/LoggingKata.Test/LoggingKata.Test.sln new file mode 100644 index 00000000..795bfcee --- /dev/null +++ b/LoggingKata.Test/LoggingKata.Test.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 25.0.1703.5 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoggingKata.Test", "LoggingKata.Test.csproj", "{92B19028-BB50-408F-ACDD-1B6AD4D8C973}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {92B19028-BB50-408F-ACDD-1B6AD4D8C973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {92B19028-BB50-408F-ACDD-1B6AD4D8C973}.Debug|Any CPU.Build.0 = Debug|Any CPU + {92B19028-BB50-408F-ACDD-1B6AD4D8C973}.Release|Any CPU.ActiveCfg = Release|Any CPU + {92B19028-BB50-408F-ACDD-1B6AD4D8C973}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7AD1EC3B-6F14-40D3-A7E1-D783AFFCB925} + EndGlobalSection +EndGlobal diff --git a/LoggingKata.Test/TacoParserTests.cs b/LoggingKata.Test/TacoParserTests.cs index 7a1d1d88..0cf72017 100644 --- a/LoggingKata.Test/TacoParserTests.cs +++ b/LoggingKata.Test/TacoParserTests.cs @@ -29,15 +29,49 @@ public void ShouldParseLongitude(string line, double expected) // extract the Longitude. Your .csv file will have many of these lines, // each representing a TacoBell location + //Arrange - write the code we need in order to call the method we're testing + var tacoParserInstance = new TacoParser(); + + //Parse method is located inside of the TacoParser class + //var tester = new TacoParser(); + + //Act + //var actual = tester.Parse(line); + var actual = tacoParserInstance.Parse(line); + + //Assert + Assert.Equal(expected, actual.Location.Longitude); + } + + + //TODO: Create a test ShouldParseLatitude + + [Theory] + [InlineData("34.073638, -84.677017, Taco Bell Acwort...", 34.073638)] + public void ShouldParseLat(string line, double expected) + { + // TODO: Complete - "line" represents input data we will Parse to + // extract the Longitude. Your .csv file will have many of these lines, + // each representing a TacoBell location + //Arrange //Act //Assert - } + var tacoParserInstance = new TacoParser(); + //Parse method is located inside of the TacoParser class + //var tester = new TacoParser(); + + //Act + //var actual = tester.Parse(line); + var actual = tacoParserInstance.Parse(line); + + //Assert + Assert.Equal(expected, actual.Location.Latitude); + } - //TODO: Create a test ShouldParseLatitude } } diff --git a/LoggingKata/ILog.cs b/LoggingKata/ILog.cs old mode 100755 new mode 100644 index f186bc0c..065d6a8d --- a/LoggingKata/ILog.cs +++ b/LoggingKata/ILog.cs @@ -10,3 +10,5 @@ public interface ILog void LogDebug(string log); } } + +//stubbed out methods \ No newline at end of file diff --git a/LoggingKata/ITrackable.cs b/LoggingKata/ITrackable.cs old mode 100755 new mode 100644 index 8e07f047..fff49bab --- a/LoggingKata/ITrackable.cs +++ b/LoggingKata/ITrackable.cs @@ -2,7 +2,8 @@ { public interface ITrackable { - string Name { get; set; } + string Name { get; set; } //property Point Location { get; set; } } -} \ No newline at end of file +} +//interfaces specify behavior \ No newline at end of file diff --git a/LoggingKata/LoggingKata.sln b/LoggingKata/LoggingKata.sln new file mode 100644 index 00000000..7885a06f --- /dev/null +++ b/LoggingKata/LoggingKata.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 25.0.1703.5 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoggingKata", "LoggingKata.csproj", "{F6482626-514A-45F3-BD67-504DC4563828}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoggingKata.Test", "..\LoggingKata.Test\LoggingKata.Test.csproj", "{EF9EB999-F284-4C2A-9000-817FF607E84C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F6482626-514A-45F3-BD67-504DC4563828}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F6482626-514A-45F3-BD67-504DC4563828}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F6482626-514A-45F3-BD67-504DC4563828}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F6482626-514A-45F3-BD67-504DC4563828}.Release|Any CPU.Build.0 = Release|Any CPU + {EF9EB999-F284-4C2A-9000-817FF607E84C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EF9EB999-F284-4C2A-9000-817FF607E84C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EF9EB999-F284-4C2A-9000-817FF607E84C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EF9EB999-F284-4C2A-9000-817FF607E84C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E3BFCAC5-C378-4BD2-AB55-9B14981BF561} + EndGlobalSection +EndGlobal diff --git a/LoggingKata/Program.cs b/LoggingKata/Program.cs index 24af91bd..114b5733 100644 --- a/LoggingKata/Program.cs +++ b/LoggingKata/Program.cs @@ -15,11 +15,21 @@ static void Main(string[] args) // TODO: Find the two Taco Bells that are the furthest from one another. // HINT: You'll need two nested forloops --------------------------- - logger.LogInfo("Log initialized"); + logger.LogInfo("Log initialized......."); // use File.ReadAllLines(path) to grab all the lines from your csv file // Log and error if you get 0 lines and a warning if you get 1 line + var lines = File.ReadAllLines(csvPath); + if(lines.Length == 0) + { + logger.LogError("file has no input"); + } + + if (lines.Length == 1) + { + logger.LogWarning("file only has one line of input"); + } logger.LogInfo($"Lines: {lines[0]}"); @@ -27,7 +37,7 @@ static void Main(string[] args) var parser = new TacoParser(); // Grab an IEnumerable of locations using the Select command: var locations = lines.Select(parser.Parse); - var locations = lines.Select(parser.Parse).ToArray(); + var locations = lines.Select(line => parser.Parse(line)).ToArray(); // DON'T FORGET TO LOG YOUR STEPS @@ -36,24 +46,50 @@ static void Main(string[] args) // TODO: Create two `ITrackable` variables with initial values of `null`. These will be used to store your two taco bells that are the farthest from each other. // Create a `double` variable to store the distance - // Include the Geolocation toolbox, so you can compare locations: `using GeoCoordinatePortable;` - - //HINT NESTED LOOPS SECTION--------------------- - // Do a loop for your locations to grab each location as the origin (perhaps: `locA`) - - // Create a new corA Coordinate with your locA's lat and long - - // Now, do another loop on the locations with the scope of your first loop, so you can grab the "destination" location (perhaps: `locB`) - - // Create a new Coordinate with your locB's lat and long - - // Now, compare the two using `.GetDistanceTo()`, which returns a double - // If the distance is greater than the currently saved distance, update the distance and the two `ITrackable` variables you set above - - // Once you've looped through everything, you've found the two Taco Bells farthest away from each other. - - - + ITrackable tacoBell1 = null; + ITrackable tacoBell2 = null; + double distance = 0; + + // Include the Geolocation toolbox, so you can compare locations: `using GeoCoordinatePortable;` + + //HINT NESTED LOOPS SECTION--------------------- + for (int i = 0; i < locations.Length; i++) + { + // Do a loop for your locations to grab each location as the origin (perhaps: `locA`) + var locA = locations[i]; + + // Create a new corA Coordinate with your locA's lat and long + var corA = new GeoCoordinate(); + corA.Latitude = locA.Location.Latitude; + corA.Longitude = locA.Location.Longitude; + + // Now, do another loop on the locations with the scope of your first loop, so you can grab the "destination" location (perhaps: `locB`) + for (int j = 0; j < locations.Length; j++) + { + var locB = locations[j ]; + + // Create a new corA Coordinate with your locA's lat and long + var corB = new GeoCoordinate(); + corB.Latitude = locB.Location.Latitude; + corB.Longitude = locB.Location.Longitude; + // Create a new Coordinate with your locB's lat and long + + // Now, compare the two using `.GetDistanceTo()`, which returns a double + // If the distance is greater than the currently saved distance, update the distance and the two `ITrackable` variables you set above + if (corA.GetDistanceTo(corB) > distance) + { + distance = corA.GetDistanceTo(corB); + tacoBell1 = locA; + tacoBell2 = locB; + } + } + + } + + // Once you've looped through everything, you've found the two Taco Bells farthest away from each other. + + logger.LogInfo($"{tacoBell1.Name} and {tacoBell2.Name} are the farthest apart"); + } } } diff --git a/LoggingKata/TacoBell-US-AL.csv b/LoggingKata/TacoBell-US-AL.csv old mode 100755 new mode 100644 index 93a25aaf..4c8787a0 --- a/LoggingKata/TacoBell-US-AL.csv +++ b/LoggingKata/TacoBell-US-AL.csv @@ -1,4 +1,4 @@ -34.073638,-84.677017,Taco Bell Acwort... + 34.073638,-84.677017,Taco Bell Acwort... 34.035985,-84.683302,Taco Bell Acworth... 34.087508,-84.575512,Taco Bell Acworth... 34.376395,-84.913185,Taco Bell Adairsvill... diff --git a/LoggingKata/TacoBell.cs b/LoggingKata/TacoBell.cs new file mode 100644 index 00000000..881a4175 --- /dev/null +++ b/LoggingKata/TacoBell.cs @@ -0,0 +1,15 @@ +using System; +namespace LoggingKata +{ + public class TacoBell : ITrackable + { + public TacoBell() + { + } + + public string Name { get; set; } + public Point Location { get; set; } + + } +} + diff --git a/LoggingKata/TacoParser.cs b/LoggingKata/TacoParser.cs index a8690c99..9e2c71fb 100644 --- a/LoggingKata/TacoParser.cs +++ b/LoggingKata/TacoParser.cs @@ -6,39 +6,34 @@ public class TacoParser { readonly ILog logger = new TacoLogger(); - + public ITrackable Parse(string line) { logger.LogInfo("Begin parsing"); - // Take your line and use line.Split(',') to split it up into an array of strings, separated by the char ',' var cells = line.Split(','); - // If your array.Length is less than 3, something went wrong if (cells.Length < 3) { // Log that and return null + logger.LogWarning("less than three items. Incomplete data"); // Do not fail if one record parsing fails, return null return null; // TODO Implement } - // grab the latitude from your array at index 0 - // grab the longitude from your array at index 1 - // grab the name from your array at index 2 + var latitude = double.Parse(cells[0]); + var longitude = double.Parse(cells[1]); + var name = cells[2]; - // Your going to need to parse your string as a `double` - // which is similar to parsing a string as an `int` + var point = new Point(); + point.Latitude = latitude; + point.Longitude = longitude; - // You'll need to create a TacoBell class - // that conforms to ITrackable + var tacoBell = new TacoBell(); + tacoBell.Name = name; + tacoBell.Location = point; - // Then, you'll need an instance of the TacoBell class - // With the name and point set correctly - - // Then, return the instance of your TacoBell class - // Since it conforms to ITrackable - - return null; + return tacoBell; } } } \ No newline at end of file