-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MergeMultiple method for merging more than two TDigest-s at once
- Loading branch information
1 parent
5d9a277
commit 4a060b6
Showing
3 changed files
with
188 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
namespace TDigestNet.Tests; | ||
|
||
public class TestMergeMultiple : TestBase | ||
{ | ||
private readonly Random _rand = new(); | ||
private readonly List<double> _actual = new(); | ||
private readonly TDigest _digestA = new(); | ||
private readonly TDigest _digestB = new(); | ||
private readonly TDigest _digestC = new(); | ||
private readonly TDigest _digestD = new(); | ||
private readonly TDigest _merged; | ||
|
||
public TestMergeMultiple() | ||
{ | ||
for (int i = 0; i < 10000; i++) | ||
{ | ||
var n = (_rand.Next() % 50) + (_rand.Next() % 50); | ||
_digestA.Add(n); | ||
_actual.Add(n); | ||
} | ||
|
||
for (int i = 0; i < 10000; i++) | ||
{ | ||
var n = (_rand.Next() % 100) + (_rand.Next() % 100); | ||
_digestB.Add(n); | ||
_actual.Add(n); | ||
} | ||
|
||
for (int i = 0; i < 10000; i++) | ||
{ | ||
var n = (_rand.Next() % 50) + (_rand.Next() % 50) + 100; | ||
_digestC.Add(n); | ||
_actual.Add(n); | ||
} | ||
|
||
for (int i = 0; i < 10000; i++) | ||
{ | ||
var n = (_rand.Next() % 100) + (_rand.Next() % 100) + 100; | ||
_digestD.Add(n); | ||
_actual.Add(n); | ||
} | ||
|
||
_actual.Sort(); | ||
|
||
_merged = TDigest.MergeMultiple(_digestA, _digestB, _digestC, _digestD); | ||
} | ||
|
||
[Test, Order(0)] | ||
public void ValidateStructure() => ValidateInternalTree(_merged); | ||
|
||
[Test, Order(1)] | ||
public void TestNotNull() => Assert.IsNotNull(_merged); | ||
|
||
[Test] | ||
public void TestCount() => Assert.That(_actual.Count, Is.EqualTo(_merged.Count)); | ||
|
||
[Test] | ||
public void TestAvgError() => Assert.That(GetAvgError(_actual, _merged!), Is.LessThan(.01)); | ||
|
||
[Test] | ||
public void TestAvgPercentileError() => Assert.That(GetAvgPercentileError(_actual, _merged), Is.LessThan(1)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters