def test_functions(): value = random.randint(-100, 100) value2 = random.randint(1, 100) assert round(c.sin(value)) == round(math.sin( value)), "Sin function is not working, you studied this in 10.." assert round(c.cos(value)) == round(math.cos( value)), "Cos function is not working, you studied this in 10.." assert round(c.tan(value)) == round(math.tan( value)), "Tan function is not working, you studied this in 10.." assert round(c.tanh(value)) == round(math.tanh( value)), "Tanh function is not working, you studied this in 10.." assert round(c.sigmoid(value)) == round( (1 / (1 + math.exp(-value)) )), "Sigmoid function is not working, this is the basic of DNN.." assert round(c.relu(value)) == round(max( 0, value)), "Relu function is not working, this is the basic of DNN,," assert round(c.log(value2)) == round(math.log( value2)), "Log function is not working, you studied this in 10.." assert round(c.e(value)) == round(math.exp( value)), "Exp function is not working, you studied this in 10.." assert [ 0.0003282279149649954, 0.0024252944769113903, 0.01792063694632493, 0.0008922159768423478, 0.9784336246849563 ] == c.softmax([1, 3, 5, 2, 9]), "Softmax not working bro.. how will you make NN then"
def test_tan(): """ Test the method tan in the calculator package :return: None """ output = calculator.tan(0) assert output == 0 output = derivatives.derivative_tan(0) assert output == 1
def test_all_function_check(): import calculator assert calculator.sin(math.pi / 2) == 1 assert calculator.cos(math.pi) == -1 assert calculator.tan(0) == 0 assert calculator.tanh(0) == 0 assert calculator.softmax([1, 2]) == [0.2689414213699951, 0.7310585786300049] assert calculator.e(0) == 1 assert calculator.log(10, base=10) == 1 assert calculator.relu(10) == 10 assert calculator.relu(-10) == 0 assert calculator.sigmoid(0) == 0.5
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 test_tan_import(): tan_output = calculator.tan(22 / 28) assert round( tan_output) == 1, "tan function in calculor has wrong implementation"
def test_function_dtan(): assert (1/(math.cos(calculator.tan(num))**2)) == derivatives.dtan(calculator.tan(num)), 'dTan implementaion failed'
def test_functions_tan(): assert math.tan(num) == calculator.tan(num), 'Tan implementaion failed'
def test_tan(): assert math.tan(3.14) == calc.tan(3.14), 'Check tan function'
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_tan_module(): assert 1.6197751905438615 == calculator.tan( 45), "tan_func module from cal package is not working as expected" assert 3.623671667901403 == derivatives.d_tan( 45), "tan_func module from cal package is not working as expected"
def test_tan(): assert calculator.tan(4) == tan(4)
def test_tan(): assert math.tan(10) == calculator.tan(10)
def test_tan(): assert calc.tan(45, 'degree') == math.tan(45)
def testTan(self): self.assertEqual(0.4663076581549986, tan(25)) self.assertEqual(-0.7002075382097097, tan(-35)) self.assertEqual(-1.2246467991473532e-16, tan(180)) self.assertEqual(-1.19175359259421, tan(180 - 50)) self.assertEqual(0.004520433552948983, tan(0.259))
def test_tan(self): assert 1 == calculator.tan("degrees", 45)
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()