def test_torture_quadratic():
    '''
    Do torture testing
    '''
    args = [10, 0, 1, 18, -5, -1, 0.5, -1.5]
    for a, b, c in itertools.permutations(args, 3):
        if a == 0:
            with py.test.raises(ZeroDivisionError):
                quadratic(a=a, b=b, c=c)
        else:
            x1, x2 = quadratic(a=a, b=b, c=c)
            assert cmath.isclose(a * x2**2 + b * x2 + c, 0.0, abs_tol=0.0001)
def test_quadratic():
    '''
    Do basic testing
    '''
    x1, x2 = quadratic(a=8, b=22, c=15)
    assert 8 * x1**2 + 22 * x1 + 15 == 0
    assert 8 * x2**2 + 22 * x2 + 15 == 0
def test_hypothesis_01(a, b, c):
    assume(abs(a) > 0.001)
    assume(abs(b) > 0.001)
    assume(abs(c) > 0.001)
    x1, x2 = quadratic(a, b, c)
    assert math.isclose(a * x1**2 + b * x1 + c, 0.0, abs_tol=0.001)
    assert math.isclose(a * x2**2 + b * x2 + c, 0.0, abs_tol=0.001)
def test_quadratic_hypothesis(a, b, c):
    assume(abs(a) > 0.001)
    assume(abs(b) > 0.001)
    assume(abs(c) > 0.001)
    x1, x2 = quadratic(a, b, c)
    # assert a*x1**2 + b*x1 + c == 0.0 -> tests fail when using a=0.0100000000002 etc
    # assert a*x2**2 + b*x2 + c == 0.0 -> better use math.isclose which takes rounding into account
    assert cmath.isclose(a * x1**2 + b * x1 + c, 0.0, abs_tol=0.0001)
    assert cmath.isclose(a * x2**2 + b * x2 + c, 0.0, abs_tol=0.0001)
Esempio n. 5
0
def calculate():
    Label(window, text=" " * 100).grid(row=4)
    global answer
    aval = a.get()
    bval = b.get()
    cval = c.get()
    if aval and bval and cval:
        answers = quadratic(float(aval), float(bval), float(cval))
        answer = Label(window,
                       text="Answer: " + str(answers[0]) + ", " +
                       str(answers[1])).grid(row=4)
        text = Label(window, text=answers[2]).grid(row=5)
Esempio n. 6
0
def main() -> None:
    message: str = "Hello"
    print(message)

    # Solve an arbitrary quadratic equation
    a: float = 11
    b: float = 18
    c: float = 7
    x_1: float
    x_2: float
    x_1, x_2 = quadratic(a=a, b=b, c=c)
    print("Solving for x in the quadratic equation ax^2 + bx + c = 0 where")
    print("a = {0}\nb = {1}\nc = {2}".format(a, b, c))
    print("The two roots (x) are: {root_1:5.5} and {root_2:5.5}".format(
        root_1=x_1, root_2=x_2))
Esempio n. 7
0
def test_basic():
    assert quadratic(0, 1) == (1, -1, 0)
    assert quadratic(4, 9) == (1, -13, 36)
    assert quadratic(2, 6) == (1, -8, 12)
    assert quadratic(-5, -4) == (1, 9, 20)
Esempio n. 8
0
def test_quadratic():
    x1, x2 = quadratic(a=8, b=22, c=15)
    assert 8 * x1**2 + 22 * x1 + 15 == 0
    assert 8 * x2**2 + 22 * x2 + 15 == 0
Esempio n. 9
0
def test_torture_test():
    args = [10, 0, 1, 18, -5, -1, 0.5, -1.5]
    for t in itertools.permutations(args, 3):
        x1, x2 = quadratic(*t)
Esempio n. 10
0
import quadratic
"""
6 15 [2, 3] [3, 5]
35 85 [5, 7] [5, 17]
204 493 [2, 2, 3, 17] [17, 29]
1189 2871 [29, 41] [3, 3, 11, 29]
6930 16731 [2, 3, 3, 5, 7, 11] [3, 3, 11, 13, 13]
40391 97513 [13, 13, 239] [13, 13, 577]
235416 568345 [2, 2, 2, 3, 17, 577] [5, 197, 577]
1372105 3312555 [5, 7, 197, 199] [3, 5, 19, 59, 197]
7997214 19306983 [2, 3, 19, 29, 41, 59] [3, 19, 59, 5741]
"""

p = [1, 6, 35, 204]

