Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/DikeProfile.cs =================================================================== diff -u -r8a6beb11ea0d1200c4dacdc0d9ef4011fdcbb8b9 -r4e7e4a0740ddf86ceb74893155d1f20f95efb342 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/DikeProfile.cs (.../DikeProfile.cs) (revision 8a6beb11ea0d1200c4dacdc0d9ef4011fdcbb8b9) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/DikeProfile.cs (.../DikeProfile.cs) (revision 4e7e4a0740ddf86ceb74893155d1f20f95efb342) @@ -74,13 +74,15 @@ } set { - if (value < 0.0 || value > 360.0) + var roundedValue = value.ToPrecision(orientation.NumberOfDecimalPlaces); + + if (roundedValue < 0.0 || roundedValue > 360.0) { - string message = string.Format(Resources.DikeProfile_Orientation_Value_0_should_be_in_interval, value.Value); + string message = string.Format(Resources.DikeProfile_Orientation_Value_0_should_be_in_interval, roundedValue); throw new ArgumentOutOfRangeException("value", message); } - orientation = value.ToPrecision(orientation.NumberOfDecimalPlaces); + orientation = roundedValue; } } Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/DikeProfileTest.cs =================================================================== diff -u -r8a6beb11ea0d1200c4dacdc0d9ef4011fdcbb8b9 -r4e7e4a0740ddf86ceb74893155d1f20f95efb342 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/DikeProfileTest.cs (.../DikeProfileTest.cs) (revision 8a6beb11ea0d1200c4dacdc0d9ef4011fdcbb8b9) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/DikeProfileTest.cs (.../DikeProfileTest.cs) (revision 4e7e4a0740ddf86ceb74893155d1f20f95efb342) @@ -88,9 +88,24 @@ } [Test] + [TestCase(-1e-3, 0.0)] + [TestCase(360 + 1e-3, 360.0)] + public void Orientation_SetValueThatIsNoLongerIllegalAfterRounding_RoundedValueIsSet(double newValue, double expectedRoundedValue) + { + // Setup + var dikeProfile = new DikeProfile(new Point2D(0, 0)); + + // Call + dikeProfile.Orientation = (RoundedDouble) newValue; + + // Assert + Assert.AreEqual(expectedRoundedValue, dikeProfile.Orientation.Value); + } + + [Test] [TestCase(-987.65)] - [TestCase(-1e-6)] - [TestCase(360 + 1e-6)] + [TestCase(-1e-2)] + [TestCase(360 + 1e-2)] [TestCase(875.12)] public void Orientation_SetIllegalValue_ThrowsArgumentOutOfRangeException(double invalidNewValue) { @@ -102,7 +117,7 @@ // Assert string expectedMessage = String.Format("De dijkprofiel oriƫntatie waarde {0} moet in het interval [0, 360] liggen.", - invalidNewValue); + new RoundedDouble(dikeProfile.Orientation.NumberOfDecimalPlaces, invalidNewValue)); TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); }