Skip to content

Commit

Permalink
Decompose tests (WalletWasabi#13272)
Browse files Browse the repository at this point in the history
Unit tests for Decomposer.Decompose.

Fails on the current master, see: WalletWasabi#13260
  • Loading branch information
csiki2 authored Jul 15, 2024
1 parent 0b51943 commit 37cacd3
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,18 @@ private static Coin CreateCoin(Script scriptPubKey, long amount)
var txOut = new TxOut(Money.Satoshis(amount), scriptPubKey);
return new Coin(prevOut, txOut);
}

[Theory]
[InlineData(2, 7, 2, 3, new long[] { 8, 4, 2 })]
[InlineData(39, 728551029, 4999, 8, new long[] { 6973569112, 4294967606, 2324523244, 1162261777, 774841288, 536871222, 268435766, 134218038, 86093752, 50000310, 33554742, 20000310, 14349217, 10000310, 5000310, 3188956, 2097462, 1594633, 1063192, 531751, 354604, 262454, 200310, 131382, 100310, 65846, 50310, 39676, 33078, 20310, 16694, 13432, 10310 })]
public void DecomposeTests(int expectedResultCount, long target, long tolerance, int maxCount, long[] stdDenoms)
{
var denoms = stdDenoms.SkipWhile(x => x > target).ToArray();
var res = Decomposer.Decompose(target, tolerance, maxCount, denoms);

Assert.True(res.Count() == res.ToHashSet().Count);
Assert.True(expectedResultCount < 0 || res.Count() == expectedResultCount);
Assert.All(res, x => Assert.True(x.Sum == Decomposer.ToRealValuesArray(x.Decomposition, x.Count, denoms).Sum()));
Assert.All(res, x => Assert.True(target - x.Sum < tolerance));
}
}

0 comments on commit 37cacd3

Please sign in to comment.