diff --git a/dotnet/src/Plugins/Plugins.Memory/Collections/MinHeap.cs b/dotnet/src/Plugins/Plugins.Memory/Collections/MinHeap.cs index 5e368ded6ee8..3726c5b0a76e 100644 --- a/dotnet/src/Plugins/Plugins.Memory/Collections/MinHeap.cs +++ b/dotnet/src/Plugins/Plugins.Memory/Collections/MinHeap.cs @@ -11,7 +11,7 @@ namespace Microsoft.SemanticKernel.Plugins.Memory.Collections; /// Implements the classic 'heap' data structure. By default, the item with the lowest value is at the top of the heap. /// /// Data type. -public sealed class MinHeap : IEnumerable where T : IComparable +internal sealed class MinHeap : IEnumerable where T : IComparable { private const int DefaultCapacity = 7; private const int MinCapacity = 0; diff --git a/dotnet/src/Plugins/Plugins.Memory/Collections/ScoredValue.cs b/dotnet/src/Plugins/Plugins.Memory/Collections/ScoredValue.cs index 9946965c800e..ebdb360b69f9 100644 --- a/dotnet/src/Plugins/Plugins.Memory/Collections/ScoredValue.cs +++ b/dotnet/src/Plugins/Plugins.Memory/Collections/ScoredValue.cs @@ -9,7 +9,7 @@ namespace Microsoft.SemanticKernel.Plugins.Memory.Collections; /// Structure for storing data which can be scored. /// /// Data type. -public readonly struct ScoredValue : IComparable>, IEquatable> +internal readonly struct ScoredValue : IComparable>, IEquatable> { /// /// Initializes a new instance of the struct. diff --git a/dotnet/src/Plugins/Plugins.Memory/Collections/TopNCollection.cs b/dotnet/src/Plugins/Plugins.Memory/Collections/TopNCollection.cs index 6369ef1ebb97..9a8b874cd2c8 100644 --- a/dotnet/src/Plugins/Plugins.Memory/Collections/TopNCollection.cs +++ b/dotnet/src/Plugins/Plugins.Memory/Collections/TopNCollection.cs @@ -10,7 +10,7 @@ namespace Microsoft.SemanticKernel.Plugins.Memory.Collections; /// Automatically flushes out any not in the top N. /// By default, items are not sorted by score until you call . /// -public class TopNCollection : IEnumerable> +internal sealed class TopNCollection : IEnumerable> { private readonly MinHeap> _heap; private bool _sorted = false; diff --git a/dotnet/src/Plugins/Plugins.UnitTests/Memory/Collections/MinHeapTests.cs b/dotnet/src/Plugins/Plugins.UnitTests/Memory/Collections/MinHeapTests.cs deleted file mode 100644 index 7472b97cce83..000000000000 --- a/dotnet/src/Plugins/Plugins.UnitTests/Memory/Collections/MinHeapTests.cs +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.SemanticKernel.Plugins.Memory.Collections; -using Xunit; - -namespace SemanticKernel.Plugins.UnitTests.Memory.Collections; - -/// -/// Contains tests for the class. -/// -public class MinHeapTests -{ - private const int MinValue = 1; - - [Fact] - public void ItThrowsExceptionWhenCapacityIsInvalid() - { - // Arrange - const int InvalidCapacity = -1; - - void Action() - { - var minHeap = new MinHeap(MinValue, InvalidCapacity); - } - - // Act - var exception = Assert.Throws("capacity", Action); - - // Assert - Assert.Equal(-1, exception.ActualValue); - } - - [Fact] - public void ItAddsItemsInCorrectOrder() - { - // Arrange - const int ExpectedTopItem = 1; - const int ExpectedCount = 3; - - // Act - var minHeap = new MinHeap(MinValue) { 3, 1, 2 }; - - // Assert - Assert.Equal(ExpectedTopItem, minHeap.Top); - Assert.Equal(ExpectedCount, minHeap.Count); - } - - [Fact] - public void ItErasesItemsCorrectly() - { - // Arrange - const int ExpectedCount = 0; - var minHeap = new MinHeap(MinValue) { 3, 1, 2 }; - - // Act - minHeap.Erase(); - - // Assert - Assert.Equal(ExpectedCount, minHeap.Count); - } - - [Fact] - public void ItReturnsItemsOnBufferDetaching() - { - // Arrange - const int ExpectedHeapCount = 0; - - var minHeap = new MinHeap(MinValue) { 3, 1, 2 }; - - // Act - var items = minHeap.DetachBuffer(); - - // Assert - Assert.True(items.Length > 0); - Assert.Equal(ExpectedHeapCount, minHeap.Count); - } - - [Fact] - public void ItThrowsExceptionOnAddingItemsAtInvalidIndex() - { - // Arrange - const int StartIndex = 4; - - var items = new List { 3, 1, 2 }; - var minHeap = new MinHeap(MinValue); - - void action() { minHeap.Add(items, StartIndex); } - - // Act - var exception = Assert.Throws("startAt", () => action()); - - // Assert - Assert.Equal(StartIndex, exception.ActualValue); - } - - [Fact] - public void ItRemovesTopItemCorrectly() - { - // Arrange - const int ExpectedTopItem = 2; - const int ExpectedHeapCount = 2; - - var minHeap = new MinHeap(MinValue) { 3, 1, 2 }; - - // Act - minHeap.RemoveTop(); - - // Assert - Assert.Equal(ExpectedTopItem, minHeap.Top); - Assert.Equal(ExpectedHeapCount, minHeap.Count); - } - - [Fact] - public void ItRemovesAllItemsCorrectly() - { - // Arrange - const int ExpectedHeapCount = 0; - - var minHeap = new MinHeap(MinValue) { 3, 1, 2 }; - - // Act - var items = minHeap.RemoveAll().ToList(); - - // Assert - Assert.Equal(1, items[0]); - Assert.Equal(2, items[1]); - Assert.Equal(3, items[2]); - - Assert.Equal(ExpectedHeapCount, minHeap.Count); - } - - [Fact] - public void ItEnsuresCapacityToExpectedValue() - { - // Arrange - const int ExpectedCapacity = 16; - - var minHeap = new MinHeap(MinValue); - - // Act - minHeap.EnsureCapacity(ExpectedCapacity); - - // Assert - Assert.Equal(ExpectedCapacity, minHeap.Capacity); - } -} diff --git a/dotnet/src/Plugins/Plugins.UnitTests/Memory/Collections/TopNCollectionTests.cs b/dotnet/src/Plugins/Plugins.UnitTests/Memory/Collections/TopNCollectionTests.cs deleted file mode 100644 index 507df5c972d3..000000000000 --- a/dotnet/src/Plugins/Plugins.UnitTests/Memory/Collections/TopNCollectionTests.cs +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.SemanticKernel.Plugins.Memory.Collections; -using Xunit; - -namespace SemanticKernel.Plugins.UnitTests.Memory.Collections; - -/// -/// Contains tests for the class. -/// -public class TopNCollectionTests -{ - private const int MaxItemsCount = 5; - - [Fact] - public void ItResetsCollectionCorrectly() - { - // Arrange - const int ExpectedItemsCount = 0; - - var topNCollection = this.GetTestCollection(MaxItemsCount); - - // Act - topNCollection.Reset(); - - // Assert - Assert.Equal(ExpectedItemsCount, topNCollection.Count); - } - - [Fact] - public void ItKeepsMaxItemsCountWhenMoreItemsWereAdded() - { - // Arrange - const int ExpectedCollectionCount = 5; - - // Act - var topNCollection = this.GetTestCollection(ExpectedCollectionCount); - - // Assert - Assert.Equal(ExpectedCollectionCount, topNCollection.Count); - } - - [Fact] - public void ItSortsCollectionByScoreInDescendingOrder() - { - // Arrange - var topNCollection = this.GetTestCollection(MaxItemsCount); - - // Act - topNCollection.SortByScore(); - - // Assert - var items = topNCollection.ToList(); - - for (var i = 0; i < topNCollection.Count - 1; i++) - { - Assert.True(items[i].Score > items[i + 1].Score); - } - } - - private TopNCollection GetTestCollection(int maxItemsCount) - { - return new TopNCollection(maxItemsCount) - { - new ScoredValue(1, 0.5), - new ScoredValue(2, 0.6), - new ScoredValue(3, 0.4), - new ScoredValue(4, 0.2), - new ScoredValue(5, 0.9), - new ScoredValue(6, 0.1), - }; - } -}