Example #1
0
def test_sqrt_cases(n, expected, error):
    if error:
        with pytest.raises(ValueError):
            sqrt(n)
        return

    value = sqrt(n)
    assert expected == round(value, 4), f'sqrt({n})'
Example #2
0
def test_sqrt():
    tolerance = 0.1

    test_numbers = [
        0,
        1,
        4,
        9,
        16,
        25,
        36,
        49,
        64,
        81,
        100,
        # ok, now for the difficult ones
        2,
        5,
    ]
    for n in test_numbers:
        got = s.sqrt(n)
        expected = math.sqrt(n)
        if got == expected:
            # exact match. probably a square number.
            continue

        # check with tolerance
        lbound = expected * (1.0 - tolerance)
        ubound = expected * (1.0 + tolerance)
        assert lbound < got and got < ubound, \
            f"Calculating sqrt({n}), failed: {lbound} < {got} < {ubound}"
Example #3
0
def test_sqrt_zero_precision_return_0():
    assert_equal(0, sqrt(3, 0))
Example #4
0
def test_sqrt_negative_number_return_0():
    assert_equal(0, sqrt(-1, 0.21))
Example #5
0
def test_sqrt():
    assert_equal(3, sqrt(10, 1))
Example #6
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()
Example #7
0
import add
import sub
import mul
import div
import exp
import sqrt

a = int(input("a-> "))
b = int(input("b-> "))
print("a+b")
print(add.add(a, b))
print("a-b")
print(sub.sub(a, b))
print("a*b")
print(mul.mul(a, b))
print("a/b")
print(div.div(a, b))
print("a^(b)")
print(exp.exp(a, b))
print("sqrt(a)")
print(sqrt.sqrt(a))
Example #8
0
def test_sqrt():
    n = 2
    expected = 1.4142
    value = sqrt(n)
    assert expected == round(value, 4), f'sqrt({n})'
Example #9
0
def test_neg():
    with pytest.raises(ValueError):
        sqrt(-2)
Example #10
0
from sqrt import sqrt

while True:
    num = float(input("num: "))
    intervalo = 0
    with open("log", "w") as f:
        ultimo = 0
        i = 0

        while i <= num:
            res = sqrt(i)
            f.write('(%.1f, %f)\n' %
                    (i, i - res.real**2))  #((i**(1/2))-res.real)))
            i += 1
Example #11
0
 def test_sqrt_of_nine(self):
     self.assertEquals(3, round(sqrt.sqrt(9)))
Example #12
0
 def test_sqrt_of_four(self):
     self.assertEquals(2, round(sqrt.sqrt(4)))
Example #13
0
 def test_sqrt_of_sixteen(self):
     self.assertEquals(4, round(sqrt.sqrt(16)))
Example #14
0
def test_sqrt():
    assert sqrt.sqrt(256) == 16
def testRange():
    assert all(withinTolerance(sqrt(x), builtinSqrt(x)) for x in xrange(100000))
Example #16
0
 def test_sq_root(self):
     self.assertEqual(sqrt(0.4), 0.632)
     self.assertEqual(sqrt(100), 10.0)
     self.assertEqual(sqrt(12), 3.464)