Skip to content

Commit

Permalink
Refactor : Renamed Region to Bookend. #375
Browse files Browse the repository at this point in the history
  • Loading branch information
Pressacco authored Oct 30, 2024
1 parent 8975957 commit 13f0837
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 117 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace BlueDotBrigade.Weevil
using System.Collections.Generic;
using System.Collections.Immutable;

internal class RegionManager
internal class BookendManager
{
private readonly List<RegionOfInterest> _regions = new List<RegionOfInterest>();
private readonly List<Bookend> _regions = new List<Bookend>();

private int? _startLineNumber = null;

public ImmutableArray<RegionOfInterest> Regions => _regions.ToImmutableArray();
public ImmutableArray<Bookend> Bookends => _regions.ToImmutableArray();

public void MarkStart(int lineNumber)
{
Expand All @@ -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))
Expand Down
110 changes: 110 additions & 0 deletions Tst/BlueDotBrigade.Weevil.Core-UnitTests/BookendManagerTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
110 changes: 0 additions & 110 deletions Tst/BlueDotBrigade.Weevil.Core-UnitTests/RegionManagerTests.cs

This file was deleted.

0 comments on commit 13f0837

Please sign in to comment.