示例#1
0
def test_muldiv():

    assert quickTest(
        "x^3 * x^2", multiplication
    ) == "x^(3.0)x^(2.0)"  # FIXME: Further simplification required

    assert quickTest("x^2 / x^2", division) == "1.0"
    assert quickTest("x^4 / x^2", division) == "x^(2.0)"
    assert quickTest("x^2 / x^4", division) == "x^(-2.0)"
示例#2
0
def test_integrate():

    assert quickTest("x + 1", integrate, 'x') == "0.5x^(2)+x"

    assert quickTest(
        "xyz + xy/z + x + 1 + 1/x", integrate, 'x'
    ) == "0.5x^(2)yz+0.5x^(2)yz^(-1)+0.5x^(2)+x+1.0*log(x)"  # FIXME(integration.py): Ignore coeff if 1
    assert quickTest("xyz + xy/z + x + 1 + 1/x", integrate,
                     'y') == "0.5xy^(2)z+0.5xy^(2)z^(-1)+xy+y+x^(-1)y"
    assert quickTest("xyz + xy/z + x + 1 + 1/x", integrate,
                     'z') == "0.5xyz^(2)+xy*log(z)+xz+z+x^(-1)z"
示例#3
0
def test_differentiate():

    assert quickTest("x^2 + x", differentiate, 'x') == "2.0x+1"

    assert quickTest("x + 2y + 3z + 4", differentiate, 'x') == "1"
    # FIXME(tokensToString error): assert quickTest("x + 2y + 3z + 4", differentiate, 'y') == "2"
    # FIXME(tokensToString error): assert quickTest("x + 2y + 3z + 4", differentiate, 'z') == "3"

    assert quickTest("xy + xy^2 + xyz", differentiate, 'x') == "y+y^(2.0)+yz"
    assert quickTest("xy + xy^2 + xyz", differentiate, 'y') == "x+2.0xy+xz"
    assert quickTest("xy + xy^2 + xyz", differentiate,
                     'z') == "+xy"  # FIXME: Remove unnecessary sign '+'
示例#4
0
def test_solveFor():

    assert quickTest("x - 1 + 2 = 0", solveFor, 'x') == "x=(-1.0)"
    assert quickTest("1 + y^2 = 0", solveFor, 'y') == "y=(-1.0)^(0.5)"
    assert quickTest("x^2 - 1 = 0", solveFor, 'x') == "x=(1.0)^(0.5)"

    assert quickTest("x - yz + 1= 0", solveFor, 'x') == "x=(-1.0+yz)"
    assert quickTest("x - 2yz + 1= 0", solveFor, 'y') == "y=-0.5*((-1.0-x)/z)"
    assert quickTest("x - 5yz + 1= 0", solveFor, 'z') == "z=-0.2*((-1.0-x)/y)"

    assert quickTest("w + x^2 + yz^3 = 1", solveFor, 'w') == "w=(-x^(2.0)-yz^(3.0)+1.0)"
    assert quickTest("w + x^2 + yz^3 = 1", solveFor, 'x') == "x=(-w-yz^(3.0)+1.0)^(0.5)"
    assert quickTest("w + x^2 + yz^3 = 1", solveFor, 'y') == "y=((-w-x^(2.0)+1.0)/z^(3.0))"
    assert quickTest("w + x^2 + yz^3 = 1", solveFor, 'z') == "z=((-w-x^(2.0)+1.0)/y)^(0.3333333333333333)"
