package meerkat.crypto.secretsharing.shamir.PolynomialTests;

import meerkat.crypto.utils.GenerateRandomPolynomial;
import meerkat.crypto.utils.Z;
import meerkat.crypto.secretsharing.shamir.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] = GenerateRandomPolynomial.generateRandomPolynomial(random.nextInt(maxDegree),bits,random,new Z());
            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.evaluate(x).equals(p.evaluate(x).multiply(c)));
    }

    @Test
    public void mulByConstTest(){
        for (int i = 0 ; i < arr1.length; i ++){
            oneTest(arr1[i],arr2[i]);
        }
    }
}
