Exemple #1
0
def test_InitFromListDec():

    for x in range(10, 15):

        fx = str(randint(10, 100000))
        modulo = str(PyBigNumbers.GenerateRandPrimeDec(100))
        listCoefficients = []
        dec = 1

        for i in range(x):
            # Generate random coefficients for the polynomial
            listCoefficients.append(str(randint(100000, 1000000)))

        # create a Polynomial from a list of coefficients
        allCoeffeicient = PyPolynomial.initFromList(listCoefficients, dec)
        assert len(allCoeffeicient) == x, "Test failed"

        # Calling evaluate polynomial function
        polynomialFX = polynomialEvaluation(listCoefficients, fx, modulo, dec)

        # convert list of coefficients from string to decimal
        lst = []
        for i in range(len(allCoeffeicient)):
            lst.append(int(allCoeffeicient[i]))

        fx = int(fx)
        modulo = int(modulo)
        actualValue = polynomial_evaluate(lst, fx, modulo)
        assert polynomialFX == str(actualValue), "Test failed"
Exemple #2
0
def test_RandomPolynomialDec():

    for x in range(5):

        fx = PyBigNumbers.GenerateRandDec(256)
        degree = randint(10, 15)
        modulo = PyBigNumbers.GenerateRandPrimeDec(100)
        dec = 1

        # create a random polynomial
        listCoefficients = PyPolynomial.randomPolynomial(degree, modulo, dec)
        assert len(listCoefficients) == (degree + 1), "Test failed"

        # calling evaluate polynomial function
        polynomialFX = polynomialEvaluation(listCoefficients, fx, modulo, dec)
        # convert list of coefficients from string to decimal
        lst = []
        for i in range(len(listCoefficients)):

            lst.append(int(listCoefficients[i]))

        fx = int(fx)
        modulo = int(modulo)
        actualValue = polynomial_evaluate(lst, fx, modulo)
        assert polynomialFX == str(actualValue), "Test failed"
Exemple #3
0
def test_GenerateRandPrimeDec():

    #Generating prime decimal numbers with input parameter
    for x in range(10, 1000, 10):

        # Generate Random Prime Number of arbitary precision in dec
        primeDec_Value = PyBigNumbers.GenerateRandPrimeDec(x)

        # Verifying the actual value as prime number or not
        assert PyBigNumbers.isPrimeDec(primeDec_Value), "Test failed"
Exemple #4
0
def test_LGInterpolatorSingleDec():

    listTupleObj = [(1, "13"), (2, "4"), (3, "2"), (4, "5"), (5, "11"),
                    (6, "1")]
    modulo = str(PyBigNumbers.GenerateRandPrimeDec(100))
    dec = 1
    xValue = str(randint(10, 100000))

    for x in range(1, 6):
        xPoint = str(x)

        # LGInterpolator, evaluate the ith basis polynomial at xValue
        lgInterpolatorX = PyPolynomial.LGInterpolatorSingle(
            listTupleObj, modulo, xValue, xPoint, dec)
        assert type(lgInterpolatorX) == str, "Test failed"