Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions PowerKit.Tests/CollectionExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@ namespace PowerKit.Tests;

public class CollectionExtensionsTests
{
[Fact]
public void AddRange_Test()
{
// Arrange
var collection = (ICollection<int>)new List<int> { 1, 2, 3 };

// Act
collection.AddRange([4, 5, 6]);

// Assert
collection.Should().Equal(1, 2, 3, 4, 5, 6);
}

[Fact]
public void RemoveRange_Test()
{
// Arrange
var collection = (ICollection<int>)new List<int> { 1, 2, 3, 4, 5 };

// Act
collection.RemoveRange([2, 4]);

// Assert
collection.Should().Equal(1, 3, 5);
}
Comment thread
Tyrrrz marked this conversation as resolved.

[Fact]
public void RemoveAll_Test()
{
Expand Down
18 changes: 18 additions & 0 deletions PowerKit/Extensions/CollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ internal static class CollectionExtensions
{
extension<T>(ICollection<T> source)
{
/// <summary>
/// Adds all elements from the specified sequence to the collection.
/// </summary>
public void AddRange(IEnumerable<T> items)
{
foreach (var item in items)
Comment thread
Tyrrrz marked this conversation as resolved.
Outdated
source.Add(item);
}

/// <summary>
/// Removes all elements in the specified sequence from the collection.
/// </summary>
public void RemoveRange(IEnumerable<T> items)
{
foreach (var item in items)
Comment thread
Tyrrrz marked this conversation as resolved.
Outdated
source.Remove(item);
}

/// <summary>
/// Removes all elements from the collection that match the specified predicate.
/// </summary>
Expand Down