示例#5
0
def test_integrate():

    assert quickTest("x + 1", integrate, 'x') == "0.5x^(2.0)+x"

    assert quickTest(
        "xyz + xy/z + x + 1 + 1/x", integrate, 'x'
    ) == "0.5x^(2.0)yz+0.5x^(2.0)yz^(-1.0)+0.5x^(2.0)+x+1.0*log(x)"  # FIXME(integration.py): Ignore coeff if 1
    assert quickTest("xyz + xy/z + x + 1 + 1/x", integrate,
                     'y') == "0.5xy^(2.0)z+0.5xy^(2.0)z^(-1.0)+xy+y+x^(-1.0)y"
    assert quickTest("xyz + xy/z + x + 1 + 1/x", integrate,
                     'z') == "0.5xyz^(2.0)+xy*log(z)+xz+z+x^(-1.0)z"

    assert quickTest("sin(x)", integrate, 'x') == "-1.0*cos(x)"
    assert quickTest("cos(x)", integrate, 'x') == "sin(x)"
    assert quickTest("tan(x)", integrate, 'x') == "-1.0*ln(cos(x))"
    assert quickTest("csc(x)", integrate, 'x') == "-1.0*ln((csc(x)+cot(x)))"
    assert quickTest("sec(x)", integrate, 'x') == "ln((sec(x)+tan(x)))"
    assert quickTest("cot(x)", integrate, 'x') == "ln(sin(x))"
示例#6
0
def test_factorize():
    assert quickTest("x", factorize) == "x"
    assert quickTest("x^2 + 2x + 1", factorize) == "(x+1.0)*(x+1.0)"
    assert quickTest("2x^2 - 4x + 2", factorize) == "2.0*(x-1.0)*(x-1.0)"
    assert quickTest("x^4 - 1", factorize) == "(x+1.0)*(x-1.0)*(x^(2)+1.0)"
    assert quickTest("1 - x^3", factorize) == "(x-1.0)*(-x^(2)-x-1.0)"
    assert quickTest("x^4 - 5x^2 + 4", factorize) == "(x+2.0)*(x+1.0)*(x-1.0)*(x-2.0)"
示例#7
0
def test_muldiv():

    assert quickTest("3*y + x*2", multiplication) == "3.0y+2.0x"
    assert quickTest("x^3 * x^2", multiplication) == "x^(5.0)"
    assert quickTest("x^(-1)y^2 * zx^2", multiplication) == "xy^(2.0)z"

    assert quickTest("x^2 / x^2", division) == "1.0"
    assert quickTest("x^2 / x^4", division) == "x^(-2.0)"
    assert quickTest("x^(-1)y^2 / zx^2", division) == "x^(-3.0)y^(2.0)z^(-1)"
示例#8
0
def test_statistics():

    assert quickTest([12, 1, -12, -1, 0], ArithemeticMean) == "0.0"
    assert quickTest([11, 1, -2, -1, 0], ArithemeticMean) == "1.8"

    assert quickTest([12, 12, 12, 12, 1, -12, -1, 0],
                     Mode) == "Mode=12;ModeFrequency=4"
    assert quickTest([-1, -1, 2, 3, 4, 5, 6],
                     Mode) == "Mode=-1;ModeFrequency=2"

    assert quickTest([1, 2, 3, 4, 5], Median) == "3"
    assert quickTest([1, 2, 3, 4, 5, 12], Median) == "3.5"
示例#9
0
def test_factorial():

    assert quickTest("5", factorial) == "120.0"
    assert quickTest("0", factorial) == "1"
    assert quickTest("11", factorial) == "39916800.0"
    assert quickTest("11 - 11", factorial) == "1"
示例#10
0
def test_combination():

    assert quickTest("5;2", combination) == "10.0"
    assert quickTest("2;2", permutation) == "2.0"
    assert quickTest("11;0", permutation) == "1.0"
    assert quickTest("11;11 - 11", permutation) == "1.0"
示例#11
0
def test_permutation():

    assert quickTest("5;2", permutation) == "20.0"
    assert quickTest("12;3", permutation) == "1320.0"
    assert quickTest("10 + 2;5 - 2", permutation) == "1320.0"
    assert quickTest("11;11", permutation) == "39916800.0"
