Example #1
0
def test_sin_N():
    with pytest.raises(Exception) as f:
        assert calculator.sin(mt.pi / 2, 0.5)
    assert str(f.value) == 'N can only be positive integer'
Example #2
0
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}')
Example #3
0
def test_sin_neg(x):
    with pytest.raises(Exception) as e:
        assert calculator.sin(x[0], x[1])
    assert str(e.value) == 'Sin of negative not defined'
Example #4
0
def test_sin():
    x = 3
    N = 10
    assert abs(sin(x, N) -
               math.sin(x)) < 1E-9, 'Computed sine is not equal to maths sine'
Example #5
0
def test_sin_parametrize(x, expected):
    assert abs(sin(x[0], x[1]) - expected) < 1E-20
Example #6
0
def test_sin(x):
    tol = 1e-10
    assert abs(m.sin(x) - sin(x, 20)) < tol
Example #7
0
def test_sin():
    tol = 1e-10
    assert abs(m.sin(0) - sin(0, 20)) < tol
Example #8
0
def test_sin_exercise_4(arg):
    assert abs(calculator.sin(arg[0], arg[1]) - sin(arg[0])) < 1e-6
 def test_sin(self):
     assert 1 == calculator.sin("degrees", 90)
Example #10
0
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()
Example #11
0
def test_sin_exercise_4(arg, expected_output):
    assert (calculator.sin(arg[0], arg[1]) - expected_output) < 1e-12
def test_sin(arg, expected_output):
    assert math.isclose(calculator.sin(arg[0], arg[1]), expected_output)