Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/DikeProfiles/DikeProfileDataReader.cs =================================================================== diff -u -rb1ec20c759f606a49e6acdf12c6409e78abcf21b -rb6a73e405591aa848377355d3f2d931cfbb91ff4 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/DikeProfiles/DikeProfileDataReader.cs (.../DikeProfileDataReader.cs) (revision b1ec20c759f606a49e6acdf12c6409e78abcf21b) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/DikeProfiles/DikeProfileDataReader.cs (.../DikeProfileDataReader.cs) (revision b6a73e405591aa848377355d3f2d931cfbb91ff4) @@ -74,6 +74,9 @@ /// A piece of text from the file cannot be converted in the expected variable type. /// A converted value is invalid. /// The file is incomplete. + /// A parameter is defined more then once. + /// The geometry points for either the dike or foreshore do not have monotonically + /// increasing X-coordinates. /// public DikeProfileData ReadDikeProfileData(string filePath) { @@ -613,9 +616,13 @@ /// The line number. /// True if the text matches a DIJK key-value pair and has been /// validated successfully; false otherwise. - /// The value after the DIJK key - /// does not represent a valid number or any of read the parameters in the following - /// data block is invalid or has already been defined. + /// When + /// + /// The value after the DIJK key does not represent a valid number. + /// Any of read the parameters in the following data block is invalid. + /// The parameter has already been defined. + /// The X-coordinates of the dike are not monotonically increasing. + /// private bool TryReadDikeRoughnessPoints(string text, DikeProfileData data, TextReader reader, ref int lineNumber) { Match dikeGeometryMatch = new Regex(@"^DIJK(\s+(?.+?)?)?\s*$").Match(text); @@ -648,7 +655,15 @@ RoughnessPoint roughnessPoint = ReadRoughnessPoint(text, lineNumber); data.DikeGeometry[i] = roughnessPoint; + + if (i > 0) + { + ValidateDikePointsAreMonotonicallyIncreasing(roughnessPoint.Point, + data.DikeGeometry[i - 1].Point, + lineNumber); + } } + readParameters |= ParametersFoundInFile.DIJK; return true; } @@ -783,18 +798,36 @@ } /// + /// Validates that two dike points are monotonically increasing. + /// + /// The current point. + /// The previous point. + /// The line number. + /// When + /// has an X coordinate before or equal to that of . + private void ValidateDikePointsAreMonotonicallyIncreasing(Point2D currentPoint, Point2D previousPoint, int lineNumber) + { + if (currentPoint.X <= previousPoint.X) + { + throw CreateCriticalFileReadException(lineNumber, Resources.DikeProfileDataReader_ValidateDikePointsAreMonotonicallyIncreasing_Error_message); + } + } + + /// /// Attempts to match the given text to a VOORLAND key-value pair. If a match is /// found, the data block is being read. If valid, the value is stored. /// /// The text of the VOORLAND key-value pair. /// The data to be updated. /// The reader of the file. /// The line number. - /// True if the text matches a VOORLAND key-value pair and has been - /// validated successfully; false otherwise. - /// The value after the VOORLAND key - /// does not represent a valid number or any of read the parameters in the following - /// data block is invalid or has already been defined. + /// When + /// + /// The value after the VOORLAND key does not represent a valid number. + /// Any of read the parameters in the following data block is invalid. + /// The parameter has already been defined. + /// The X-coordinates of the foreshore are not monotonically increasing. + /// private bool TryReadForeshoreRoughnessPoints(string text, DikeProfileData data, TextReader reader, ref int lineNumber) { Match foreshoreGeometryMatch = new Regex(@"^VOORLAND(\s+(?.+?)?)?\s*$").Match(text); @@ -827,6 +860,13 @@ RoughnessPoint roughnessPoint = ReadRoughnessPoint(text, lineNumber); data.ForeshoreGeometry[i] = roughnessPoint; + + if (i > 0) + { + ValidateForeshorePointsAreMonotonicallyIncreasing(roughnessPoint.Point, + data.ForeshoreGeometry[i - 1].Point, + lineNumber); + } } readParameters |= ParametersFoundInFile.VOORLAND; return true; @@ -879,6 +919,22 @@ } } + /// + /// Validates that two foreshore points are monotonically increasing. + /// + /// The current point. + /// The previous point. + /// The line number. + /// When + /// has an X coordinate before or equal to that of . + private void ValidateForeshorePointsAreMonotonicallyIncreasing(Point2D currentPoint, Point2D previousPoint, int lineNumber) + { + if (currentPoint.X <= previousPoint.X) + { + throw CreateCriticalFileReadException(lineNumber, Resources.DikeProfileDataReader_ValidateForeshorePointsAreMonotonicallyIncreasing_Error_message); + } + } + private bool TryReadMemo(string text, DikeProfileData data, StreamReader reader) { Match memoMatch = new Regex(@"^MEMO\s*$").Match(text); Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.Designer.cs =================================================================== diff -u -rb1ec20c759f606a49e6acdf12c6409e78abcf21b -rb6a73e405591aa848377355d3f2d931cfbb91ff4 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b1ec20c759f606a49e6acdf12c6409e78abcf21b) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b6a73e405591aa848377355d3f2d931cfbb91ff4) @@ -328,6 +328,25 @@ } /// + /// Looks up a localized string similar to Dijkgeometrie punten dienen X-coordinaten te hebben die monotoon strict toenemend zijn.. + /// + internal static string DikeProfileDataReader_ValidateDikePointsAreMonotonicallyIncreasing_Error_message { + get { + return ResourceManager.GetString("DikeProfileDataReader_ValidateDikePointsAreMonotonicallyIncreasing_Error_message", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Voorlandgeometrie punten dienen X-coordinaten te hebben die monotoon strict toenemend zijn.. + /// + internal static string DikeProfileDataReader_ValidateForeshorePointsAreMonotonicallyIncreasing_Error_message { + get { + return ResourceManager.GetString("DikeProfileDataReader_ValidateForeshorePointsAreMonotonicallyIncreasing_Error_mes" + + "sage", resourceCulture); + } + } + + /// /// Looks up a localized string similar to De ingelezen Id ({0}) bevat spaties, welke niet zijn toegestaan.. /// internal static string DikeProfileDataReader_ValidateId_Id_0_has_unsupported_white_space { Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.resx =================================================================== diff -u -rb1ec20c759f606a49e6acdf12c6409e78abcf21b -rb6a73e405591aa848377355d3f2d931cfbb91ff4 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.resx (.../Resources.resx) (revision b1ec20c759f606a49e6acdf12c6409e78abcf21b) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.resx (.../Resources.resx) (revision b6a73e405591aa848377355d3f2d931cfbb91ff4) @@ -252,4 +252,10 @@ De parameter {0} is al eerder in het bestand gedefinieerd. + + Dijkgeometrie punten dienen X-coordinaten te hebben die monotoon strict toenemend zijn. + + + Voorlandgeometrie punten dienen X-coordinaten te hebben die monotoon strict toenemend zijn. + \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/DikeProfiles/DikeProfileDataReaderTest.cs =================================================================== diff -u -rb1ec20c759f606a49e6acdf12c6409e78abcf21b -rb6a73e405591aa848377355d3f2d931cfbb91ff4 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/DikeProfiles/DikeProfileDataReaderTest.cs (.../DikeProfileDataReaderTest.cs) (revision b1ec20c759f606a49e6acdf12c6409e78abcf21b) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/DikeProfiles/DikeProfileDataReaderTest.cs (.../DikeProfileDataReaderTest.cs) (revision b6a73e405591aa848377355d3f2d931cfbb91ff4) @@ -832,6 +832,30 @@ } [Test] + [TestCase("faulty_dijkNotMonotonicallyIncreasingX_1.prfl", 20, "Dijk")] + [TestCase("faulty_dijkNotMonotonicallyIncreasingX_2.prfl", 18, "Dijk")] + [TestCase("faulty_voorlandNotMonotonicallyIncreasingX_1.prfl", 12, "Voorland")] + [TestCase("faulty_voorlandNotMonotonicallyIncreasingX_2.prfl", 11, "Voorland")] + public void ReadDikeProfileData_FaultyFileWithNotMonotonicallyIncreasingX_ThrowsCriticalFileReadException( + string faultyFileName, int expectedLineNumber, string expectedTypePrefix) + { + // Setup + string faultyFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.GrassCoverErosionInwards.IO, + Path.Combine("DikeProfiles", faultyFileName)); + + var reader = new DikeProfileDataReader(); + + // Call + TestDelegate call = () => reader.ReadDikeProfileData(faultyFilePath); + + // Assert + string message = Assert.Throws(call).Message; + string expectedMessage = string.Format("Fout bij het lezen van bestand '{0}' op regel {1}: {2}geometrie punten dienen X-coordinaten te hebben die monotoon strict toenemend zijn.", + faultyFilePath, expectedLineNumber, expectedTypePrefix); + Assert.AreEqual(expectedMessage, message); + } + + [Test] [TestCase("faulty_unparsableVoorland.prfl", "oidushp9t8w uyp394hp 983 94")] [TestCase("faulty_unparsableVoorland_noValue1.prfl", "")] [TestCase("faulty_unparsableVoorland_noValue2.prfl", "")] Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/faulty_dijkNotMonotonicallyIncreasingX_1.prfl =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/faulty_dijkNotMonotonicallyIncreasingX_1.prfl (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/faulty_dijkNotMonotonicallyIncreasingX_1.prfl (revision b6a73e405591aa848377355d3f2d931cfbb91ff4) @@ -0,0 +1,27 @@ +VERSIE 4.0 +ID profiel004 + +RICHTING 330 + +DAM 0 +DAMHOOGTE 0.5 + +VOORLAND 3 +-150.000 -9.000 1.000 +-100.000 -6.000 1.000 +-18.000 -6.000 1.000 + +DAMWAND 0 +KRUINHOOGTE 6 +DIJK 5 +-18.000 -6.000 1.000 +-2.000 -0.100 0.500 +2.000 0.100 1.000 +2.000 2.300 1.000 +18.000 6.000 1.000 + +MEMO +Verkenning prfl format: +geen dam +voorland +talud met (ruwe) berm Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/faulty_dijkNotMonotonicallyIncreasingX_2.prfl =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/faulty_dijkNotMonotonicallyIncreasingX_2.prfl (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/faulty_dijkNotMonotonicallyIncreasingX_2.prfl (revision b6a73e405591aa848377355d3f2d931cfbb91ff4) @@ -0,0 +1,26 @@ +VERSIE 4.0 +ID profiel004 + +RICHTING 330 + +DAM 0 +DAMHOOGTE 0.5 + +VOORLAND 3 +-150.000 -9.000 1.000 +-100.000 -6.000 1.000 +-18.000 -6.000 1.000 + +DAMWAND 0 +KRUINHOOGTE 6 +DIJK 4 +18.000 6.000 1.000 +2.000 0.100 1.000 +-2.000 -0.100 0.500 +-18.000 -6.000 1.000 + +MEMO +Verkenning prfl format: +geen dam +voorland +talud met (ruwe) berm Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/faulty_voorlandNotMonotonicallyIncreasingX_1.prfl =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/faulty_voorlandNotMonotonicallyIncreasingX_1.prfl (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/faulty_voorlandNotMonotonicallyIncreasingX_1.prfl (revision b6a73e405591aa848377355d3f2d931cfbb91ff4) @@ -0,0 +1,27 @@ +VERSIE 4.0 +ID profiel004 + +RICHTING 330 + +DAM 0 +DAMHOOGTE 0.5 + +VOORLAND 4 +-150.000 -9.000 1.000 +-100.000 -6.000 1.000 +-100.000 -3.000 1.000 +-18.000 -3.000 1.000 + +DAMWAND 0 +KRUINHOOGTE 6 +DIJK 4 +-18.000 -6.000 1.000 +-2.000 -0.100 0.500 +2.000 0.100 1.000 +18.000 6.000 1.000 + +MEMO +Verkenning prfl format: +geen dam +voorland +talud met (ruwe) berm Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/faulty_voorlandNotMonotonicallyIncreasingX_2.prfl =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/faulty_voorlandNotMonotonicallyIncreasingX_2.prfl (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/faulty_voorlandNotMonotonicallyIncreasingX_2.prfl (revision b6a73e405591aa848377355d3f2d931cfbb91ff4) @@ -0,0 +1,26 @@ +VERSIE 4.0 +ID profiel004 + +RICHTING 330 + +DAM 0 +DAMHOOGTE 0.5 + +VOORLAND 3 +-18.000 -6.000 1.000 +-100.000 -6.000 1.000 +-150.000 -9.000 1.000 + +DAMWAND 0 +KRUINHOOGTE 6 +DIJK 4 +-18.000 -6.000 1.000 +-2.000 -0.100 0.500 +2.000 0.100 1.000 +18.000 6.000 1.000 + +MEMO +Verkenning prfl format: +geen dam +voorland +talud met (ruwe) berm