示例#12
0
def test_addsub():

    assert quickTest("1 + 2", addition) == "3.0"
    assert quickTest("x + 2x", addition) == "3.0x"
    assert quickTest("xy^2 + 2xy^2", addition) == "3.0xy^(2.0)"
    assert quickTest("-1 + 2", addition) == "1.0"
    assert quickTest("-x + 2x", addition) == "x"
    assert quickTest("-xy^2 + 3xy^2", addition) == "2.0xy^(2.0)"
    assert quickTest("1 + 0", addition) == "1.0"
    assert quickTest("1 + 2 + 3", addition) == "6.0"
    assert quickTest("1 + 2 + x + 3x", addition) == "3.0+4.0x"

    assert quickTest("1 + 2 = x + 3x", additionEquation) == "3.0=4.0x"
    assert quickTest("y + 2 = -x + x", additionEquation) == "y+2.0=0"

    assert quickTest("1 - 2", subtraction) == "-1.0"
    assert quickTest("x - 2x", subtraction) == "-x"
    assert quickTest("xy^2 - 3xy^2", subtraction) == "-2.0xy^(2.0)"

    assert quickTest("1 - 2 = x - 3x", subtractionEquation) == "-1.0=-2.0x"
    assert quickTest("y + 2 = -x - x", subtractionEquation) == "y+2.0=-2.0x"
示例#13
0
def test_simplify():

    assert quickTest("1 + 2 - 3", simplify) == "0"
    assert quickTest("1 + 2 - 4", simplify) == "-1.0"

    assert quickTest("3*2 + 4*2 - 3*4", simplify) == "2.0"
    assert quickTest("3*x + 4*x - 2*y", simplify) == "7.0x-2.0y"
    assert quickTest("x*y + x*x + x*x^2 + x^2*x + x*y^2 + x^2*y",
                     simplify) == "xy+x^(2)+2x^(3.0)+xy^(2.0)+x^(2.0)y"

    assert quickTest("3/2 + 4/2 - 2/4", simplify) == "3.0"
    assert quickTest("x/5 + x/4 - 2/y", simplify) == "0.45x-2.0y^(-1)"
    assert quickTest(
        "x/y + x/x + x/x^2 + x^2/x + x/y^2 + x^2/y + x + 1",
        simplify) == "xy^(-1)+x^(-1.0)+xy^(-2.0)+x^(2.0)y^(-1)+2.0x+2.0"

    assert quickTest("1 + 2 = 3",
                     simplifyEquation) == "=0"  # FIXME: Vanishing zero
    assert quickTest("1 + 2 = 4", simplifyEquation) == "-1.0=0"

    assert quickTest("3*2 + 4*2 = 3*4", simplifyEquation) == "2.0=0"
    assert quickTest("3*x = 4*x + 2*y", simplifyEquation) == "-x-2.0y=0"
    assert quickTest("1 - 1 = 3*x + 4*x + 2*y",
                     simplifyEquation) == "7.0x+2.0y=0"

    assert quickTest(
        "x = y --1 --x^2", simplifyEquation
    ) == "x-y-1.0-x^(2.0)=0"  # FIXME: Valid but silly input case

    assert quickTest("4 = 3x - 4x - 1 + 2", simplifyEquation) == "3.0+x=0"
    assert quickTest("z = x^2 - x + 1 - 2",
                     simplifyEquation) == "z-x^(2.0)+x+1.0=0"
    assert quickTest(
        "x = -1 + 2", simplifyEquation
    ) == "x+1.0-2.0=0"  # FIXME: Further simplification required (simplification in RHS)
    assert quickTest("x*y + x*x + x*x^2 = x^2*x + x*y^2 + x^2*y",
                     simplifyEquation) == "xy+x^(2)-xy^(2.0)-x^(2.0)y=0"

    assert quickTest("3/2 + 4/2 = 2/4", simplifyEquation) == "3.0=0"
    assert quickTest("x/5 + x/4 = 2/y",
                     simplifyEquation) == "0.45x-2.0y^(-1)=0"
    assert quickTest(
        "x/y + x/x + x/x^2 + x^2/x = x/y^2 + x^2/y + x - 1",
        simplifyEquation) == "xy^(-1)+2.0+x^(-1.0)-xy^(-2.0)-x^(2.0)y^(-1)=0"