while 1:
    r = (6 * p[-1]) - p[-2]
    c = -(r * (r - 1))
    b = -(1 + 2 * r)
    a = 1
    t = quadratic.quadratic(a, b, c)
    best_root = t[0]
    if int(best_root) == best_root:
        best_root = int(best_root)
        print r, best_root
        p.append(r)
    if (r + best_root) > 1000 * 1000 * 1000 * 1000:
        print r, best_root, r + best_root
        break
Esempio n. 11
0
def menu():
    print("1-Addition \t\t 2-Subtration \t\t 3-Multiply \t\t 4-Division")
    print("5-Sin() \t\t 6-Cos() \t\t 7-Tan() \t\t 8-Sec()")
    print("9-Cosec() \t\t 10-Cot() \t\t 11-Square \t\t 12-Square Root \t\t")
    print("13-Power \t\t 14-Root \t\t 15-Expontial(e^x)")
    print("16-Factorial \t\t 17-log()\t\t 18-ln() \t\t 19-Quadratic Eq Solver")
    print(
        "20-Inverse(x^-1) \t 21-Sin inverse \t 22-Cos Inverse \t 23.Tan Inverse"
    )
    print("24-Permutation \t\t 25-Combination \t 26-Percentage")
    print("27-Multiple Basic Operators At a time \t\t 28-Close")

    while True:
        try:
            choice = int(input("Enter your choice(press number):"))
            break
        except ValueError:
            print("Input must be a number!")
    if choice == 1:
        while True:
            Sum.Sum()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 2:
        while True:
            Sub.sub()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 3:
        while True:
            Mul.multiply()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 4:
        while True:
            divide.divide()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 5:
        while True:
            sin.sin()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 6:
        while True:
            cos.cos()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 7:
        while True:
            tan.tan()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 8:
        while True:
            sec.sec()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 9:
        while True:
            cosec.cosec()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 10:
        while True:
            cot.cot()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 11:
        while True:
            square.square()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 12:
        while True:
            sqrt.sqrt()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 13:
        while True:
            power.power()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 14:
        while True:
            root.root()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 15:
        while True:
            exponential.exponential()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 16:
        while True:
            factorial.factorial()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 17:
        while True:
            log.log()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 18:
        while True:
            ln.ln()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 19:
        while True:
            quadratic.quadratic()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 20:
        while True:
            inverse.inv()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 21:
        while True:
            asin.asin()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 22:
        while True:
            acos.acos()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 23:
        while True:
            atan.atan()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 24:
        while True:
            per.per()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 25:
        while True:
            com.com()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 26:
        while True:
            percentage.percentage()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 27:
        while True:
            combine()
            x = int(input("press 1 to try again,press 2 to return to menu"))
            if x == 1:
                continue
            if x == 2:
                menu()
                break
    elif choice == 28:
        close()
    else:
        print("Invalid Input.Try Again")
        menu()
Esempio n. 12
0
def example_3():
    expected = (0.0, )
    actual = quadratic(1, 0, 0)
    assert actual == expected, "Test 3 (example): failed!"
Esempio n. 13
0
def test_complex():
    assert_equal(quadratic(1, 0, 1), [],
                 err_msg="Roots of x^2 + 1 = 0 should be [], empty list")
Esempio n. 14
0
def test_inconsistent():
    assert_equal(
        quadratic(0, 0, 1), [],
        err_msg="Roots of 0 x^2 + 0 x + 1 = 0 should be [], empty list")
Esempio n. 15
0
import quadratic

"""
6 15 [2, 3] [3, 5]
35 85 [5, 7] [5, 17]
204 493 [2, 2, 3, 17] [17, 29]
1189 2871 [29, 41] [3, 3, 11, 29]
6930 16731 [2, 3, 3, 5, 7, 11] [3, 3, 11, 13, 13]
40391 97513 [13, 13, 239] [13, 13, 577]
235416 568345 [2, 2, 2, 3, 17, 577] [5, 197, 577]
1372105 3312555 [5, 7, 197, 199] [3, 5, 19, 59, 197]
7997214 19306983 [2, 3, 19, 29, 41, 59] [3, 19, 59, 5741]
"""

p = [1, 6, 35, 204]

while 1 :
	r = (6 * p[-1]) - p[-2]
	c = -(r * (r - 1))
	b = -(1 + 2*r)
	a = 1
	t = quadratic.quadratic(a,b,c)
	best_root = t[0]
	if int(best_root) == best_root :
		best_root = int(best_root)
		print r, best_root
		p.append(r)
	if (r + best_root) > 1000*1000*1000*1000 :
		print r, best_root, r + best_root
		break
