From b1b87f6a0a27c35bed79a6f65f9c039039870f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CBaruc?= <“bdotgo@hotmail.comgit config --global user.email “bdotgo@hotmail.com> Date: Sun, 25 Sep 2022 21:35:59 -0500 Subject: [PATCH 1/2] working state --- LoggingKata.Test/LoggingKata.Test.sln | 25 +++++++++++++++++++++ LoggingKata.Test/TacoParserTests.cs | 29 ++++++++++++++++++++++--- LoggingKata/ILog.cs | 2 ++ LoggingKata/ITrackable.cs | 5 +++-- LoggingKata/LoggingKata.sln | 31 +++++++++++++++++++++++++++ LoggingKata/Program.cs | 2 +- LoggingKata/TacoBell-US-AL.csv | 2 +- LoggingKata/TacoBell.cs | 15 +++++++++++++ LoggingKata/TacoParser.cs | 21 ++++++++++++++---- 9 files changed, 121 insertions(+), 11 deletions(-) create mode 100644 LoggingKata.Test/LoggingKata.Test.sln mode change 100755 => 100644 LoggingKata/ILog.cs mode change 100755 => 100644 LoggingKata/ITrackable.cs create mode 100644 LoggingKata/LoggingKata.sln mode change 100755 => 100644 LoggingKata/TacoBell-US-AL.csv create mode 100644 LoggingKata/TacoBell.cs 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..4e5f2e01 100644 --- a/LoggingKata.Test/TacoParserTests.cs +++ b/LoggingKata.Test/TacoParserTests.cs @@ -29,15 +29,38 @@ 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 + //Arrange - write the code we need in order to call the method we're testing + var tacoParserInstance = new TacoParser(); - //Act + //Parse method is located inside of the TacoParser class + //var tester = new TacoParser(); - //Assert + //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...", -84.677017)] + //public void ShouldParseLongitude(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 + //} + + } } 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..1af45fb0 100644 --- a/LoggingKata/Program.cs +++ b/LoggingKata/Program.cs @@ -27,7 +27,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 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..da78c20d 100644 --- a/LoggingKata/TacoParser.cs +++ b/LoggingKata/TacoParser.cs @@ -6,7 +6,8 @@ public class TacoParser { readonly ILog logger = new TacoLogger(); - + + // interface method name public ITrackable Parse(string line) { logger.LogInfo("Begin parsing"); @@ -18,27 +19,39 @@ public ITrackable Parse(string line) 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 + var latitude = double.Parse(cells[0]); // grab the longitude from your array at index 1 + var longitude = double.Parse(cells[1]); // grab the name from your array at index 2 + var name = cells[2]; - // Your going to need to parse your string as a `double` + // Done - Your going to need to parse your string as a `double` // which is similar to parsing a string as an `int` - // You'll need to create a TacoBell class + // Done - You'll need to create a TacoBell class // that conforms to ITrackable // Then, you'll need an instance of the TacoBell class // With the name and point set correctly + var point = new Point(); + point.Latitude = latitude; + point.Longitude = longitude; + + var tacoBell = new TacoBell(); + tacoBell.Name = name; + tacoBell.Location = point; + // Then, return the instance of your TacoBell class // Since it conforms to ITrackable - return null; + return tacoBell; } } } \ No newline at end of file From 4092d3b4aed47b0cd9168ef445bc80ba1464b44a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CBaruc?= <“bdotgo@hotmail.comgit config --global user.email “bdotgo@hotmail.com> Date: Sun, 25 Sep 2022 23:01:13 -0500 Subject: [PATCH 2/2] completed --- LoggingKata.Test/TacoParserTests.cs | 33 ++++++++----- LoggingKata/Program.cs | 74 +++++++++++++++++++++-------- LoggingKata/TacoParser.cs | 18 ------- 3 files changed, 77 insertions(+), 48 deletions(-) diff --git a/LoggingKata.Test/TacoParserTests.cs b/LoggingKata.Test/TacoParserTests.cs index 4e5f2e01..0cf72017 100644 --- a/LoggingKata.Test/TacoParserTests.cs +++ b/LoggingKata.Test/TacoParserTests.cs @@ -46,20 +46,31 @@ public void ShouldParseLongitude(string line, double expected) //TODO: Create a test ShouldParseLatitude - //[Theory] - //[InlineData("34.073638, -84.677017, Taco Bell Acwort...", -84.677017)] - //public void ShouldParseLongitude(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 + [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 + //Arrange + + //Act - // //Act + //Assert + var tacoParserInstance = new TacoParser(); - // //Assert - //} + //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); + } } diff --git a/LoggingKata/Program.cs b/LoggingKata/Program.cs index 1af45fb0..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]}"); @@ -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/TacoParser.cs b/LoggingKata/TacoParser.cs index da78c20d..9e2c71fb 100644 --- a/LoggingKata/TacoParser.cs +++ b/LoggingKata/TacoParser.cs @@ -7,15 +7,12 @@ public class TacoParser { readonly ILog logger = new TacoLogger(); - // interface method name 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 @@ -24,21 +21,10 @@ public ITrackable Parse(string line) return null; // TODO Implement } - // grab the latitude from your array at index 0 var latitude = double.Parse(cells[0]); - // grab the longitude from your array at index 1 var longitude = double.Parse(cells[1]); - // grab the name from your array at index 2 var name = cells[2]; - // Done - Your going to need to parse your string as a `double` - // which is similar to parsing a string as an `int` - - // Done - You'll need to create a TacoBell class - // that conforms to ITrackable - - // Then, you'll need an instance of the TacoBell class - // With the name and point set correctly var point = new Point(); point.Latitude = latitude; point.Longitude = longitude; @@ -47,10 +33,6 @@ public ITrackable Parse(string line) tacoBell.Name = name; tacoBell.Location = point; - - // Then, return the instance of your TacoBell class - // Since it conforms to ITrackable - return tacoBell; } }