示例#14
0
def test_differentiate():

    assert quickTest("x^2 + x", differentiate, 'x') == "2.0x+1.0"

    assert quickTest("x + 2y + 3z + 4", differentiate, 'x') == "1.0"
    assert quickTest("x + 2y + 3z + 4", differentiate, 'y') == "2.0"
    assert quickTest("x + 2y + 3z + 4", differentiate, 'z') == "3.0"

    assert quickTest("xy + xy^2 + xyz", differentiate, 'x') == "y+y^(2.0)+yz"
    assert quickTest("xy + xy^2 + xyz", differentiate, 'y') == "x+2.0xy+xz"
    assert quickTest("xy + xy^2 + xyz", differentiate, 'z') == "xy"

    assert quickTest("xy + z", differentiate, 'z') == "1.0"
    assert quickTest("z + xy", differentiate, 'z') == "1.0"
    assert quickTest("z - xy", differentiate, 'z') == "1.0"
    assert quickTest("xy - z", differentiate, 'z') == "-1.0"

    assert quickTest("sin(x)", differentiate, 'x') == "cos(x)*1.0"
    assert quickTest("sin(x)", differentiate, 'y') == "0.0"
    assert quickTest("sin(xxx)", differentiate,
                     'x') == "cos(x^(3.0))*3.0x^(2.0)"
    assert quickTest("sin(log(xx))", differentiate,
                     'x') == "cos(log(x^(2.0)))*x^(-1.0)*2.0x"

    assert quickTest("cos(x)", differentiate, 'x') == "-1.0*sin(x)*1.0"
    assert quickTest("cos(x)", differentiate, 'y') == "0.0"
    assert quickTest("cos(xxx)", differentiate,
                     'x') == "-1.0*sin(x^(3.0))*3.0x^(2.0)"
    assert quickTest("cos(log(xx))", differentiate,
                     'x') == "-1.0*sin(log(x^(2.0)))*x^(-1.0)*2.0x"

    assert quickTest("tan(x)", differentiate, 'x') == "sec(x)*1.0"
    # FIXME: Simplify module simplifies sec^2(x) as sec(x) and cosec^2(x) as cosec(x), however differentiation modules give correct output
    assert quickTest("tan(x)", differentiate, 'y') == "0.0"

    assert quickTest("cot(x)", differentiate, 'x') == "-1.0*csc(x)*1.0"
    # FIXME: Simplify module simplifies sec^2(x) as sec(x) and cosec^2(x) as cosec(x), however differentiation modules give correct output
    assert quickTest("cot(x)", differentiate, 'y') == "0.0"

    assert quickTest("csc(x)", differentiate, 'x') == "-1.0*csc(x)*cot(x)*1.0"
    assert quickTest("csc(x)", differentiate, 'y') == "0.0"

    assert quickTest("sec(x)", differentiate, 'x') == "sec(x)*tan(x)*1.0"
    assert quickTest("sec(x)", differentiate, 'y') == "0.0"

    assert quickTest("log(x)", differentiate, 'x') == "x^(-1.0)"
    assert quickTest("log(xx)", differentiate, 'x') == "2.0"

    # Tests for Product Rule of Differentiation.
    assert quickTest("sin(x)*cos(x)", differentiationProductRule,
                     'x') == "(cos(x)*1.0)*cos(x)+sin(x)*(-1.0*sin(x)*1.0)"
    assert quickTest("sin(x)*x", differentiationProductRule,
                     'x') == "(cos(x)*1.0)*x+sin(x)*(1.0)"
    assert quickTest("sin(x)*y", differentiationProductRule,
                     'x') == "(cos(x)*1.0)*y+sin(x)*(0.0)"
    assert quickTest(
        "sin(x)*cos(x)*sec(x)", differentiationProductRule, 'x'
    ) == "(cos(x)*1.0)*cos(x)*sec(x)+sin(x)*(-1.0*sin(x)*1.0)*sec(x)+sin(x)*cos(x)*(sec(x)*tan(x)*1.0)"
