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
51 changes: 41 additions & 10 deletions LoggingKata.Test/TacoParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,75 @@
using System;
using System.Collections.Generic;
using Xunit;


namespace LoggingKata.Test
{
public class TacoParserTests
{
private IEnumerable<object> expected;
private object line;
private object tacoParserInstance;


[Fact]
public void ShouldReturnNonNullObject()
{
//Arrange
var tacoParser = new TacoParser();
//Arrange -write the code we need in order to call the method we're testing
var tacoParserInstance = new TacoParser();

//Act
var actual = tacoParser.Parse("34.073638, -84.677017, Taco Bell Acwort...");

var actual = tacoParserInstance.Parse("34.073638, -84.677017, Taco Bell Acwort...");
//Assert
Assert.NotNull(actual);

}

[Theory]
[InlineData("34.073638, -84.677017, Taco Bell Acwort...", -84.677017)]
[InlineData("34.073638, -84.677017, Taco Bell Acwort...", 34.073638)]
[InlineData("30.39371,-87.68332,Taco Bell Fole...", 30.39371)]
[InlineData("34.8831,-84.293899,Taco Bell Blue Ridg...", 34.8831)]
[InlineData("32.571331,-85.499655,Taco Bell Auburn...", 32.571331)]


//Add additional inline data. Refer to your CSV file.
public void ShouldParseLongitude(string line, double expected)
public void ShouldParseLat(string line, double expected)
{
// TODO: Complete the test with Arrange, Act, Assert steps below.
// Done: Complete the test with Arrange, Act, Assert steps below.
// Note: "line" string represents input data we will Parse
// to extract the Longitude.
// Each "line" from your .csv file
// represents a TacoBell location

//Arrange
//Arrange - write the code we need in order to call the method we're testing
var tacoParserInstance = new TacoParser();

//Act

var actual = tacoParserInstance.Parse(line);
//Assert
Assert.Equal(expected, actual.Location.Latitude);
}




//TODO: Create a test called ShouldParseLatitude
//Done: Create a test called ShouldParseLongitude
public void ShouldParseLong(string line, double expected)
{
//Arrange - write the code we need in order to call the method we're testing
var tacoParserInstance = new TacoParser();

//Act
var actual = tacoParserInstance.Parse(line);
//Assert
Assert.Equal(expected, actual.Location.Longitude);






}
}
}
88 changes: 65 additions & 23 deletions LoggingKata/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
using System.Linq;
using System.IO;
using GeoCoordinatePortable;
using System.Collections.Generic;

namespace LoggingKata
{
class Program
{
static readonly ILog logger = new TacoLogger();
private static ITrackable locB;
private static GeoCoordinate corB;
private static double distance;
const string csvPath = "TacoBell-US-AL.csv";

static void Main(string[] args)
Expand All @@ -19,7 +23,20 @@ static void Main(string[] args)

// Use File.ReadAllLines(path) to grab all the lines from your csv file.
// Optional: Log an error if you get 0 lines and a warning if you get 1 line
var lines = File.ReadAllLines(csvPath);
string[] 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");

}



// This will display the first item in your lines array
logger.LogInfo($"Lines: {lines[0]}");
Expand All @@ -28,45 +45,70 @@ static void Main(string[] args)
var parser = new TacoParser();

// Use the Select LINQ method to parse every line in lines collection
var locations = lines.Select(parser.Parse).ToArray();
var locations = lines.Select(line => parser.Parse(line)).ToArray();


// Complete the Parse method in TacoParser class first and then START BELOW ----------

// TODO: Create two `ITrackable` variables with initial values of `null`.
// Done: 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.

// TODO: Create a `double` variable to store the distance

// TODO: Add the Geolocation library to enable location comparisons: using GeoCoordinatePortable;
// Look up what methods you have access to within this library.
// Done: Create a `double` variable to store the distance

ITrackable tacoBell1 = null;
ITrackable tacoBell2 = null;
double distant = 0;


// Done: Add the Geolocation library to enable location comparisons: using GeoCoordinatePortable;

// NESTED LOOPS SECTION----------------------------

// FIRST FOR LOOP -
// TODO: Create a loop to go through each item in your collection of locations.
// This loop will let you select one location at a time to act as the "starting point" or "origin" location.
// Naming suggestion for variable: `locA`

// TODO: Once you have locA, create a new Coordinate object called `corA` with your locA's latitude and longitude.

// SECOND FOR LOOP -
// TODO: Now, Inside the scope of your first loop, create another loop to iterate through locations again.
// This allows you to pick a "destination" location for each "origin" location from the first loop.
// Naming suggestion for variable: `locB`
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" loca
for (int j = 0; j < locations.Length; j++)
{
// Create a new Coordinate with your locB's lat and long

// Now, compare the two using '.GetDistanceTo()', which returns a double

var locB = locations[j];
var corB = new GeoCoordinate();
corB.Latitude = locB.Location.Latitude;
corB.Longitude = locB.Location.Longitude;

if (corA.GetDistanceTo(corB) > distance)
{
distant = corA.GetDistanceTo(corB);
tacoBell1 = locA;
tacoBell2 = locB;

}
}


// Now, compare the two using '.GetDistanceTo()', which returns a double

// TODO: Once you have locB, create a new Coordinate object called `corB` with your locB's latitude and longitude.
// If the distance is greater than the currently saved distance, update the distance and the two 'ITrackable' vari

// TODO: Now, still being inside the scope of the second for loop, compare the two locations using `.GetDistanceTo()` method, which returns a double.
// If the distance is greater than the currently saved distance, update the distance variable and the two `ITrackable` variables you set above.
}

