Skip to content

Commit

Permalink
Ran csharpier
Browse files Browse the repository at this point in the history
  • Loading branch information
sibartlett committed Oct 2, 2024
1 parent e4c37bc commit dbf4789
Show file tree
Hide file tree
Showing 200 changed files with 7,323 additions and 1,472 deletions.
82 changes: 61 additions & 21 deletions Geo.Tests/CoordinateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,80 @@ public void Parse(string coordinate, double latitude, double longitude)
[Fact]
public void Equality_Elevation()
{
Assert.True(new CoordinateZ(0, 0, 0).Equals(new CoordinateZ(0, 0, 0),
new SpatialEqualityOptions { UseElevation = true }));
Assert.False(new CoordinateZ(0, 0, 0).Equals(new CoordinateZ(0, 0, 10),
new SpatialEqualityOptions { UseElevation = true }));
Assert.True(new CoordinateZ(0, 0, 0).Equals(new CoordinateZ(0, 0, 10),
new SpatialEqualityOptions { UseElevation = false }));
Assert.True(
new CoordinateZ(0, 0, 0).Equals(
new CoordinateZ(0, 0, 0),
new SpatialEqualityOptions { UseElevation = true }
)
);
Assert.False(
new CoordinateZ(0, 0, 0).Equals(
new CoordinateZ(0, 0, 10),
new SpatialEqualityOptions { UseElevation = true }
)
);
Assert.True(
new CoordinateZ(0, 0, 0).Equals(
new CoordinateZ(0, 0, 10),
new SpatialEqualityOptions { UseElevation = false }
)
);
}

[Fact]
public void Equality_M()
{
Assert.True(new CoordinateZM(0, 0, 0, 0).Equals(new CoordinateZM(0, 0, 0, 0),
new SpatialEqualityOptions { UseM = true }));
Assert.False(new CoordinateZM(0, 0, 0, 0).Equals(new CoordinateZM(0, 0, 0, 10),
new SpatialEqualityOptions { UseM = true }));
Assert.True(new CoordinateZM(0, 0, 0, 0).Equals(new CoordinateZM(0, 0, 0, 10),
new SpatialEqualityOptions { UseM = false }));
Assert.True(
new CoordinateZM(0, 0, 0, 0).Equals(
new CoordinateZM(0, 0, 0, 0),
new SpatialEqualityOptions { UseM = true }
)
);
Assert.False(
new CoordinateZM(0, 0, 0, 0).Equals(
new CoordinateZM(0, 0, 0, 10),
new SpatialEqualityOptions { UseM = true }
)
);
Assert.True(
new CoordinateZM(0, 0, 0, 0).Equals(
new CoordinateZM(0, 0, 0, 10),
new SpatialEqualityOptions { UseM = false }
)
);
}

[Fact]
public void Equality_PoleCoordinates()
{
Assert.True(new CoordinateZM(90, 0, 0, 0).Equals(new CoordinateZM(90, 180, 0, 0),
new SpatialEqualityOptions { PoleCoordiantesAreEqual = true }));
Assert.False(new CoordinateZM(90, 0, 0, 0).Equals(new CoordinateZM(90, 180, 0, 0),
new SpatialEqualityOptions { PoleCoordiantesAreEqual = false }));
Assert.True(
new CoordinateZM(90, 0, 0, 0).Equals(
new CoordinateZM(90, 180, 0, 0),
new SpatialEqualityOptions { PoleCoordiantesAreEqual = true }
)
);
Assert.False(
new CoordinateZM(90, 0, 0, 0).Equals(
new CoordinateZM(90, 180, 0, 0),
new SpatialEqualityOptions { PoleCoordiantesAreEqual = false }
)
);
}