示例#15
0
def test_simplify():

    assert quickTest("1 + 2 - 3", simplify) == "0"
    assert quickTest("1 + 2 - 4", simplify) == "-1.0"
    assert quickTest("0 + 0 + 1", simplify) == "1.0"
    assert quickTest("0 + 0 + xyz", simplify) == "xyz"

    assert quickTest("(2 + 3) * (4 + 5) * (6 + 7)", simplify) == "585.0"
    assert quickTest("3 * (3 * (3 * ( 3 * 3)))", simplify) == "243.0"
    assert quickTest("3 + (3 + (3 * 1))", simplify) == "9.0"
    assert quickTest("3 - (1 - 3 - (1 + 2))", simplify) == "8.0"

    assert quickTest("3*2 + 4*2 - 3*4", simplify) == "2.0"
    assert quickTest("3*x + 4*x - 2*y", simplify) == "7.0x-2.0y"
    assert quickTest("x*y + x*x + x*x^2 + x^2*x + x*y^2 + x^2*y",
                     simplify) == "xy+x^(2)+2x^(3.0)+xy^(2.0)+x^(2.0)y"

    assert quickTest("3/2 + 4/2 - 2/4", simplify) == "3.0"
    assert quickTest("x/5 + x/4 - 2/y", simplify) == "0.45x-2.0y^(-1)"
    assert quickTest(
        "x/y + x/x + x/x^2 + x^2/x + x/y^2 + x^2/y + x + 1",
        simplify) == "xy^(-1)+x^(-1.0)+xy^(-2.0)+x^(2.0)y^(-1)+2.0x+2.0"

    assert quickTest("1 + 2 = 3",
                     simplifyEquation) == "=0"  # FIXME: Vanishing zero
    assert quickTest("1 + 2 = 4", simplifyEquation) == "-1.0=0"

    assert quickTest("3*2 + 4*2 = 3*4", simplifyEquation) == "2.0=0"
    assert quickTest("3*x = 4*x + 2*y", simplifyEquation) == "-x-2.0y=0"
    assert quickTest("1 - 1 = 3*x + 4*x + 2*y",
                     simplifyEquation) == "7.0x+2.0y=0"

    assert quickTest(
        "x = y --1 --x^2", simplifyEquation
    ) == "x-y-1.0-x^(2.0)=0"  # FIXME: Valid but silly input case

    assert quickTest("4 = 3x - 4x - 1 + 2", simplifyEquation) == "3.0+x=0"
    assert quickTest("z = x^2 - x + 1 - 2",
                     simplifyEquation) == "z-x^(2.0)+x+1.0=0"
    assert quickTest(
        "x = -1 + 2", simplifyEquation
    ) == "x+1.0-2.0=0"  # FIXME: Further simplification required (simplification in RHS)
    assert quickTest("x*y + x*x + x*x^2 = x^2*x + x*y^2 + x^2*y",
                     simplifyEquation) == "xy+x^(2)-xy^(2.0)-x^(2.0)y=0"

    assert quickTest("3/2 + 4/2 = 2/4", simplifyEquation) == "3.0=0"
    assert quickTest("x/5 + x/4 = 2/y",
                     simplifyEquation) == "0.45x-2.0y^(-1)=0"
    assert quickTest(
        "x/y + x/x + x/x^2 + x^2/x = x/y^2 + x^2/y + x - 1",
        simplifyEquation) == "xy^(-1)+2.0+x^(-1.0)-xy^(-2.0)-x^(2.0)y^(-1)=0"

    # Tests regarding Expression used in equations
    assert quickTest("(1 + 2) = ( 3 + 44)", simplifyEquation) == "-44.0=0"
    assert quickTest("x = -1 * (z + 10)", simplifyEquation) == "x+z+10.0=0"
    assert quickTest("x = 2*(z + q)", simplifyEquation) == "x-2.0z-2.0q=0"

    # Tests regarding Expression Simplifications
    assert quickTest("(x + 1) * (x + 1) * (x + 1)",
                     simplify) == "x^(3.0)+3x^(2.0)+3x+1.0"
    assert quickTest("(x + 1) * (x - 1) + (x + 2)",
                     simplify) == "x^(2.0)+1.0+x"
    assert quickTest("(x + 1) + (x - 1)", simplify) == "2x"
    assert quickTest("(x + 1) * (x * (1 + x))",
                     simplify) == "2x^(2.0)+x^(3.0)+x"
    assert quickTest("(x + 1) * (x - 1) + (100 + 1)",
                     simplify) == "x^(2.0)+100.0"
    assert quickTest("((x + 1) * (x - 1) + (100 + 1))",
                     simplify) == "x^(2.0)+100.0"
    #  assert quickTest("-1 * (- x - 1)", simplify) == "x--1"   FIXME: case should have a probably fix with the overlaoding of Constant Function

    # Tests regarding Exponents & Expressions
    assert quickTest("(x + 1)^3", simplify) == "x^(3.0)+3x^(2.0)+3x+1.0"
    assert quickTest("(x + 1)^2*x", simplify) == "x^(3.0)+2x^(2.0)+x"
    assert quickTest("x*(x + 1)^2*x", simplify) == "x^(4.0)+2x^(3.0)+x^(2.0)"
    assert quickTest(
        "(x+1)^2*(x + 2)^3*x", simplify
    ) == "x^(6.0)+8.0x^(5.0)+25.0x^(4.0)+38.0x^(3.0)+28.0x^(2.0)+8.0x"
    assert quickTest("(x + 1)^(1 + 1)*x", simplify) == "x^(3.0)+2x^(2.0)+x"
    assert quickTest("(x + 1)^(3 + 0 + 0)",
                     simplify) == "x^(3.0)+3x^(2.0)+3x+1.0"

    assert quickTest("3^(1 + 1)", simplify) == "9.0"
    assert quickTest("2^(3/2) + 12", simplify) == "2.0^1.5+12.0"
    assert quickTest("2^(4/2) + 12", simplify) == "16.0"
    assert quickTest("(1 + 2)^(1 + 1)", simplify) == "9.0"
    assert quickTest("(1 + 3)^(x) + (2 + 3)^(x)", simplify) == "4.0^x+5.0^x"
    assert quickTest("(1 + 3)^(1/3) + (2 + 3)^(2/3)",
                     simplify) == "4.0^0.33+5.0^0.67"