// NESTED LOOPS SECTION COMPLETE ---------------------

// Once you've looped through everything, you've found the two Taco Bells farthest away from each other.
// Display these two Taco Bell locations to the console.

logger.LogInfo($"{tacoBell1.Name} and {tacoBell2.Name} are the farthest apart");


}
}
}
}
26 changes: 26 additions & 0 deletions LoggingKata/TacoBell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LoggingKata
{
public class TacoBell : ITrackable
{
public TacoBell()
{
}

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




}




}
57 changes: 37 additions & 20 deletions LoggingKata/TacoParser.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
namespace LoggingKata
using System;
using System.Net.Http.Headers;

namespace LoggingKata
{
/// <summary>
/// Parses a POI file to locate all the Taco Bells
/// </summary>
public class TacoParser
{
readonly ILog logger = new TacoLogger();

public ITrackable Parse(string line)
{
logger.LogInfo("Begin parsing");
Expand All @@ -18,35 +21,49 @@ public ITrackable Parse(string line)
if (cells.Length < 3)
{
// Log error message and return null
return null;
logger.LogWarning("less than three items. incomplete data");
}

// TODO: Grab the latitude from your array at index 0
// grab the latitude from your array at index 0
var latitude = double.Parse(cells[0]);
// You're going to need to parse your string as a `double`
// which is similar to parsing a string as an `int`


// TODO: Grab the longitude from your array at index 1
// You're going to need to parse your string as a `double`


// grab the longitude from your array at index 1
var longitude = double.Parse(cells[1]);

// Done You're going to need to parse your string as a `double`
// which is similar to parsing a string as an `int`


// TODO: Grab the name from your array at index 2


// TODO: Create a TacoBell class

// grab the name from your array at index 2
var name = cells[2];


// Done: Create a TacoBell class
// that conforms to ITrackable

// TODO: Create an instance of the Point Struct
// TODO: Set the values of the point correctly (Latitude and Longitude)

// TODO: Create an instance of the TacoBell class
// TODO: Set the values of the class correctly (Name and Location)

// TODO: Then, return the instance of your TacoBell class,
// Done: Create an instance of the Point Struct
// Done: Set the values of the point correctly (Latitude and Longitude)

// DOne: Create an instance of the TacoBell class
// Done: Set the values of the class correctly (Name and Location)
var point = new Point();
point.Latitude = latitude;
point.Longitude = longitude;

var tacoBell = new TacoBell();
tacoBell.Name = name;
tacoBell.Location = point;

// Done: Then, return the instance of your TacoBell class,
// since it conforms to ITrackable

return null;
return tacoBell;
}


}
}