[Fact]
public void Equality_AntiMeridianCoordinates()
{
Assert.True(new Coordinate(4, 180).Equals(new Coordinate(4, -180),
new SpatialEqualityOptions { AntiMeridianCoordinatesAreEqual = true }));
Assert.False(new Coordinate(4, 180).Equals(new Coordinate(4, -180),
new SpatialEqualityOptions { AntiMeridianCoordinatesAreEqual = false }));
Assert.True(
new Coordinate(4, 180).Equals(
new Coordinate(4, -180),
new SpatialEqualityOptions { AntiMeridianCoordinatesAreEqual = true }
)
);
Assert.False(
new Coordinate(4, 180).Equals(
new Coordinate(4, -180),
new SpatialEqualityOptions { AntiMeridianCoordinatesAreEqual = false }
)
);
}
}
}
66 changes: 53 additions & 13 deletions Geo.Tests/Geodesy/SpheroidCalculatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,54 +31,94 @@ public void MeridionalDistance(double latitude, double parts)

[Theory]
[InlineData(0, 0, 10, 10, 845.100058)]
public void CalculateLoxodromicLineDistance(double lat1, double lon1, double lat2, double lon2, double distance)
public void CalculateLoxodromicLineDistance(
double lat1,
double lon1,
double lat2,
double lon2,
double distance
)
{
var calculator = new SpheroidCalculator(Spheroid.Wgs84);
var result = calculator.CalculateLoxodromicLine(new Point(lat1, lon1), new Point(lat2, lon2));
var result = calculator.CalculateLoxodromicLine(
new Point(lat1, lon1),
new Point(lat2, lon2)
);
Assert.Equal(distance, result.Distance.ConvertTo(DistanceUnit.Nm).Value, Millionth);
}

[Theory]
[InlineData(0, 0, 10, 10, 45.044293)]
public void CalculateLoxodromicCourse(double lat1, double lon1, double lat2, double lon2, double distance)
public void CalculateLoxodromicCourse(
double lat1,
double lon1,
double lat2,
double lon2,
double distance
)
{
var calculator = new SpheroidCalculator(Spheroid.Wgs84);
var result = calculator.CalculateLoxodromicLine(new Point(lat1, lon1), new Point(lat2, lon2));
var result = calculator.CalculateLoxodromicLine(
new Point(lat1, lon1),
new Point(lat2, lon2)
);
Assert.Equal(distance, result.Bearing12, Millionth);
}

[Theory]
[InlineData(0, 0, 10, 10, 44.751910, 225.629037)]
public void CalculateOrthodromicCourse(double lat1, double lon1, double lat2, double lon2, double c12, double c21)
public void CalculateOrthodromicCourse(
double lat1,
double lon1,
double lat2,
double lon2,
double c12,
double c21
)
{
var calculator = new SpheroidCalculator(Spheroid.Wgs84);
var result = calculator.CalculateOrthodromicLine(new Point(lat1, lon1), new Point(lat2, lon2));
var result = calculator.CalculateOrthodromicLine(
new Point(lat1, lon1),
new Point(lat2, lon2)
);
Assert.Equal(c12, result.Bearing12, Millionth);
Assert.Equal(c21, result.Bearing21, Millionth);
}

[Theory]
[InlineData(0, 0, 56, 34, 0.318436, 0.468951)]
[InlineData(-9.443333, 147.216667, 327.912522, 50, -8.733717, 146.769644)]
public void CalculateOrthodromicDestination(double lat1, double lon1, double angle, double distance, double lat2,
double lon2)
public void CalculateOrthodromicDestination(
double lat1,
double lon1,
double angle,
double distance,
double lat2,
double lon2
)
{
var calculator = new SpheroidCalculator(Spheroid.Wgs84);
var result = calculator.CalculateOrthodromicLine(new Point(lat1, lon1), angle,
new Distance(distance, DistanceUnit.Nm).SiValue);
var result = calculator.CalculateOrthodromicLine(
new Point(lat1, lon1),
angle,
new Distance(distance, DistanceUnit.Nm).SiValue
);
Assert.Equal(lat2, result.Coordinate2.Latitude, Millionth);
Assert.Equal(lon2, result.Coordinate2.Longitude, Millionth);
}

