Skip to content

Commit e361650

Browse files
author
Alex Peck
committed
capacity
1 parent b0e90cb commit e361650

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@ public ConcurrentLfuTests(ITestOutputHelper output)
2626
this.output = output;
2727
}
2828

29+
[Fact]
30+
public void WhenCapacityIsLessThan3CtorThrows()
31+
{
32+
Action constructor = () => { var x = new ConcurrentLfu<int, string>(2); };
33+
34+
constructor.Should().Throw<ArgumentOutOfRangeException>();
35+
}
36+
37+
[Fact]
38+
public void WhenCapacityIsValidCacheIsCreated()
39+
{
40+
var x = new ConcurrentLfu<int, string>(3);
41+
42+
x.Capacity.Should().Be(3);
43+
}
44+
45+
[Fact]
46+
public void WhenConcurrencyIsLessThan1CtorThrows()
47+
{
48+
Action constructor = () => { var x = new ConcurrentLfu<int, string>(0, 20, new ForegroundScheduler(), EqualityComparer<int>.Default); };
49+
50+
constructor.Should().Throw<ArgumentOutOfRangeException>();
51+
}
52+
2953
[Fact]
3054
public void DefaultSchedulerIsThreadPool()
3155
{

BitFaster.Caching/Lfu/ConcurrentLfu.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ internal struct ConcurrentLfuCore<K, V, N, P> : ICache<K, V>, IAsyncCache<K, V>,
309309

310310
public ConcurrentLfuCore(int concurrencyLevel, int capacity, IScheduler scheduler, IEqualityComparer<K> comparer, Action drainBuffers)
311311
{
312+
if (capacity < 3)
313+
Throw.ArgOutOfRange(nameof(capacity));
314+
312315
int dictionaryCapacity = ConcurrentDictionarySize.Estimate(capacity);
313316
this.dictionary = new (concurrencyLevel, dictionaryCapacity, comparer);
314317

0 commit comments

Comments
 (0)