def test_cos_exercise_6(arg, exp): tol = 1e-10 assert abs(calculator.cos(arg[0], arg[1]) - exp) < tol
def test_cos_exercise_4(): x = 2 * math.pi N = 30 tol = 1e-10 assert abs(calculator.cos(x, N) - math.cos(x)) < tol
def test_cos_module(): assert 0.5253219888177297 == calculator.cos( 45), "cos_func module from cal package is not working as expected" assert -0.8509035245341184 == derivatives.d_cos( 45), "cos_func module from cal package is not working as expected"
def test_type_error(): with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.sin("60") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.cos("-45") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.tan("4.5") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.tanh("50") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.relu("1.3") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.sigmoid("2.4") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.euler("4") with pytest.raises(TypeError, match=r".*invalid type*"): calculator.softmax([10, "2", "3"]) with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.log("5", 10) with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.log(3, "10") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_sin("45") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_cos("4.5") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_tan("45") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_tanh([1, 3]) with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_euler("10") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_sigmoid("3") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_relu("-5") with pytest.raises(TypeError, match=r".*invalid type*"): derivatives.d_softmax([20, "3", 5]) with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_log("5", 20) with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_log(5, "20")
def test_cos(self): assert 0 == calculator.cos("degrees", 90)
def test_cos_exercise_6(arg, expected_output): """ Function for testing cosine approximation in calculator.py. """ assert math.isclose(expected_output, calc.cos(arg[0], arg[1]))
def test_cos_exercise_4(): tol = 1e-9 assert (cos(1, 1000) == cos_math(1)) < tol
def test_function_cos(): assert math.cos(num) == calculator.cos(num), 'cos implementation failed'
def test_cos(): assert math.cos(5) == calculator.cos(5)
def test_cos_exercise_6(x, x2): tol = 1e-9 assert abs((cos(x[0], x[1]) - cos_math(x2))) < tol
def test_cos(): assert calc.cos(45, 'degree') == math.cos(45)
def test(): abs_tol = 0.001 rel_tol = 0.001 test_value = 25 # ================= testing sin ===================== assert math.isclose( calculator.sin(test_value), -0.132, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {calculator.sin(test_value)}', f'expected : {-0.132}') assert math.isclose( derivatives.sin(test_value), 0.991, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {derivatives.sin(test_value)}', f'expected : {0.991}') # ================= testing cosine ===================== assert math.isclose( calculator.cos(test_value), 0.991, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {calculator.cos(test_value)}', f'expected : {0.991}') assert math.isclose( derivatives.cos(test_value), 0.132, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {derivatives.cos(test_value)}', f'expected : {0.132}') # ================= testing exponential ===================== assert math.isclose( calculator.exp(test_value), 72004899337, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {calculator.exp(test_value)}', f'expected : {72004899337}') assert math.isclose( derivatives.exp(test_value), 72004899337, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {derivatives.exp(test_value)}', f'expected : {72004899337}') # ================= testing log ===================== assert math.isclose( calculator.log(test_value), 3.218, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {calculator.log(test_value)}', f'expected : {3.218}') assert math.isclose( derivatives.log(test_value), 0.04, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {derivatives.log(test_value)}', f'expected : {0.04}') # ================= testing relu ===================== assert math.isclose( calculator.relu(test_value), 25, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {calculator.relu(test_value)}', f'expected : {25}') assert math.isclose( derivatives.relu(test_value), 1, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {derivatives.relu(test_value)}', f'expected : {1}') # ================= testing sigmoid ===================== assert math.isclose( calculator.sigmoid(test_value), 0.999, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {calculator.sigmoid(test_value)}', f'expected : {0.999}') assert math.isclose( derivatives.sigmoid(test_value), 1.388794386457827062508E-11, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {derivatives.sigmoid(test_value)}', f'expected : {1.388794386457827062508E-11}') # ================= testing Softmax ===================== assert math.isclose( calculator.softmax(test_value), 1, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {calculator.softmax(test_value)}', f'expected : {1}') # assert math.isclose(derivatives.softmax(test_value), 0.04 , # rel_tol=abs_tol, # abs_tol=abs_tol),(f'actual : {derivatives.softmax(test_value)}', # f'expected : {0.04}' ) # ================= testing tan ===================== assert math.isclose( calculator.tan(test_value), -0.133, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {calculator.tan(test_value)}', f'expected : {-0.133}') assert math.isclose( derivatives.tan(test_value), 2.017, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {derivatives.tan(test_value)}', f'expected : {2.017}')
def testCos(self): self.assertEqual(0.9063077870366499, cos(25)) self.assertEqual(0.8191520442889918, cos(-35)) self.assertEqual(-1.0, cos(180)) self.assertEqual(-0.6427876096865394, cos(180 - 50)) self.assertEqual(0.9999897829968295, cos(0.259))
def test_cos(): assert math.cos(3.14) == calc.cos(3.14), 'Check cos function'
def test_cos(): assert calculator.cos(4) == cos(4)
def test_cos_exercise_4(arg, expected_output): assert abs(calculator.cos(2, 1000) - cos(2)) < eps
def test_cos(arg, expected_output): tol = 1e-2 N = 10 assert calculator.cos(arg, N) <= expected_output + tol
def test_function_dcos(): assert -math.sin(calculator.cos(num)) == derivatives.dcos(calculator.cos(num)), 'dcos implementation failed'
def main(): import tkinter as tk query = takeCommand() while(query != None): if ('answer of' in query.lower() or 'calculate' in query.lower() or '/' in query.lower() or 'x' in query.lower() or '-' in query.lower() or '+' in query.lower() or 'tan' in query.lower() or 'sine' in query.lower() or 'cosine' in query.lower() or 'power' in query.lower()): speak("Working on it...") string = query #calculate 10 + 10 string = re.findall('\d+', string) if (len(string) < 2): operand1 = int(string[0]) # print(operand1) if 'sine' in query.lower(): answer = sin(operand1) speak("Answer is :"+str(answer)) InsertText("Answer is : "+ str(answer)) elif 'cosine' in query.lower(): answer = cos(operand1) speak("Answer is :"+str(answer)) InsertText("Answer is : "+ str(answer)) elif 'tan' in query.lower(): answer = tan(operand1) speak("Answer is :"+str(answer)) InsertText("Answer is : "+ str(answer)) else: operand1 = int(string[0]) operand2 = int(string[1]) # print("string: "+str(string)) # print("operand1:"+str(operand1)) # print("operand2:"+str(operand2)) if ('+') in query.lower(): answer = Sum(operand1,operand2) speak("Answer is :"+str(answer)) InsertText("Answer is : "+ str(answer)) elif ('x') in query.lower(): answer = multiply(operand1,operand2) speak("Answer is :"+str(answer)) output.delete('1.0',END) InsertText("Answer is : "+ str(answer)) elif ('/') in query.lower(): answer = divide(operand1,operand2) speak("Answer is :"+str(answer)) InsertText("Answer is : "+ str(answer)) elif ('-') in query.lower(): answer = subtract(operand1,operand2) if int(answer) <0: speak("Answer is negtive:"+str(answer)) else: speak("Answer is : "+str(answer)) InsertText("Answer is : "+ str(answer)) elif ('power') in query.lower(): answer = power(operand1,operand2) speak("Answer is :"+str(answer)) InsertText("Answer is : "+ str(answer)) else: speak("This is so hard for me, Im sorry") InsertText("This is so hard for me, Im sorry") break if ('wikipedia') in query.lower(): speak('searching on wikipedia...') query = query.replace("wikipedia","") results = wikipedia.summary(query, sentences=2) # print(results) if results == False: speak("I didnt find any information") InsertText("I didnt find any information") else: print(results) InsertText(results) speak(results) break if ('search on google for' in query.lower() or 'google for' in query.lower() or 'search for' in query.lower()): text = query text = text.replace('google','') text = text.replace('search on' or 'search for' or 'search about','') speak("Searching on google..") # InsertText("Searching on google..") links = googleSearch(text) speak('I found this links may it could help you...') # print(links) InsertText(links) break if (('translate' in query.lower()) or ('french' in query.lower()) or ('spanish' in query.lower()) or ('german' in query.lower()) or ('italian' in query.lower()) ): if ('french') in query.lower(): ret = toFrench(query) print(ret) speakforeigner(ret) InsertText(ret) voice = engine.getProperty('voices')[1] engine.setProperty('voice', voice.id) elif ('german') in query.lower(): ret = toGerman(query) print(ret) speakforeigner(ret) InsertText(ret) voice = engine.getProperty('voices')[1] engine.setProperty('voice', voice.id) elif ('spanish') in query.lower(): ret = toSpanish(query) print(ret) speakforeigner(ret) InsertText(ret) voice = engine.getProperty('voices')[1] engine.setProperty('voice', voice.id) elif ('italian') in query.lower(): ret = toItalian(query) print(ret) speakforeigner(ret) InsertText(ret) voice = engine.getProperty('voices')[1] engine.setProperty('voice', voice.id) elif ('portuguese') in query.lower(): ret = toPortuguese(query) print(ret) speakforeigner(ret) InsertText(ret) voice = engine.getProperty('voices')[1] engine.setProperty('voice', voice.id) else: speakforeigner("Im sorry I dont understand this language") InsertText("Im sorry I dont understand this language") break if ('open youtube') in query.lower(): url = "youtube.com" chrome_path="C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s" speak("hold on") webbrowser.get(chrome_path).open(url) break if ('open google' in query.lower() or 'google' in query.lower()) : url = "google.com" speak("Im wondering what are you looking for") chrome_path="C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s" webbrowser.get(chrome_path).open(url) break if 'open facebook' in query.lower(): url = "facebook.com" chrome_path="C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s" speak("Im on it") webbrowser.get(chrome_path).open(url) break if 'open linkedin' in query.lower(): url = "linkedin.com" chrome_path="C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s" speak("lets get professional") webbrowser.get(chrome_path).open(url) break if 'open stackover flow' in query.lower(): url = "stackoverflow.com" chrome_path="C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s" speak("hold on") webbrowser.get(chrome_path).open(url) break if 'open soundcloud' in query.lower(): url = "soundcloud.com" chrome_path="C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s" speak("Im on it") webbrowser.get(chrome_path).open(url) break if ('play music' or 'play my list' or 'open my playlist' or 'open my favorite songs')in query.lower(): songs_dir = 'E:\\desktop\\FUN\\Myplaylist' songs = os.listdir(songs_dir) speak("playlist shuffle..") InsertText('playlist shuffle..') print(songs) os.startfile(os.path.join(songs_dir, songs[0])) break if ('the time now' in query.lower() or 'time' in query.lower() or 'what time is it' in query.lower() or 'how much oclock' in query.lower()): time = timevalue speak("The time is") speak(time) InsertText(time) break if ('what is the date' in query.lower() or 'What date is it' in query.lower() or 'What day is it' in query.lower() or "today's date" in query.lower()): date = datevalue speak("Today is ") speak(date) InsertText(date) break if ('what is the temperature now' or 'What is the weather today' or 'is it hot today' or "is it cold today") in query.lower(): temp = tempvalue speak("Today's temperture is ") speak(temp) InsertText(temp) break if ('open my code' or 'open code' or 'your code') in query.lower(): code_dir = 'C:\\Users\\Abdullah\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe' os.startfile(os.path.join(code_dir)) break if ('f*** you' or 'm**********r' or 'you are disgusting' or 'ugly' or 'bitch' or 'you are stupid' or "you're stupid") in query.lower(): speak('You are so rude, I will not respond to that') InsertText('You are so rude, I will not respond to that') break if ('love you' in query.lower() or 'would you marry me' in query.lower()): speak('oh, you are so sweet') InsertText('oh, you are so sweet') break if 'email to tina' in query.lower(): try: speak("what should I send") content = takeCommand() to ='*****@*****.**' sendEmail(to,content) speak("Email has been sent successfully") break except Exception as e: print(e) speak("There is a problem in email security, please check it and try again") break if ('draw' in query.lower() or 'drew' in query.lower()): speak("Lets draw, to save you drawing just press control S") InsertText('press " CTRL+S" to save your draw..') drawStart() break if ('game' in query.lower()): speak("lets play a game") InsertText("Have fun..") startGame() break else: speak("Im not sure I understand") speak("Say it again") InsertText("Im not sure I understand\nSay it again") query= takeCommand()