-
Notifications
You must be signed in to change notification settings - Fork 292
/
ConsistentHash_Tests.cs
37 lines (31 loc) · 1.04 KB
/
ConsistentHash_Tests.cs
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
using System;
using Advanced.Algorithms.Distributed;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Advanced.Algorithms.Tests
{
[TestClass]
public class ConsistentHashTests
{
[TestMethod]
public void ConsistantHash_Smoke_Test()
{
var hash = new ConsistentHash<int>();
hash.AddNode(15);
hash.AddNode(25);
hash.AddNode(172);
for (var i = 200; i < 300; i++) hash.AddNode(i);
hash.RemoveNode(15);
hash.RemoveNode(172);
hash.RemoveNode(25);
var rnd = new Random();
for (var i = 0; i < 1000; i++)
{
Assert.AreNotEqual(15, hash.GetNode(rnd.Next().ToString()));
Assert.AreNotEqual(25, hash.GetNode(rnd.Next().ToString()));
Assert.AreNotEqual(172, hash.GetNode(rnd.Next().ToString()));
var t = hash.GetNode(rnd.Next().ToString());
Assert.IsTrue(t >= 200 && t < 300);
}
}
}
}