Skip to content

Commit

Permalink
class data test
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardotondello committed Aug 3, 2024
1 parent f6ca838 commit cbee1bc
Showing 1 changed file with 31 additions and 34 deletions.
65 changes: 31 additions & 34 deletions LRU.Tests/LeastRecentlyUsedCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,41 +48,8 @@ public void Should_Not_Have_More_Than_Capacity(int capacity)
result.Should().BeFalse();
}


public static IEnumerable<object[]> TestCaseSourceForExpectedValues()
{
return new List<object[]>
{
new object[]
{
2, new[,]
{
{ 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 }
},
3, 3
},
new object[]
{
50, new[,]
{
{ 10, 90 }, { 20, 77 }, { 33, 5 }, { 35, 44 }, { 45, 89 }
},
45, 89
},
//repeated data test
new object[]
{
2, new[,]
{
{ 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }
},
3, 3
}
};
}

[Theory]
[MemberData(nameof(TestCaseSourceForExpectedValues))]
[ClassData(typeof(LruTestData))]
public void Should_Return_Expected_Value(int capacity, int[,] values, int key, int expected)
{
var cache = new LeastRecentlyUsedCache<int, int>(capacity);
Expand Down Expand Up @@ -348,4 +315,34 @@ public void Should_ReturnKeys_When_Get_Keys()

cache.Keys.Should().BeEquivalentTo(new List<int> { 1 });
}

public class LruTestData : TheoryData<int, int[,], int, int>
{
public LruTestData()
{
Add(
2, new[,]
{
{ 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 }
},
3, 3
);

Add(
50, new[,]
{
{ 10, 90 }, { 20, 77 }, { 33, 5 }, { 35, 44 }, { 45, 89 }
},
45, 89
);
//repeated data test
Add(
2, new[,]
{
{ 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }
},
3, 3
);
}
}
}

0 comments on commit cbee1bc

Please sign in to comment.