def test_lexical_errors(): with pytest.raises(evaluator.LexicalError): answer = evaluator.calc("!1+1") with pytest.raises(evaluator.LexicalError): answer = evaluator.calc("1+!1") with pytest.raises(evaluator.LexicalError): answer = evaluator.calc("1+1!")
def Jarvis(data): data = str.lower(data) if "how are you" in data: go(Fore.BLUE + "I am fine, How about you" + Fore.RESET) if "what time is it" in data: go(Fore.BLUE + ctime() + Fore.RESET) if "open camera" in data: go("Opening Cheese ...... ") os.system("cheese") if "where am i" in data: mapps.locateme() if "weather" in data: mapps.weatherr() if "near me" in data: mapps.nearme(data) if "movies" in data: try: movie_name = raw_input(Fore.RED + "What do you want to watch?\n" + Fore.RESET) except: movie_name = input(Fore.RED + "What do you want to watch?\n" + Fore.RESET) os.system("ims " + movie_name) if "music" in data: os.system("instantmusic") if "increase volume" in data: os.system("pactl -- set-sink-volume 0 +3%") if "decrease volume" in data: os.system("pactl -- set-sink-volume 0 -10%") if "hotspot start" in data: os.system("sudo ap-hotspot start") if "hotspot stop" in data: os.system("sudo ap-hotspot stop") if "search for a string in file" in data: try: file_name = raw_input(Fore.RED + "Enter file name?:\n" + Fore.RESET) stringg = raw_input(Fore.GREEN + "Enter string:\n" + Fore.RESET) except: file_name = input(Fore.RED + "Enter file name?:\n" + Fore.RESET) stringg = input(Fore.GREEN + "Enter string:\n" + Fore.RESET) os.system("grep '" + stringg + "' " + file_name) if "check ram" in data: os.system("free -lm") if "todo" in data: todo.todoHandler(data) if "news" in data: newws.show_news() if "show me pics of" in data: picshow.showpics(data) if "evaluate" in data: tempt = data.split(" ", 1) or "" if len(tempt) > 1: evaluator.calc(tempt[1]) else: print(Fore.RED + "Error : Not in correct format" + Fore.RESET) if "show me directions from" in data: mapps.directions(data)
def test_recursive_descent_binary_plus(expr_bin_plus, truth_bin_plus): answer = evaluator.calc(expr_bin_plus, evaluator_class=evaluator.RecursiveDescentEvaluator) assert answer == truth_bin_plus
def test_recursive_descent_random_all_ops(expr_rand, truth_rand): answer = evaluator.calc(expr_rand, evaluator_class=evaluator.RecursiveDescentEvaluator) assert abs(answer - truth_rand) < 0.0000001
def test_recursive_descent_random_div(expr_rand_div, truth_rand_div): answer = evaluator.calc(expr_rand_div, evaluator_class=evaluator.RecursiveDescentEvaluator) assert abs(answer - truth_rand_div) < 0.0000001
def test_recursive_descent_binary_all_ops(expr_bin, truth_bin): answer = evaluator.calc(expr_bin, evaluator_class=evaluator.RecursiveDescentEvaluator) assert abs(answer - truth_bin) < 0.0000001
def test_recursive_descent_binary_mult(expr_bin_mult, truth_bin_mult): answer = evaluator.calc(expr_bin_mult, evaluator_class=evaluator.RecursiveDescentEvaluator) assert (abs(answer - truth_bin_mult) / truth_bin_mult) < 0.000000000001
def test_div_by_zero(): with pytest.raises(ZeroDivisionError): answer = evaluator.calc("1 / 0")
def test_syntax_errors(): with pytest.raises(SyntaxError): answer = evaluator.calc("1++1") with pytest.raises(SyntaxError): answer = evaluator.calc("+1")
def test_whitespace(): assert evaluator.calc(" 1 + 1 ") == 2
def Jarvis(data): data = str.lower(data) if "how are you" in data: go(Fore.BLUE + "I am fine, How about you" + Fore.RESET) if "what time is it" in data: go(Fore.BLUE + ctime() + Fore.RESET) if "open camera" in data: go("Opening Cheese ...... ") os.system("cheese") if "where am i" in data: mapps.locateme() if "weather" in data: if " in " in data: wordList = data.split() city = " ".join(wordList[wordIndex(data, "in") + 1:]) mapps.weather(city) else: mapps.weather() if "near" in data: wordList = data.split() things = " ".join(wordList[0:wordIndex(data, "near")]) if " me" in data: city = 0 else: wordList = data.split() city = " ".join(wordList[wordIndex(data, "near") + 1:]) print city mapps.searchNear(things, city) if "directions" in data and " to " in data: wordList = data.split() to_index = wordIndex(data, "to") if " from " in data: from_index = wordIndex(data, "from") if from_index > to_index: toCity = " ".join(wordList[to_index + 1:from_index]) fromCity = " ".join(wordList[from_index + 1:]) else: fromCity = " ".join(wordList[from_index + 1:to_index]) toCity = " ".join(wordList[to_index + 1:]) else: toCity = " ".join(wordList[to_index + 1:]) fromCity = 0 mapps.directions(toCity, fromCity) if "movies" in data: try: movie_name = raw_input(Fore.RED + "What do you want to watch?\n" + Fore.RESET) except: movie_name = input(Fore.RED + "What do you want to watch?\n" + Fore.RESET) os.system("ims " + movie_name) if "music" in data: music.play(data) if "increase volume" in data: os.system("pactl -- set-sink-volume 0 +3%") if "decrease volume" in data: os.system("pactl -- set-sink-volume 0 -10%") if "hotspot start" in data: os.system("sudo ap-hotspot start") if "hotspot stop" in data: os.system("sudo ap-hotspot stop") if "search for a string in file" in data: try: file_name = raw_input(Fore.RED + "Enter file name?:\n" + Fore.RESET) stringg = raw_input(Fore.GREEN + "Enter string:\n" + Fore.RESET) except: file_name = input(Fore.RED + "Enter file name?:\n" + Fore.RESET) stringg = input(Fore.GREEN + "Enter string:\n" + Fore.RESET) os.system("grep '" + stringg + "' " + file_name) if "check ram" in data: os.system("free -lm") if "todo" in data: todo.todoHandler(data) if "news" in data: newws.show_news() if "show me pics of" in data: picshow.showpics(data) if "evaluate" in data: tempt = data.split(" ", 1) or "" if len(tempt) > 1: evaluator.calc(tempt[1]) else: print(Fore.RED + "Error : Not in correct format" + Fore.RESET) if "quit" in data or "exit" in data or "goodbye" in data: print(Fore.RED + "Goodbye, see you later!" + Fore.RESET) exit()