-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLFUTests.cs
More file actions
68 lines (54 loc) · 1.53 KB
/
LFUTests.cs
File metadata and controls
68 lines (54 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System.Globalization;
using AlgorithmsAndDataStructures.DataStructures.Cache;
using Xunit;
namespace AlgorithmsAndDataStructures.Tests.DataStructures.Cache;
public class LfuTests
{
[Fact]
public void CanInsertEntry()
{
var sut = new Lfu(1);
sut.Add(1, "Test");
}
[Fact]
public void CanGetEntry()
{
var sut = new Lfu(1);
sut.Add(1, "Test");
Assert.Equal("Test", sut.Get(1));
}
[Fact]
public void CanUpdateEntry()
{
var sut = new Lfu(1);
sut.Add(1, "Test");
sut.Add(1, "Test1");
Assert.Equal("Test1", sut.Get(1));
}
[Fact]
public void LeastFrequentlyUsedEntryRemoved()
{
var sut = new Lru(2);
sut.Add(1, "Test");
sut.Add(2, "Test1");
sut.Get(2);
sut.Add(3, "Test2");
Assert.Null(sut.Get(1));
Assert.Equal("Test1", sut.Get(2));
Assert.Equal("Test2", sut.Get(3));
}
[Fact]
public void Fuzzy()
{
var testCaseSize = 10;
var sut = new Lfu(testCaseSize);
for (var i = 0; i < testCaseSize - 1; i++) sut.Add(i, i.ToString(CultureInfo.InvariantCulture));
sut.Add(testCaseSize, testCaseSize.ToString(CultureInfo.InvariantCulture));
for (var i = testCaseSize + 1; i < testCaseSize * 2; i++)
{
for (var j = 0; j < testCaseSize; j++) sut.Get(j);
sut.Add(i, i.ToString(CultureInfo.InvariantCulture));
Assert.Null(sut.Get(i - testCaseSize - 1));
}
}
}