Esempio n. 16
0
def test_quadratic_types():
    '''
    Do typing testing
    '''
    with py.test.raises(TypeError):
        quadratic(a=8, b='hello', c=15)
Esempio n. 17
0
def test_torture():
    args = [10, 0, -5, 1, -1, 18, 99]
    for t in permutations(args, 3):
        x1, x2 = quadratic(*t)
Esempio n. 18
0
def test_quadratic_types():
    x1, x2 = quadratic(a='eight', b=22, c=15)
Esempio n. 19
0
def test_repeated_real_trivial():
    assert_allclose(quadratic(1, 0, 0), [0, 0],
                    err_msg="Roots of x^2 = 0 should be [0, 0]")
Esempio n. 20
0
def test_repeated_real_nontrivial():
    assert_allclose(quadratic(4, -4, 1), [0.5, 0.5],
                    err_msg="Roots of (2 x - 1)^2 = 0 should be [1/2, 1/2]")
Esempio n. 21
0
from abs_se import self_abs
# print(hex(int('34')))

print(self_abs(-9))
# print(self_abs('d'))
print(type('23'))

# 返回多个值
from game import move
import math
print(move(4, 5, 2, 30))

r = move(100, 100, 60, math.pi / 6)
print(r)

from quadratic import quadratic

print(quadratic(1, -2, 1))
# 测试:
print('quadratic(2, 3, 1) =', quadratic(2, 3, 1))
print('quadratic(1, 3, -4) =', quadratic(1, 3, -4))

if quadratic(2, 3, 1) != (-0.5, -1.0):
    print('测试失败')
elif quadratic(1, 3, -4) != (1.0, -4.0):
    print('测试失败')
else:
    print('测试成功')
Esempio n. 22
0
def test_linear():
    assert_allclose(quadratic(0, 1, -1), [1],
                    err_msg="Roots of 0 x^2 + x - 1 = 0 should be [1]")
Esempio n. 23
0
def test_quad(a, b, c):
    assume(abs(a) >= 0.0001)
    x1, x2 = quadratic(a, b, c)
    assert cmath.isclose(a * x1**2 + b * x1 + c, 0.0, abs_tol=0.0001)
    assert cmath.isclose(a * x1**2 + b * x1 + c, 0.0, abs_tol=0.0001)
Esempio n. 24
0
def test_distinct_real():
    assert_allclose(quadratic(1, 0, -1), [1, -1],
                    err_msg="Roots of x^2 - 1 = 0 should be [1, -1]")
Esempio n. 25
0
def example_2():
    expected = (-1.0,)
    actual = quadratic(1, 2, 1)
    assert actual == expected, "Test 2 (example): failed!"
Esempio n. 26
0
import math
from quadratic import quadratic

print('quadratic(2,3,1) = ', quadratic(2, 3, 1))
print('quadratic(1,3,-4) = ', quadratic(1, 3, -4))
Esempio n. 27
0
def example_3():
    expected = (11111111111111111111111111111111111111111)
    actual = quadratic(1, 1, 1)
    assert actual == expected, "Test 3 (example): failed!"
Esempio n. 28
0
def example_1():
    expected = (2.5, 1.0)
    actual = quadratic(2, -7, 5)
    assert actual == expected, "Test 1 (example): failed!"
Esempio n. 29
0
def test_quadratic_types():
    with pytest.raises(TypeError):
        quadratic(a=8, b='hello', c=15)
    with pytest.raises(TypeError):
        quadratic(a=8, b=22, c=15, d=4)
Esempio n. 30
0
from quadratic import quadratic

a = float(
    input(
        'Please input the parameters for the equation: a*x^2 + b*x + c = 0. \n'
        + 'a = '))
b = float(input('b = '))
c = float(input('c = '))

quadratic(a, b, c)
Esempio n. 31
0


print('--------import my_abs--------')
from my_abs import my_abs
print('1 of abs is',my_abs(1))
print('-1 of abs is',my_abs(-1))
print('0 of abs is',my_abs(0))
# print('\'a\' of abs is',my_abs('a'))


print('--------return multi value--------')
import math
def move(x, y, step, angle=0):
    nx = x +step* math.cos(angle)
    ny = y +step* math.cos(angle)
    return nx, ny


x, y = move(100,100,60,math.pi/6)
print(x, y)
r = move(100,100,60,math.pi/6)
print(r)
print('returning multi value is just return a tuple')



print('--------exercise--------')
from quadratic import quadratic
print(quadratic(1,3,-4))
print(quadratic(1,5,-150))