diff --git a/Tests/CodexReleaseTests/Utils/PurchaseParams.cs b/Tests/CodexReleaseTests/Utils/PurchaseParams.cs index 483d6f36..eef539aa 100644 --- a/Tests/CodexReleaseTests/Utils/PurchaseParams.cs +++ b/Tests/CodexReleaseTests/Utils/PurchaseParams.cs @@ -33,7 +33,7 @@ namespace CodexReleaseTests.Utils var numSlotBlocks = 1 + ((numBlocks - 1) / Nodes); // round-up div. // Next power of two: - var numSlotBlocksPow2 = NextPowerOf2(numSlotBlocks); + var numSlotBlocksPow2 = IsOrNextPowerOf2(numSlotBlocks); return new ByteSize(blockSize.SizeInBytes * numSlotBlocksPow2); } @@ -51,8 +51,9 @@ namespace CodexReleaseTests.Utils return new ByteSize(blockSize.SizeInBytes * totalBlocks); } - private int NextPowerOf2(int n) + private int IsOrNextPowerOf2(int n) { + if (IsPowerOfTwo(n)) return n; n = n - 1; var lg = Convert.ToInt32(Math.Round(Math.Log2(Convert.ToDouble(n)))); return 1 << (lg + 1); @@ -63,5 +64,10 @@ namespace CodexReleaseTests.Utils var x = size.SizeInBytes; return (x != 0) && ((x & (x - 1)) == 0); } + + private static bool IsPowerOfTwo(int x) + { + return (x != 0) && ((x & (x - 1)) == 0); + } } }