示例#16
0
def test_quadraticRoots():

    assert quickTest("x^2 + 2x + 1 = 0", quadraticRoots) == "(x+1.0)^(2)=0"
    assert quickTest("x^2 + 2x = - 1", quadraticRoots) == "(x+1.0)^(2)=0"
    assert quickTest("x^2 = - 2x - 1", quadraticRoots) == "(x+1.0)^(2)=0"
    assert quickTest("0 = x^2 + 2x + 1", quadraticRoots) == "(x+1.0)^(2)=0"

    assert quickTest("x^2 + 1 - 2x = 0", quadraticRoots) == "(x-1.0)^(2)=0"
    assert quickTest("x^2 + 1 = 2x", quadraticRoots) == "(x-1.0)^(2)=0"
    assert quickTest("x^2 = 2x - 1", quadraticRoots) == "(x-1.0)^(2)=0"
    assert quickTest("-2x = - x^2 - 1", quadraticRoots) == "(x-1.0)^(2)=0"
    # FIXME: assert quickTest("0 = 2x - x^2 - 1", quadraticRoots) == "(x-1.0)^(2)=0"

    assert quickTest("2x^2 - 4x - 6 = 0",
                     quadraticRoots) == "(x+1.0)*(x-3.0)=0"
    assert quickTest("3x^2 + 7x + 1 = 0",
                     quadraticRoots) == "(x+2.18)*(x+0.15)=0"
    assert quickTest("3x^2 - 7x + 1 = 0",
                     quadraticRoots) == "(x-0.15)*(x-2.18)=0"

    assert quickTest("x^2 + x + 1 = 0", quadraticRoots
                     ) == "(x+0.5+0.87*sqrt[2](-1))*(x+0.5-0.87*sqrt[2](-1))=0"
    assert quickTest("x^2 - x + 1 = 0", quadraticRoots
                     ) == "(x-0.5+0.87*sqrt[2](-1))*(x-0.5-0.87*sqrt[2](-1))=0"
