From 13f0837d8e64345c3b7af7f4590b8cddcb2efd4c Mon Sep 17 00:00:00 2001 From: Pressacco <5507864+Pressacco@users.noreply.github.com> Date: Wed, 30 Oct 2024 00:38:54 +0000 Subject: [PATCH] Refactor : Renamed `Region` to `Bookend`. #375 --- .../{RegionOfInterest.cs => Bookend.cs} | 6 +- .../{RegionManager.cs => BookendManager.cs} | 8 +- .../BookendManagerTests.cs | 110 ++++++++++++++++++ .../RegionManagerTests.cs | 110 ------------------ 4 files changed, 117 insertions(+), 117 deletions(-) rename Src/BlueDotBrigade.Weevil.Core/{RegionOfInterest.cs => Bookend.cs} (74%) rename Src/BlueDotBrigade.Weevil.Core/{RegionManager.cs => BookendManager.cs} (88%) create mode 100644 Tst/BlueDotBrigade.Weevil.Core-UnitTests/BookendManagerTests.cs delete mode 100644 Tst/BlueDotBrigade.Weevil.Core-UnitTests/RegionManagerTests.cs diff --git a/Src/BlueDotBrigade.Weevil.Core/RegionOfInterest.cs b/Src/BlueDotBrigade.Weevil.Core/Bookend.cs similarity index 74% rename from Src/BlueDotBrigade.Weevil.Core/RegionOfInterest.cs rename to Src/BlueDotBrigade.Weevil.Core/Bookend.cs index aa95dc1..98ddcf4 100644 --- a/Src/BlueDotBrigade.Weevil.Core/RegionOfInterest.cs +++ b/Src/BlueDotBrigade.Weevil.Core/Bookend.cs @@ -1,17 +1,17 @@ namespace BlueDotBrigade.Weevil { - internal class RegionOfInterest + internal class Bookend { public int StartLineNumber { get; } public int EndLineNumber { get; } - public RegionOfInterest(int startLineNumber, int endLineNumber) + public Bookend(int startLineNumber, int endLineNumber) { this.StartLineNumber = startLineNumber; this.EndLineNumber = endLineNumber; } - public bool OverlapsWith(RegionOfInterest other) + public bool OverlapsWith(Bookend other) { return this.StartLineNumber <= other.EndLineNumber && this.EndLineNumber >= other.StartLineNumber; } diff --git a/Src/BlueDotBrigade.Weevil.Core/RegionManager.cs b/Src/BlueDotBrigade.Weevil.Core/BookendManager.cs similarity index 88% rename from Src/BlueDotBrigade.Weevil.Core/RegionManager.cs rename to Src/BlueDotBrigade.Weevil.Core/BookendManager.cs index cc7b16f..8e03624 100644 --- a/Src/BlueDotBrigade.Weevil.Core/RegionManager.cs +++ b/Src/BlueDotBrigade.Weevil.Core/BookendManager.cs @@ -5,13 +5,13 @@ namespace BlueDotBrigade.Weevil using System.Collections.Generic; using System.Collections.Immutable; - internal class RegionManager + internal class BookendManager { - private readonly List _regions = new List(); + private readonly List _regions = new List(); private int? _startLineNumber = null; - public ImmutableArray Regions => _regions.ToImmutableArray(); + public ImmutableArray Bookends => _regions.ToImmutableArray(); public void MarkStart(int lineNumber) { @@ -29,7 +29,7 @@ public void MarkEnd(int lineNumber) var start = Math.Min(_startLineNumber.Value, lineNumber); var end = Math.Max(_startLineNumber.Value, lineNumber); - var newRegion = new RegionOfInterest(start, end); + var newRegion = new Bookend(start, end); // Prevent creating the same region twice if (_regions.Any(r => r.StartLineNumber == newRegion.StartLineNumber && r.EndLineNumber == newRegion.EndLineNumber)) diff --git a/Tst/BlueDotBrigade.Weevil.Core-UnitTests/BookendManagerTests.cs b/Tst/BlueDotBrigade.Weevil.Core-UnitTests/BookendManagerTests.cs new file mode 100644 index 0000000..c9b0873 --- /dev/null +++ b/Tst/BlueDotBrigade.Weevil.Core-UnitTests/BookendManagerTests.cs @@ -0,0 +1,110 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using BlueDotBrigade.Weevil.Core; + +namespace BlueDotBrigade.Weevil.Core.UnitTests +{ + [TestClass] + public class RegionManagerTests + { + private BookendManager _bookendManager; + + [TestInitialize] + public void Setup() + { + _bookendManager = new BookendManager(); + } + + [TestMethod] + public void MarkEnd_AfterStart_BookendCreated() + { + // Arrange + int startIndex = 800; + int endIndex = 900; + _bookendManager.MarkStart(startIndex); + + // Act + _bookendManager.MarkEnd(endIndex); + + // Assert + Assert.AreEqual(1, _bookendManager.Bookends.Length); + Assert.AreEqual(startIndex, _bookendManager.Bookends[0].StartLineNumber); + Assert.AreEqual(endIndex, _bookendManager.Bookends[0].EndLineNumber); + } + + [TestMethod] + [ExpectedException(typeof(InvalidOperationException))] + public void MarkEnd_WithoutStart_ThrowsInvalidOperationException() + { + // Arrange + int endIndex = 900; + + // Act + _bookendManager.MarkEnd(endIndex); + + // Assert handled by ExpectedException + } + + [TestMethod] + public void Bookends_CreateMultipleBookends_ReturnsAllBookends() + { + // Arrange + _bookendManager.MarkStart(800); + _bookendManager.MarkEnd(900); + + _bookendManager.MarkStart(950); + _bookendManager.MarkEnd(1000); + + // Act + // Assert + Assert.AreEqual(2, _bookendManager.Bookends.Length); + Assert.AreEqual(800, _bookendManager.Bookends[0].StartLineNumber); + Assert.AreEqual(900, _bookendManager.Bookends[0].EndLineNumber); + Assert.AreEqual(950, _bookendManager.Bookends[1].StartLineNumber); + Assert.AreEqual(1000, _bookendManager.Bookends[1].EndLineNumber); + } + + [TestMethod] + public void Clear_ExistingBookends_AllBookendsDeleted() + { + // Arrange + _bookendManager.MarkStart(800); + _bookendManager.MarkEnd(900); + + // Act + _bookendManager.Clear(); + + // Assert + Assert.AreEqual(0, _bookendManager.Bookends.Length); + } + + [TestMethod] + public void Clear_IndexIsWithinBookend_BookendDeleted() + { + // Arrange + _bookendManager.MarkStart(800); + _bookendManager.MarkEnd(900); + + // Act + _bookendManager.Clear(850); + + // Assert + Assert.AreEqual(0, _bookendManager.Bookends.Length); + } + + [TestMethod] + [ExpectedException(typeof(InvalidOperationException))] + public void Clear_LineNumberIsOutsideOfBookend_Throws() + { + // Arrange + _bookendManager.MarkStart(800); + _bookendManager.MarkEnd(900); + + // Act + _bookendManager.Clear(100); + + // Assert + Assert.AreEqual(1, _bookendManager.Bookends.Length); + } + } +} \ No newline at end of file diff --git a/Tst/BlueDotBrigade.Weevil.Core-UnitTests/RegionManagerTests.cs b/Tst/BlueDotBrigade.Weevil.Core-UnitTests/RegionManagerTests.cs deleted file mode 100644 index 8706711..0000000 --- a/Tst/BlueDotBrigade.Weevil.Core-UnitTests/RegionManagerTests.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using BlueDotBrigade.Weevil.Core; - -namespace BlueDotBrigade.Weevil.Core.UnitTests -{ - [TestClass] - public class RegionManagerTests - { - private RegionManager _regionManager; - - [TestInitialize] - public void Setup() - { - _regionManager = new RegionManager(); - } - - [TestMethod] - public void MarkRegionEnd_AfterStartRegion_RegionAdded() - { - // Arrange - int startIndex = 800; - int endIndex = 900; - _regionManager.MarkStart(startIndex); - - // Act - _regionManager.MarkEnd(endIndex); - - // Assert - Assert.AreEqual(1, _regionManager.Regions.Length); - Assert.AreEqual(startIndex, _regionManager.Regions[0].StartLineNumber); - Assert.AreEqual(endIndex, _regionManager.Regions[0].EndLineNumber); - } - - [TestMethod] - [ExpectedException(typeof(InvalidOperationException))] - public void MarkRegionEnd_WithoutStart_ThrowsInvalidOperationException() - { - // Arrange - int endIndex = 900; - - // Act - _regionManager.MarkEnd(endIndex); - - // Assert handled by ExpectedException - } - - [TestMethod] - public void GetRegionsOfInterest_AfterMultipleRegions_ReturnsAllRegions() - { - // Arrange - _regionManager.MarkStart(800); - _regionManager.MarkEnd(900); - - _regionManager.MarkStart(950); - _regionManager.MarkEnd(1000); - - // Act - // Assert - Assert.AreEqual(2, _regionManager.Regions.Length); - Assert.AreEqual(800, _regionManager.Regions[0].StartLineNumber); - Assert.AreEqual(900, _regionManager.Regions[0].EndLineNumber); - Assert.AreEqual(950, _regionManager.Regions[1].StartLineNumber); - Assert.AreEqual(1000, _regionManager.Regions[1].EndLineNumber); - } - - [TestMethod] - public void Clear_ExistingRegions_AllRegionsDeleted() - { - // Arrange - _regionManager.MarkStart(800); - _regionManager.MarkEnd(900); - - // Act - _regionManager.Clear(); - - // Assert - Assert.AreEqual(0, _regionManager.Regions.Length); - } - - [TestMethod] - public void Clear_IndexIsWithinRegion_RegionDeleted() - { - // Arrange - _regionManager.MarkStart(800); - _regionManager.MarkEnd(900); - - // Act - _regionManager.Clear(850); - - // Assert - Assert.AreEqual(0, _regionManager.Regions.Length); - } - - [TestMethod] - [ExpectedException(typeof(InvalidOperationException))] - public void Clear_IndexIsOutsideOfRegion_Throws() - { - // Arrange - _regionManager.MarkStart(800); - _regionManager.MarkEnd(900); - - // Act - _regionManager.Clear(100); - - // Assert - Assert.AreEqual(1, _regionManager.Regions.Length); - } - } -} \ No newline at end of file