-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added comments and changed the positions of the files
- Loading branch information
Georgi Grigorov
committed
Oct 18, 2024
1 parent
c00fe3e
commit d1eb9f3
Showing
5 changed files
with
116 additions
and
40 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
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,88 @@ | ||
package com.limechain.babe; | ||
|
||
import com.limechain.chain.lightsyncstate.Authority; | ||
import org.javatuples.Pair; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.math.BigInteger; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class AuthorshipTest { | ||
|
||
@Test | ||
void testCalculatePrimaryThreshold() { | ||
var constant = new Pair<>(BigInteger.ONE, BigInteger.valueOf(4)); | ||
Authority authority1 = new Authority(new byte[32], BigInteger.ONE); | ||
Authority authority2 = new Authority(new byte[32], BigInteger.ONE); | ||
Authority authority3 = new Authority(new byte[32], BigInteger.ONE); | ||
|
||
var authorities = List.of(authority1, authority2, authority3); | ||
var result = Authorship.calculatePrimaryThreshold(constant, authorities, 0); | ||
assertEquals(new BigInteger("31115318766088776340791719032032067584"), result); | ||
} | ||
|
||
|
||
@Test | ||
void testCalculatePrimaryThresholdWithConstantNumeratorEqualsZero() { | ||
var constant = new Pair<>(BigInteger.ZERO, BigInteger.valueOf(4)); | ||
Authority authority1 = new Authority(new byte[32], BigInteger.ONE); | ||
Authority authority2 = new Authority(new byte[32], BigInteger.ONE); | ||
Authority authority3 = new Authority(new byte[32], BigInteger.ONE); | ||
|
||
var authorities = List.of(authority1, authority2, authority3); | ||
var result = Authorship.calculatePrimaryThreshold(constant, authorities, 0); | ||
assertEquals(new BigInteger("0"), result); | ||
} | ||
|
||
@Test | ||
void testCalculatePrimaryThresholdWithConstantDenominatorEqualsZero() { | ||
var constant = new Pair<>(BigInteger.ONE, BigInteger.ZERO); | ||
Authority authority1 = new Authority(new byte[32], BigInteger.ONE); | ||
Authority authority2 = new Authority(new byte[32], BigInteger.ONE); | ||
Authority authority3 = new Authority(new byte[32], BigInteger.ONE); | ||
|
||
var authorities = List.of(authority1, authority2, authority3); | ||
assertThrows(IllegalArgumentException.class, | ||
() -> Authorship.calculatePrimaryThreshold(constant, authorities, 0)); | ||
} | ||
|
||
@Test | ||
void testCalculatePrimaryThresholdWithBabeConstantOutOfRange() { | ||
var constant = new Pair<>(BigInteger.TEN, BigInteger.ONE); | ||
Authority authority1 = new Authority(new byte[32], BigInteger.ONE); | ||
Authority authority2 = new Authority(new byte[32], BigInteger.ONE); | ||
Authority authority3 = new Authority(new byte[32], BigInteger.ONE); | ||
|
||
var authorities = List.of(authority1, authority2, authority3); | ||
assertThrows(IllegalStateException.class, | ||
() -> Authorship.calculatePrimaryThreshold(constant, authorities, 0)); | ||
} | ||
|
||
@Test | ||
void testCalculatePrimaryThresholdWithAuthorityIndexOutOfBounds() { | ||
var constant = new Pair<>(BigInteger.ONE, BigInteger.valueOf(4)); | ||
Authority authority1 = new Authority(new byte[32], BigInteger.ONE); | ||
Authority authority2 = new Authority(new byte[32], BigInteger.ONE); | ||
Authority authority3 = new Authority(new byte[32], BigInteger.ONE); | ||
|
||
var authorities = List.of(authority1, authority2, authority3); | ||
var nonExistingIndex = Integer.MAX_VALUE; | ||
assertThrows(IllegalArgumentException.class, | ||
() -> Authorship.calculatePrimaryThreshold(constant, authorities, nonExistingIndex)); | ||
} | ||
|
||
@Test | ||
void testCalculatePrimaryThresholdWithNegativeAuthorityIndex() { | ||
var constant = new Pair<>(BigInteger.ONE, BigInteger.valueOf(4)); | ||
Authority authority1 = new Authority(new byte[32], BigInteger.ONE); | ||
Authority authority2 = new Authority(new byte[32], BigInteger.ONE); | ||
Authority authority3 = new Authority(new byte[32], BigInteger.ONE); | ||
|
||
var authorities = List.of(authority1, authority2, authority3); | ||
assertThrows(IllegalArgumentException.class, | ||
() -> Authorship.calculatePrimaryThreshold(constant, authorities, -1)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
5 changes: 2 additions & 3 deletions
5
.../com/limechain/utils/BigRationalTest.java → ...limechain/utils/math/BigRationalTest.java
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