示例#17
0
def test_rootFinder():

    #  Tests for Quadratic (2nd Degree) Equations
    assert quickTest("x^2 + 2x + 1 = 0", rootFinder) == "(x+1.0)^(2)=0"
    assert quickTest("x^2 + 2x = - 1", rootFinder) == "(x+1.0)^(2)=0"
    assert quickTest("x^2 = - 2x - 1", rootFinder) == "(x+1.0)^(2)=0"
    assert quickTest("0 = x^2 + 2x + 1", rootFinder) == "(x+1.0)^(2)=0"

    assert quickTest("x^2 + 1 - 2x = 0", rootFinder) == "(x-1.0)^(2)=0"
    assert quickTest("x^2 + 1 = 2x", rootFinder) == "(x-1.0)^(2)=0"
    assert quickTest("x^2 = 2x - 1", rootFinder) == "(x-1.0)^(2)=0"
    assert quickTest("-2x = - x^2 - 1", rootFinder) == "(x-1.0)^(2)=0"
    # FIXME: assert quickTest("0 = 2x - x^2 - 1", rootFinder) == "(x-1.0)^(2)=0"
    # assert quickTest("0 = 2x - x^2 - 1", rootFinder) == "(x-1.0)^(2)=0"

    assert quickTest("2x^2 - 4x - 6 = 0", rootFinder) == "(x+1.0)*(x-3.0)=0"
    assert quickTest("3x^2 + 7x + 1 = 0", rootFinder) == "(x+2.18)*(x+0.15)=0"
    assert quickTest("3x^2 - 7x + 1 = 0", rootFinder) == "(x-0.15)*(x-2.18)=0"

    assert quickTest("x^2 + x + 1 = 0", rootFinder) == "(x+0.5+0.87*sqrt[2](-1))*(x+0.5-0.87*sqrt[2](-1))=0"
    assert quickTest("x^2 - x + 1 = 0", rootFinder) == "(x-0.5+0.87*sqrt[2](-1))*(x-0.5-0.87*sqrt[2](-1))=0"

    # Tests for Cubic (3rd Degree) Equations
    assert quickTest("2x^3 - 4x^2 - 22x + 24 = 0", rootFinder) == "(x-4.0)*(x+3.0)*(x-1.0)=0"
    assert quickTest("x^3 + 6x^2 + 12x + 8 = 0", rootFinder) == "(x+2.0)^(3)=0"
    assert quickTest("x^3 = 1", rootFinder) == "(x-1.0)*(x-(-0.5+0.87*sqrt[2](-1)))*(x-(-0.5-0.87*sqrt[2](-1)))=0"

    # Tests for Quartic (4th Degree) Equations
    assert quickTest("3x^4 + 6x^3 - 123x^2 - 126x + 1080 = 0", rootFinder) == "(x-5.0)*(x+4.0)*(x-3.0)*(x+6.0)=0"
    assert quickTest("-20x^4 + 5x^3 + 17x^2 - 29x + 87 = 0", rootFinder) == "(x-1.49)*(x-(0.22+1.3*sqrt[2](-1)))*(x-(0.22-1.3*sqrt[2](-1)))*(x+1.69)=0"
    assert quickTest("2x^4 + 4x^3 + 6x^2 + 8x + 10 = 0", rootFinder) == "(x-(0.28+1.42*sqrt[2](-1)))*(x-(-1.28+0.85*sqrt[2](-1)))*(x-(-1.28-0.85*sqrt[2](-1)))*(x-(0.28-1.42*sqrt[2](-1)))=0"