[Theory(Skip = "Need to re-visit")]
[InlineData(30, 175, -30, -3.5)]
[InlineData(30, 176, -30, -3.5)]
public void Bug7(double lat1, double lon1, double lat2, double lon2)
{
var calculator = new SpheroidCalculator(Spheroid.Wgs84);
var result = calculator.CalculateOrthodromicLine(new Point(lat1, lon1), new Point(lat2, lon2));
var result = calculator.CalculateOrthodromicLine(
new Point(lat1, lon1),
new Point(lat2, lon2)
);
Console.WriteLine(result.Distance);
Console.WriteLine(result.Bearing12);
Console.WriteLine(result.Bearing21);
}
}
}
2 changes: 1 addition & 1 deletion Geo.Tests/Geomagnetism/GeomagnetismCalculatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public void Test()
var b = a.TryCalculate(new Coordinate(51.8, -0.15), DateTime.UtcNow.Date);
Console.WriteLine(b);
}
}
}
3 changes: 1 addition & 2 deletions Geo.Tests/Geometries/CircleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ public void An_60Degree_CircleWith_111000M_RadiusShouldBeAboutOneDegreeWide()
Assert.True(maxLonError <= 0.002);
}


public double Distance(double nr1, double nr2)
{
return Math.Abs(nr1 - nr2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ public class GarminFlightplanDeSerializerTests : SerializerTestFixtureBase
[Fact]
public void CanParse()
{
var fileInfo =
GetReferenceFileDirectory("garmin").EnumerateFiles().First(x => x.Name == "garmin.fpl");
var fileInfo = GetReferenceFileDirectory("garmin")
.EnumerateFiles()
.First(x => x.Name == "garmin.fpl");

using var stream = new FileStream(fileInfo.FullName, FileMode.Open);
var file = new GarminFlightplanDeSerializer().DeSerialize(new StreamWrapper(stream));

Assert.NotNull(file);
Assert.Single(file.Routes);
Assert.Equal(5, file.Routes[0].Waypoints.Count);
}
}
}
2 changes: 1 addition & 1 deletion Geo.Tests/Gps/Serialization/GpsDeSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public void ImageFileTest()

Assert.Null(data);
}
}
}
14 changes: 9 additions & 5 deletions Geo.Tests/Gps/Serialization/GpxSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ private void Compare(Gpx11Serializer serializer, GpsData data, string gpxData)
private void Compare(GpsData data, GpsData data2)
{
Assert.Equal(data.Metadata.Count, data2.Metadata.Count);
foreach (var entry in data.Metadata) Assert.Equal(entry.Value, data2.Metadata[entry.Key]);
foreach (var entry in data.Metadata)
Assert.Equal(entry.Value, data2.Metadata[entry.Key]);

Assert.Equal(data.Tracks.Count, data2.Tracks.Count);
for (var i = 0; i < data.Tracks.Count; i++)
Expand All @@ -70,7 +71,8 @@ private void Compare(GpsData data, GpsData data2)
var track2 = data2.Tracks[i];

Assert.Equal(track1.Metadata.Count, track2.Metadata.Count);
foreach (var entry in track1.Metadata) Assert.Equal(entry.Value, track2.Metadata[entry.Key]);
foreach (var entry in track1.Metadata)
Assert.Equal(entry.Value, track2.Metadata[entry.Key]);

Assert.Equal(track1.Segments.Count, track2.Segments.Count);
for (var s = 0; s < track1.Segments.Count; s++)
Expand Down Expand Up @@ -109,10 +111,12 @@ private void Compare(GpsData data, GpsData data2)
var r2 = data2.Routes[i];

Assert.Equal(r1.Metadata.Count, r2.Metadata.Count);
foreach (var entry in r1.Metadata) Assert.Equal(entry.Value, r2.Metadata[entry.Key]);
foreach (var entry in r1.Metadata)
Assert.Equal(entry.Value, r2.Metadata[entry.Key]);

Assert.Equal(r1.Waypoints.Count, r2.Waypoints.Count);
for (var c = 0; c < r1.Waypoints.Count; c++) Compare(r1.Waypoints[c], r2.Waypoints[c]);
for (var c = 0; c < r1.Waypoints.Count; c++)
Compare(r1.Waypoints[c], r2.Waypoints[c]);
}
}

