-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHashBucketTests.cs
More file actions
106 lines (81 loc) · 2.73 KB
/
HashBucketTests.cs
File metadata and controls
106 lines (81 loc) · 2.73 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
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Text;
using YellowCounter.FileSystemState.PathRedux;
using Shouldly;
namespace PathReduxTests.PathRedux
{
[TestClass]
public class HashBucketTests
{
[TestMethod]
public void HashBucketStoreRetrieve()
{
var m = new HashBucket(2, 2);
m.Store(0, 123456).ShouldBe(true);
m.Store(0, 765432).ShouldBe(true);
var result = m.Retrieve(0);
result.ToArray().ShouldBe(new[] { 123456, 765432 });
}
[TestMethod]
public void HashBucketStoreFlowpast()
{
var m = new HashBucket(2, 2);
m.Store(1, 123456).ShouldBe(true);
m.Store(1, 765432).ShouldBe(true);
var result = m.Retrieve(1);
result.ToArray().ShouldBe(new[] { 123456, 765432 });
}
[TestMethod]
public void HashBucketStoreZero()
{
var m = new HashBucket(2, 2);
// It can store a zero
m.Store(0, 0).ShouldBe(true);
var result = m.Retrieve(0);
result.ToArray().ShouldBe(new[] { 0 });
}
[TestMethod]
public void HashBucketChainLimit()
{
var m = new HashBucket(8, 2);
m.Store(0, 100).ShouldBe(true);
m.Store(0, 200).ShouldBe(true);
m.Store(0, 300).ShouldBe(false);
var result = m.Retrieve(0);
result.ToArray().ShouldBe(new[] { 100, 200 });
}
[TestMethod]
public void HashBucketOverlap()
{
var m = new HashBucket(8, 8);
// The values are going to overlap.
m.Store(0, 100).ShouldBe(true);
m.Store(1, 200).ShouldBe(true);
m.Store(0, 300).ShouldBe(true);
var result = m.Retrieve(0);
result.ToArray().ShouldBe(new[] { 100, 200, 300 });
}
[TestMethod]
public void HashBucketOverlapLimited()
{
var m = new HashBucket(8, 2);
// If we set the max chain to a lower value then the overlap
// won't occur.
m.Store(0, 100).ShouldBe(true);
m.Store(1, 200).ShouldBe(true);
m.Store(0, 300).ShouldBe(false);
m.Retrieve(0).ToArray().ShouldBe(new[] { 100, 200 });
m.Retrieve(1).ToArray().ShouldBe(new[] { 200 });
}
[TestMethod]
public void HashBucketWraparound()
{
var m = new HashBucket(4, 2);
m.Store(3, 100).ShouldBe(true);
m.Store(3, 200).ShouldBe(true);
m.Retrieve(3).ToArray().ShouldBe(new[] { 100, 200 });
}
}
}