示例#18
0
def test_simulSolvers():
    assert quickTest("1000x + 2y + 3z = 4; 5x + 6y + 7z = 8; 9x + 10y + 1100z = 12", simulSolver, 'x') == "x=0.0"
    assert quickTest("1000x + 2y + 3z = 4; 5x + 6y + 7z = 8; 9x + 10y + 1100z = 12", simulSolver, 'y') == "y=1.33"
    assert quickTest("1000x + 2y + 3z = 4; 5x + 6y + 7z = 8; 9x + 10y + 1100z = 12", simulSolver, 'z') == "z=-0.0"

    assert quickTest("1000x + 2y + 3z = 4; 5x + 6y + 7z = 8; 9x + 10y + 11z = 12", simulSolver, 'x') == "x=-0.0"
    assert quickTest("1000x + 2y + 3z = 4; 5x + 6y + 7z = 8; 9x + 10y + 11z = 12", simulSolver, 'y') == "y=-1.0"
    assert quickTest("1000x + 2y + 3z = 4; 5x + 6y + 7z = 8; 9x + 10y + 11z = 12", simulSolver, 'z') == "z=2.0"

    assert quickTest("1x + 2y + 3z = 4; 5x + 6y + 7z = 8; 9x + 10y + 11z = 12", simulSolver, 'x') == "NoTrivialSolution"
    assert quickTest("1x + 2y + 3z = 4; 5x + 6y + 7z = 8; 9x + 10y + 11z = 12", simulSolver, 'y') == "NoTrivialSolution"
    assert quickTest("1x + 2y + 3z = 4; 5x + 6y + 7z = 8; 9x + 10y + 11z = 12", simulSolver, 'z') == "NoTrivialSolution"

    assert quickTest("1000a + 2y + 3w = 4; 5a + 6y + 7w = 8; 9a + 10y + 1100w = 12", simulSolver, 'a') == "a=0.0"
    assert quickTest("1000a + 2y + 3w = 4; 5a + 6y + 7w = 8; 9a + 10y + 1100w = 12", simulSolver, 'y') == "y=1.33"
    assert quickTest("1000a + 2y + 3w = 4; 5a + 6y + 7w = 8; 9a + 10y + 1100w = 12", simulSolver, 'w') == "w=-0.0"

    assert quickTest("1000a + 2y + 3w = 4; 5a + 6y + 7w = 8; 10y = 12", simulSolver, 'a') == "a=0.0"
    assert quickTest("1000a + 2y + 3w = 4; 5a + 6y + 7w = 8; 10y = 12", simulSolver, 'y') == "y=1.2"
    assert quickTest("1000a + 2y + 3w = 4; 5a + 6y + 7w = 8; 10y = 12", simulSolver, 'w') == "w=0.11"

    # Tests for testing 'solve for all variable' option in case no variable is specified by user.
    assert quickTest("1000x + 2y + 3z = 4; 5x + 6y + 7z = 8; 9x + 10y + 1100z = 12", simulSolver) == "z=-0.0;y=1.33;x=0.0"
    assert quickTest("1000x + 2y + 3z = 4; 5x + 6y + 7z = 8; 9x + 10y + 11z = 12", simulSolver) == "z=2.0;y=-1.0;x=-0.0"
    assert quickTest("1000a + 2y + 3w = 4; 5a + 6y + 7w = 8; 9a + 10y + 1100w = 12", simulSolver) == "y=1.33;w=-0.0;a=0.0"
    assert quickTest("1000a + 2y + 3w = 4; 5a + 6y + 7w = 8; 10y = 12", simulSolver) == "y=1.2;w=0.11;a=0.0"