Skip to content

Commit

Permalink
Merge pull request #15 from RichardVasquez/3.7.2
Browse files Browse the repository at this point in the history
Added code to match 3.7.2 and new unit tests.
  • Loading branch information
RichardVasquez authored Aug 30, 2021
2 parents 37b8c17 + 692b67c commit 87d0a59
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions H3Lib/Extensions/BaseCellsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;

namespace H3Lib.Extensions
Expand All @@ -16,6 +17,10 @@ public static class BaseCellsExtensions
/// -->
public static bool IsBaseCellPentagon(this int baseCell)
{
if (baseCell < 0 || baseCell >= Constants.H3.NUM_BASE_CELLS)
{
return false;
}
return Constants.BaseCells.BaseCellData[baseCell].IsPentagon == 1;
}

Expand Down
8 changes: 7 additions & 1 deletion H3Lib/Extensions/H3IndexExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,13 @@ public static (H3Index, int) NeighborRotations(this H3Index origin, Direction di

Direction oldDigit = outHex.GetIndexDigit(r + 1);
Direction nextDir;


if (oldDigit == Direction.INVALID_DIGIT)
{
// only possible on invalid input
return (Constants.H3Index.H3_NULL, outRotations);
}

if((r+1).IsResClassIii())
{
outHex = outHex.SetIndexDigit
Expand Down
1 change: 1 addition & 0 deletions Tests/NUnit/H3Suite/H3Suite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<ItemGroup>
<PackageReference Include="DecimalMath.DecimalEx" Version="1.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="nunit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
Expand Down
18 changes: 18 additions & 0 deletions Tests/NUnit/H3Suite/TestKRing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,25 @@ public void ClockwiseOffsetPent()
);
}
}
}

[Test]
public void KRingInvalid()
{
var badCell = new H3Index(0x7fffffffffffffff);
var k = 1000;

badCell.KRing(k);
// Assertion is should not crash - should return an error in the future
}

[Test]
public void KRingInvalidDigit()
{
var k = 2;
var badCell = new H3Index(0x4d4b00fe5c5c3030);
badCell.KRing(k);
// Assertion is should not crash - should return an error in the future
}

}
Expand Down

0 comments on commit 87d0a59

Please sign in to comment.