/// <summary> /// Generates a new Partition Key value for the record /// </summary> /// <returns>Partition Key value</returns> public static string GetPartitionKey(Region region) { int lat = (int)PrecisionHelper.Round(region.LatitudePrefix, 0); int lon = (int)PrecisionHelper.Round(region.LongitudePrefix, 0); return($"{lat},{lon}"); }
public void RoundTest() { Assert.AreEqual(0, PrecisionHelper.Round(0, 0)); Assert.AreEqual(0, PrecisionHelper.Round(0, 1)); Assert.AreEqual(0, PrecisionHelper.Round(0, 2)); Assert.AreEqual(0, PrecisionHelper.Round(0, 3)); Assert.AreEqual(0, PrecisionHelper.Round(0, 4)); Assert.AreEqual(0, PrecisionHelper.Round(0, 5)); Assert.AreEqual(0, PrecisionHelper.Round(0, 6)); Assert.AreEqual(0, PrecisionHelper.Round(0, 7)); Assert.AreEqual(0, PrecisionHelper.Round(0, 8)); Assert.AreEqual(0, PrecisionHelper.Round(1, 0)); Assert.AreEqual(0, PrecisionHelper.Round(1, 1)); Assert.AreEqual(0, PrecisionHelper.Round(1, 2)); Assert.AreEqual(0, PrecisionHelper.Round(1, 3)); Assert.AreEqual(0, PrecisionHelper.Round(1, 4)); Assert.AreEqual(0, PrecisionHelper.Round(1, 5)); Assert.AreEqual(0, PrecisionHelper.Round(1, 6)); Assert.AreEqual(0, PrecisionHelper.Round(1, 7)); Assert.AreEqual(1, PrecisionHelper.Round(1, 8)); Assert.AreEqual(0, PrecisionHelper.Round(-1, 0)); Assert.AreEqual(0, PrecisionHelper.Round(-1, 1)); Assert.AreEqual(0, PrecisionHelper.Round(-1, 2)); Assert.AreEqual(0, PrecisionHelper.Round(-1, 3)); Assert.AreEqual(0, PrecisionHelper.Round(-1, 4)); Assert.AreEqual(0, PrecisionHelper.Round(-1, 5)); Assert.AreEqual(0, PrecisionHelper.Round(-1, 6)); Assert.AreEqual(0, PrecisionHelper.Round(-1, 7)); Assert.AreEqual(-1, PrecisionHelper.Round(-1, 8)); Assert.AreEqual(0, PrecisionHelper.Round(37, 0)); Assert.AreEqual(0, PrecisionHelper.Round(37, 1)); Assert.AreEqual(0, PrecisionHelper.Round(37, 2)); Assert.AreEqual(32, PrecisionHelper.Round(37, 3)); Assert.AreEqual(32, PrecisionHelper.Round(37, 4)); Assert.AreEqual(32, PrecisionHelper.Round(37, 5)); Assert.AreEqual(36, PrecisionHelper.Round(37, 6)); Assert.AreEqual(36, PrecisionHelper.Round(37, 7)); Assert.AreEqual(37, PrecisionHelper.Round(37, 8)); Assert.AreEqual(0, PrecisionHelper.Round(-37, 0)); Assert.AreEqual(0, PrecisionHelper.Round(-37, 1)); Assert.AreEqual(0, PrecisionHelper.Round(-37, 2)); Assert.AreEqual(-32, PrecisionHelper.Round(-37, 3)); Assert.AreEqual(-32, PrecisionHelper.Round(-37, 4)); Assert.AreEqual(-32, PrecisionHelper.Round(-37, 5)); Assert.AreEqual(-36, PrecisionHelper.Round(-37, 6)); Assert.AreEqual(-36, PrecisionHelper.Round(-37, 7)); Assert.AreEqual(-37, PrecisionHelper.Round(-37, 8)); Assert.AreEqual(0, PrecisionHelper.Round(179.999, 0)); Assert.AreEqual(128, PrecisionHelper.Round(179.999, 1)); Assert.AreEqual(128, PrecisionHelper.Round(179.999, 2)); Assert.AreEqual(160, PrecisionHelper.Round(179.999, 3)); Assert.AreEqual(176, PrecisionHelper.Round(179.999, 4)); Assert.AreEqual(176, PrecisionHelper.Round(179.999, 5)); Assert.AreEqual(176, PrecisionHelper.Round(179.999, 6)); Assert.AreEqual(178, PrecisionHelper.Round(179.999, 7)); Assert.AreEqual(179, PrecisionHelper.Round(179.999, 8)); }
public void RoundTest() { Assert.AreEqual(0.0, PrecisionHelper.Round(0.0, 0)); Assert.AreEqual(0.0, PrecisionHelper.Round(0.0, 1)); Assert.AreEqual(0.0, PrecisionHelper.Round(0.0, 2)); Assert.AreEqual(0.0, PrecisionHelper.Round(0.0, 3)); Assert.AreEqual(0.0, PrecisionHelper.Round(0.0, 4)); Assert.AreEqual(0.0, PrecisionHelper.Round(0.0, -1)); Assert.AreEqual(0.0, PrecisionHelper.Round(0.0, -2)); Assert.AreEqual(0.0, PrecisionHelper.Round(0.0, -3)); Assert.AreEqual(0.0, PrecisionHelper.Round(0.0, -4)); Assert.AreEqual(0.0, PrecisionHelper.Round(0.5, 0)); Assert.AreEqual(0.5, PrecisionHelper.Round(0.5, 1)); Assert.AreEqual(0.5, PrecisionHelper.Round(0.5, 2)); Assert.AreEqual(0.5, PrecisionHelper.Round(0.5, 3)); Assert.AreEqual(0.5, PrecisionHelper.Round(0.5, 4)); Assert.AreEqual(0.0, PrecisionHelper.Round(0.5, -1)); Assert.AreEqual(0.0, PrecisionHelper.Round(0.5, -2)); Assert.AreEqual(0.0, PrecisionHelper.Round(0.5, -3)); Assert.AreEqual(0.0, PrecisionHelper.Round(0.5, -4)); Assert.AreEqual(-1.0, PrecisionHelper.Round(-0.5, 0)); Assert.AreEqual(-0.5, PrecisionHelper.Round(-0.5, 1)); Assert.AreEqual(-0.5, PrecisionHelper.Round(-0.5, 2)); Assert.AreEqual(-0.5, PrecisionHelper.Round(-0.5, 3)); Assert.AreEqual(-0.5, PrecisionHelper.Round(-0.5, 4)); Assert.AreEqual(-2.0, PrecisionHelper.Round(-0.5, -1)); Assert.AreEqual(-4.0, PrecisionHelper.Round(-0.5, -2)); Assert.AreEqual(-8.0, PrecisionHelper.Round(-0.5, -3)); Assert.AreEqual(-16.0, PrecisionHelper.Round(-0.5, -4)); Assert.AreEqual(1.0, PrecisionHelper.Round(1.0, 0)); Assert.AreEqual(1.0, PrecisionHelper.Round(1.0, 1)); Assert.AreEqual(1.0, PrecisionHelper.Round(1.0, 2)); Assert.AreEqual(1.0, PrecisionHelper.Round(1.0, 3)); Assert.AreEqual(1.0, PrecisionHelper.Round(1.0, 4)); Assert.AreEqual(0.0, PrecisionHelper.Round(1.0, -1)); Assert.AreEqual(0.0, PrecisionHelper.Round(1.0, -2)); Assert.AreEqual(0.0, PrecisionHelper.Round(1.0, -3)); Assert.AreEqual(0.0, PrecisionHelper.Round(1.0, -4)); Assert.AreEqual(-1.0, PrecisionHelper.Round(-1.0, 0)); Assert.AreEqual(-1.0, PrecisionHelper.Round(-1.0, 1)); Assert.AreEqual(-1.0, PrecisionHelper.Round(-1.0, 2)); Assert.AreEqual(-1.0, PrecisionHelper.Round(-1.0, 3)); Assert.AreEqual(-1.0, PrecisionHelper.Round(-1.0, 4)); Assert.AreEqual(-2.0, PrecisionHelper.Round(-1.0, -1)); Assert.AreEqual(-4.0, PrecisionHelper.Round(-1.0, -2)); Assert.AreEqual(-8.0, PrecisionHelper.Round(-1.0, -3)); Assert.AreEqual(-16.0, PrecisionHelper.Round(-1.0, -4)); Assert.AreEqual(1.0, PrecisionHelper.Round(1.3, 0)); Assert.AreEqual(1.0, PrecisionHelper.Round(1.3, 1)); Assert.AreEqual(1.25, PrecisionHelper.Round(1.3, 2)); Assert.AreEqual(1.25, PrecisionHelper.Round(1.3, 3)); Assert.AreEqual(1.25, PrecisionHelper.Round(1.3, 4)); Assert.AreEqual(0.0, PrecisionHelper.Round(1.3, -1)); Assert.AreEqual(0.0, PrecisionHelper.Round(1.3, -2)); Assert.AreEqual(0.0, PrecisionHelper.Round(1.3, -3)); Assert.AreEqual(0.0, PrecisionHelper.Round(1.3, -4)); Assert.AreEqual(-2.0, PrecisionHelper.Round(-1.3, 0)); Assert.AreEqual(-1.5, PrecisionHelper.Round(-1.3, 1)); Assert.AreEqual(-1.5, PrecisionHelper.Round(-1.3, 2)); Assert.AreEqual(-1.375, PrecisionHelper.Round(-1.3, 3)); Assert.AreEqual(-1.3125, PrecisionHelper.Round(-1.3, 4)); Assert.AreEqual(-2.0, PrecisionHelper.Round(-1.3, -1)); Assert.AreEqual(-4.0, PrecisionHelper.Round(-1.3, -2)); Assert.AreEqual(-8.0, PrecisionHelper.Round(-1.3, -3)); Assert.AreEqual(-16.0, PrecisionHelper.Round(-1.3, -4)); Assert.AreEqual(37.0, PrecisionHelper.Round(37.9, 0)); Assert.AreEqual(37.5, PrecisionHelper.Round(37.9, 1)); Assert.AreEqual(37.75, PrecisionHelper.Round(37.9, 2)); Assert.AreEqual(37.875, PrecisionHelper.Round(37.9, 3)); Assert.AreEqual(37.875, PrecisionHelper.Round(37.9, 4)); Assert.AreEqual(36.0, PrecisionHelper.Round(37.9, -1)); Assert.AreEqual(36.0, PrecisionHelper.Round(37.9, -2)); Assert.AreEqual(32.0, PrecisionHelper.Round(37.9, -3)); Assert.AreEqual(32.0, PrecisionHelper.Round(37.9, -4)); Assert.AreEqual(-38.0, PrecisionHelper.Round(-37.9, 0)); Assert.AreEqual(-38.0, PrecisionHelper.Round(-37.9, 1)); Assert.AreEqual(-38.0, PrecisionHelper.Round(-37.9, 2)); Assert.AreEqual(-38.0, PrecisionHelper.Round(-37.9, 3)); Assert.AreEqual(-37.9375, PrecisionHelper.Round(-37.9, 4)); Assert.AreEqual(-38.0, PrecisionHelper.Round(-37.9, -1)); Assert.AreEqual(-40.0, PrecisionHelper.Round(-37.9, -2)); Assert.AreEqual(-40.0, PrecisionHelper.Round(-37.9, -3)); Assert.AreEqual(-48.0, PrecisionHelper.Round(-37.9, -4)); }