Expand All @@ -138,4 +142,4 @@ private static void Compare(Coordinate coord1, Coordinate coord2)
if (coord1.IsMeasured)
Assert.Equal(((IsMeasured)coord1).Measure, ((IsMeasured)coord2).Measure);
}
}
}
2 changes: 1 addition & 1 deletion Geo.Tests/Gps/Serialization/IgcDeSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ public void igc2()
Assert.Single(result.Tracks[0].Segments);
Assert.Equal(9, result.Tracks[0].Segments[0].Waypoints.Count);
}
}
}
6 changes: 4 additions & 2 deletions Geo.Tests/Gps/Serialization/NmeaDeSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public class NmeaDeSerializerTests : SerializerTestFixtureBase
[Fact]
public void Stockholm_Walk()
{
var file = GetReferenceFileDirectory("nmea").GetFiles().First(x => x.Name == "Stockholm_Walk.nmea");
var file = GetReferenceFileDirectory("nmea")
.GetFiles()
.First(x => x.Name == "Stockholm_Walk.nmea");
using var stream = new FileStream(file.FullName, FileMode.Open);
var streamWrapper = new StreamWrapper(stream);
var parser = new NmeaDeSerializer();
Expand All @@ -23,4 +25,4 @@ public void Stockholm_Walk()
Assert.Single(result.Tracks[0].Segments);
Assert.Equal(674, result.Tracks[0].Segments[0].Waypoints.Count);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ public class PocketFmsFlightplanDeSerializerTests : SerializerTestFixtureBase
[Fact]
public void CanParse()
{
var fileInfo =
GetReferenceFileDirectory("pocketfms").EnumerateFiles().First(x => x.Name == "pocketfms_fp.xml");
var fileInfo = GetReferenceFileDirectory("pocketfms")
.EnumerateFiles()
.First(x => x.Name == "pocketfms_fp.xml");

using var stream = new FileStream(fileInfo.FullName, FileMode.Open);
var file = new PocketFmsFlightplanDeSerializer().DeSerialize(new StreamWrapper(stream));
Assert.NotNull(file);
}
}
}
10 changes: 7 additions & 3 deletions Geo.Tests/Gps/Serialization/SerializerTestFixtureBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public abstract class SerializerTestFixtureBase
{
protected DirectoryInfo GetReferenceFileDirectory(params string[] subDirectories)
{
var filePath = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().Location).LocalPath);
var filePath = Path.GetDirectoryName(
new Uri(Assembly.GetExecutingAssembly().Location).LocalPath
);
filePath = Path.Combine(filePath, "..", "..");

var dir = new DirectoryInfo(filePath);
Expand All @@ -27,7 +29,9 @@ protected DirectoryInfo GetReferenceFileDirectory(params string[] subDirectories
{
foreach (var directory in subDirectories)
if (refDir != null)
refDir = refDir.EnumerateDirectories().FirstOrDefault(x => x.Name == directory);
refDir = refDir
.EnumerateDirectories()
.FirstOrDefault(x => x.Name == directory);
dir = refDir;
}

Expand All @@ -39,4 +43,4 @@ protected DirectoryInfo GetReferenceFileDirectory(params string[] subDirectories

return dir;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ public class SkyDemonFlightplanDeSerializerTests : SerializerTestFixtureBase
[Fact]
public void CanParse()
{
var fileInfo =
GetReferenceFileDirectory("skydemon").EnumerateFiles().First(x => x.Name == "skydemon.flightplan");
var fileInfo = GetReferenceFileDirectory("skydemon")
.EnumerateFiles()
.First(x => x.Name == "skydemon.flightplan");

using var stream = new FileStream(fileInfo.FullName, FileMode.Open);
var file = new SkyDemonFlightplanDeSerializer().DeSerialize(new StreamWrapper(stream));

Assert.NotNull(file);
Assert.Single(file.Routes);
Assert.Equal(4, file.Routes[0].Waypoints.Count);
}
}
}
Loading

0 comments on commit dbf4789

Please sign in to comment.