Skip to content
Merged
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ AppyWay geojson model and json serialization converters.

| Package | Latest Stable |
| --- | --- |
| [Appy.Spatial.GeoJSON](https://www.nuget.org/packages/Appy.Spatial.GeoJSON) | [![Nuget Package](https://img.shields.io/badge/nuget-2.0.0-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON) |
| [Appy.Spatial.GeoJSON.Newtonsoft](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.Newtonsoft) | [![Nuget Package](https://img.shields.io/badge/nuget-2.0.0-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.Newtonsoft) |
| [Appy.Spatial.GeoJSON.TextJson](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.TextJson) | [![Nuget Package](https://img.shields.io/badge/nuget-2.0.0-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.TextJson) |
| [Appy.Spatial.GeoJSON](https://www.nuget.org/packages/Appy.Spatial.GeoJSON) | [![Nuget Package](https://img.shields.io/badge/nuget-2.0.1-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON) |
| [Appy.Spatial.GeoJSON.Newtonsoft](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.Newtonsoft) | [![Nuget Package](https://img.shields.io/badge/nuget-2.0.1-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.Newtonsoft) |
| [Appy.Spatial.GeoJSON.TextJson](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.TextJson) | [![Nuget Package](https://img.shields.io/badge/nuget-2.0.1-blue.svg)](https://www.nuget.org/packages/Appy.Spatial.GeoJSON.TextJson) |

## Supported frameworks

Expand Down
60 changes: 60 additions & 0 deletions src/Appy.Spatial.GeoJSON.Tests/LatLngComparerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using FluentAssertions;
using Xunit;

namespace Appy.Spatial.GeoJSON.Tests;

public class LatLngComparerTests
{
readonly LatLngComparer _comparer = new();

[Fact]
public void ShouldBeEqualWhenCoordinatesMatch()
{
var x = new LatLng { Latitude = 51.5, Longitude = -0.12 };
var y = new LatLng { Latitude = 51.5, Longitude = -0.12 };

_comparer.Equals(x, y).Should().BeTrue();
_comparer.GetHashCode(x).Should().Be(_comparer.GetHashCode(y));
}

[Fact]
public void ShouldNotBeEqualWhenLatitudeDiffers()
{
var x = new LatLng { Latitude = 51.5, Longitude = -0.12 };
var y = new LatLng { Latitude = 52.5, Longitude = -0.12 };

_comparer.Equals(x, y).Should().BeFalse();
}

[Fact]
public void ShouldNotBeEqualWhenLongitudeDiffers()
{
var x = new LatLng { Latitude = 51.5, Longitude = -0.12 };
var y = new LatLng { Latitude = 51.5, Longitude = 1.5 };

_comparer.Equals(x, y).Should().BeFalse();
}

[Fact]
public void ShouldNotBeEqualWhenOtherLongitudeMatchesLatitude()
{
// Regression: longitude was compared against the other point's latitude
var x = new LatLng { Latitude = 10, Longitude = 10 };
var y = new LatLng { Latitude = 10, Longitude = 20 };

_comparer.Equals(x, y).Should().BeFalse();
}

[Fact]
public void ShouldBeEqualWhenBothNull() =>
_comparer.Equals(null, null).Should().BeTrue();

[Fact]
public void ShouldNotBeEqualWhenOneIsNull()
{
var x = new LatLng { Latitude = 51.5, Longitude = -0.12 };

_comparer.Equals(x, null).Should().BeFalse();
_comparer.Equals(null, x).Should().BeFalse();
}
}
2 changes: 1 addition & 1 deletion src/Appy.Spatial.GeoJSON/LatLng.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class LatLngComparer : IEqualityComparer<LatLng>
{
public bool Equals(LatLng x, LatLng y) =>
x == null && y == null ||
x != null && y != null && x.Latitude.Equals(y.Latitude) && x.Longitude.Equals(y.Latitude);
x != null && y != null && x.Latitude.Equals(y.Latitude) && x.Longitude.Equals(y.Longitude);

public int GetHashCode(LatLng obj) =>
obj.Latitude.GetHashCode() +
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup Label="Package Validation" Condition="'$(IsPackable)' != 'false'">
<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>2.0.0</PackageValidationBaselineVersion>
<PackageValidationBaselineVersion>2.0.1</PackageValidationBaselineVersion>
</PropertyGroup>

<!-- MinVer sets the version just before GenerateNuspec; run it before NuGet computes the package
Expand Down
Loading