47 lines
1.2 KiB
Java
47 lines
1.2 KiB
Java
|
package FeldmanVerifiableSecretSharing.ShamirSecretSharing.PolynomialTests;
|
||
|
|
||
|
import FeldmanVerifiableSecretSharing.ShamirSecretSharing.Polynomial;
|
||
|
import org.junit.Before;
|
||
|
import org.junit.Test;
|
||
|
|
||
|
import java.math.BigInteger;
|
||
|
import java.util.Random;
|
||
|
|
||
|
/**
|
||
|
* Created by Tzlil on 1/27/2016.
|
||
|
*/
|
||
|
public class MulByConstTest {
|
||
|
|
||
|
|
||
|
Polynomial[] arr1;
|
||
|
BigInteger[] arr2;
|
||
|
int tests = 1 << 12;
|
||
|
int maxDegree = 15;
|
||
|
int bits = 128;
|
||
|
Random random;
|
||
|
|
||
|
@Before
|
||
|
public void settings(){
|
||
|
random = new Random();
|
||
|
arr1 = new Polynomial[tests];
|
||
|
arr2 = new BigInteger[tests];
|
||
|
for (int i = 0; i < arr1.length; i++){
|
||
|
arr1[i] = Utils.generateRandomPolynomial(random.nextInt(maxDegree),bits,random);
|
||
|
arr2[i] = new BigInteger(bits,random);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void oneTest(Polynomial p, BigInteger c){
|
||
|
Polynomial product = p.mul(c);
|
||
|
BigInteger x = new BigInteger(bits,random);
|
||
|
assert(product.image(x).equals(p.image(x).multiply(c)));
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void mulByConstTest(){
|
||
|
for (int i = 0 ; i < arr1.length; i ++){
|
||
|
oneTest(arr1[i],arr2[i]);
|
||
|
}
|
||
|
}
|
||
|
}
|