Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions LoggingKata.Test/LoggingKata.Test.sln
Original file line number Diff line number Diff line change
@@ -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
38 changes: 36 additions & 2 deletions LoggingKata.Test/TacoParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
}
2 changes: 2 additions & 0 deletions LoggingKata/ILog.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ public interface ILog
void LogDebug(string log);
}
}

//stubbed out methods
5 changes: 3 additions & 2 deletions LoggingKata/ITrackable.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
{
public interface ITrackable
{
string Name { get; set; }
string Name { get; set; } //property
Point Location { get; set; }
}
}
}
//interfaces specify behavior
31 changes: 31 additions & 0 deletions LoggingKata/LoggingKata.sln
Original file line number Diff line number Diff line change
@@ -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
76 changes: 56 additions & 20 deletions LoggingKata/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,29 @@ 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]}");

// Create a new instance of your TacoParser class
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

Expand All @@ -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");

}
}
}
2 changes: 1 addition & 1 deletion LoggingKata/TacoBell-US-AL.csv
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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...
Expand Down
15 changes: 15 additions & 0 deletions LoggingKata/TacoBell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
namespace LoggingKata
{
public class TacoBell : ITrackable
{
public TacoBell()
{
}

public string Name { get; set; }
public Point Location { get; set; }

}
}

29 changes: 12 additions & 17 deletions LoggingKata/TacoParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}