-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathTestBuckets64.cs
More file actions
120 lines (100 loc) · 3.19 KB
/
TestBuckets64.cs
File metadata and controls
120 lines (100 loc) · 3.19 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ProbabilisticDataStructures;
namespace TestProbabilisticDataStructures
{
[TestClass]
public class TestBuckets64
{
/// <summary>
/// Ensures that Max returns the correct maximum based on the bucket
/// size.
/// </summary>
[TestMethod]
public void TestMaxBucketValue()
{
var b = new Buckets64(10, 2);
var max = b.MaxBucketValue();
Assert.AreEqual(3, max);
}
/// <summary>
/// Ensures that Count returns the number of buckets.
/// </summary>
[TestMethod]
public void TestBuckets64Count()
{
var b = new Buckets64(10, 2);
var count = b.count;
Assert.AreEqual(10u, count);
}
/// <summary>
/// Ensures that Increment increments the bucket value by the correct delta and
/// clamps to zero and the maximum, Get returns the correct bucket value, and Set
/// sets the bucket value correctly.
/// </summary>
[TestMethod]
public void TestBuckets64IncrementAndGetAndSet()
{
var b = new Buckets64(5, 2);
var incrementedB = b.Increment(0, 1);
Assert.AreSame(b, incrementedB, "Returned Buckets64 should be the same instance");
var v = b.Get(0);
Assert.AreEqual(1u, v);
b.Increment(1u, -1);
v = b.Get(1);
Assert.AreEqual(0u, v);
var setB = b.Set(2u, 100);
Assert.AreSame(b, setB, "Returned Buckets64 should be the same instance");
v = b.Get(2);
Assert.AreEqual(3u, v);
b.Increment(3, 2);
v = b.Get(3);
Assert.AreEqual(2u, v);
}
/// <summary>
/// Ensures that Reset restores the Buckets64 to the original state.
/// </summary>
[TestMethod]
public void TestBuckets64Reset()
{
var b = new Buckets64(5, 2);
for (uint i = 0; i < 5; i++)
{
b.Increment(i, 1);
}
var resetB = b.Reset();
Assert.AreSame(b, resetB, "Returned Buckets64 should be the same instance");
for (uint i = 0; i < 5; i++)
{
var c = b.Get(i);
Assert.AreEqual(0u, c);
}
}
[TestMethod]
public void BenchmarkBuckets64Increment()
{
var buckets = new Buckets64(10000, 10);
for (uint i = 0; i < buckets.count; i++)
{
buckets.Increment(i % 10000, 1);
}
}
[TestMethod]
public void BenchmarkBuckets64Set()
{
var buckets = new Buckets64(10000, 10);
for (uint i = 0; i < buckets.count; i++)
{
buckets.Set(i % 10000, 1);
}
}
[TestMethod]
public void BenchmarkBuckets64Get()
{
var buckets = new Buckets64(10000, 10);
for (uint i = 0; i < buckets.count; i++)
{
buckets.Get(i % 10000);
}
}
}
}