def test(text, rule_string): print("-" * 80) print(Fore.GREEN + "Rule tested:" + Style.RESET_ALL, rule_string) print(Fore.GREEN + "Input string:" + Style.RESET_ALL, text) stdout.write(Fore.CYAN + "Result: " + Style.RESET_ALL) calc.main(text, pretty_mode=True) print("-" * 80 + "\n")
def test_not_number(self): user_input = ['5', 'a', '-'] with redirect_stdout(self.response): with patch('builtins.input', side_effect=user_input): calculator.main() self.assertFalse(self.response.getvalue() == '')
def test_sub(self): user_input = ['5', '4', '-'] with redirect_stdout(self.response): with patch('builtins.input', side_effect=user_input): calculator.main() self.assertTrue('1' in self.response.getvalue())
def main(): print(""" ꧁༒☬𝓢𝓽𝓾𝓭𝓮𝓷𝓽'𝓼 𝓗𝓮𝓵𝓹𝓮𝓻☬༒꧂ 1. Calculator 2. Dna to mRNA converter 3. Exit """) menu = input("Option:") if menu == "1": # go to calculator main_func = True calculator.main() elif menu == "2": main_func = True converter.main() elif menu == "3": exit() else: print("Invalid input. Please try again.")
def test_calculator(): assert calculator.main( ['', "examples/cart-4560.json", "examples/base-prices.json"]) == 4560 assert calculator.main( ['', "examples/cart-9363.json", "examples/base-prices.json"]) == 9363 assert calculator.main( ['', "examples/cart-9500.json", "examples/base-prices.json"]) == 9500 assert calculator.main( ['', "examples/cart-11356.json", "examples/base-prices.json"]) == 11356
def test_invalid_operation(self): user_input = ['5', '4', 'v'] with redirect_stdout(self.response): with patch('builtins.input', side_effect=user_input): calculator.main() value = self.response.getvalue() self.assertFalse('1' in value) self.assertFalse('9' in value) self.assertFalse('20' in value)
def main(): a = '' while a not in ('run', 'test'): print("Choose an option:\n\tRun\n\tTest") a = input("Your choice: ") a = a.lower() if a == "run": print("\n--Running Program--\n") student.main() elif a == "test": print("\n--Testing Program--\n") pytest.main(['-v'])
def analyze(data): query = nlp.process(data) response = {} if(query['type'] == "wiki"): response = encyclopedia(query['subject']) if(query['type'] == "calc"): response = calculator.main(query['subject']) if(query['type'] == "error"): response = query return response
def select(selection): #route to calculator if selection == '1': calculator.main() print() main() #route to compound interest calculator elif selection == '2': compoundInterestCalculator.main() print() main() #route to rock paper scissors game elif selection == '3': rockpaperscissors.main() print() main() #route to countoff game elif selection == '4': countoff.main() print() main() #route to tictactoe game elif selection == '5': tictactoe.main() print() main() #exit program elif selection == '6': print("Goodbye!") return #catch all invalid entries and restart main else: print("Invalid Entry!") print() main()
async def accept(websocket, path): while True: # 클라이언트로부터 메시지를 대기한다. data = await websocket.recv() print("receive : " + data) # 함수 위치 data = main(data) print(data) # await websocket.send("echo : " + data) await websocket.send(data)
def main(): run = True while (run): print("1.CALCULATOR") print("2.REVERSE A NUMBER") print("3.PRIME OR NOT") print("4.MONTH NAME") print("5.SORTED OR NOT") print("6.EXIT") print("ENTER CHOICE: ") try: choice = int(input()) if (choice == 1): calculator.main() elif (choice == 2): reverse.main() elif (choice == 3): isPrime.main() elif (choice == 4): month.main() elif (choice == 5): Sorted.main() elif (choice == 6): run = False else: print("INVALID INPUT!") except ValueError: print("INVALID CHOICE! ENTER A NUMBER\n")
def loopCalc(win,screen,numList,keyList,screenText): num = [] i = 1 while True: mouse = click(win,keyList) createNumber(win,num,numList,keyList,mouse,screenText) isplayScreen = display(win,i, num, numList,screenText) # Calls to calculate.py to compute solution if mouse == "=": solution = calculator.main(numList) screenText.setText(solution) # QUIT BUTTON if mouse == "Quit": win.close() pass
def test_multiplication(self): self.assertEqual(main("250*14.3"), 3575)
def test__8(self): #invalid character case with self.assertRaisesRegex(Exception, 'Invalid syntax'): calculator.main('3+')
def test__6(self): #invalid character case with self.assertRaisesRegex(Exception, 'Invalid character found: :'): calculator.main('4+5:1')
def test__4(self): #dividing by 0 case with self.assertRaisesRegex(Exception, 'Can not be divided by 0'): calculator.main('5+4/0')
def test__2(self): #one number case expected = 0 actual = calculator.main('0') self.assertEqual(expected, actual)
def test_multiply(self): sys.argv = "scriptname 10 x 2".split() result = calculator.main() self.assertEqual(result, 20)
def test_parentheses(self): arg = '5*(2+1)' res = calculator.main(arg) res = float(res) self.failUnlessEqual(res, 15)
def test_times(self): arg = '5*4' res = calculator.main(arg) res = float(res) self.failUnlessEqual(res, 20)
def testMinus(self): arg = '1-2' res = calculator.main(arg) res = float(res) self.failUnlessEqual(res, -1)
def test_input_two(self, stdout): main() self.assertEqual(stdout.getvalue(), '0\n')
def test_input_one(self, stdout): main() self.assertEqual(stdout.getvalue(), '9\n')
def test_invalid_operator(self): sys.argv = "scriptname 10 $ 2".split() result = calculator.main() self.assertEqual(result, 'invalid input')
def test_divide(self): sys.argv = "scriptname 10 / 2".split() result = calculator.main() self.assertEqual(result, 5)
def test_nested_parentheses(self): arg = '5*(2+(3*2))' res = calculator.main(arg) res = float(res) self.failUnlessEqual(res, 40)
def main(): """ Main module for all others, presents menus in loops for easy end-user accessibility and re-usability. :return: :rtype: """ # Try statement for catching errors try: # Continuous while loop that keeps the program going indefinitely while True: # Prints a long yellow line to separate sections of the menu my_tools.print_lines() # Program's banner, containing the name, version and date print( "\t\t\t\t\t\t\t", my_tools.PyColors.bold, my_tools.PyColors.Fg.light_yellow, " <<< Dashboard >>>", my_tools.PyColors.reset, "\n\n\t\t\t\t\t", my_tools.PyColors.Fg.light_green, " Project Version <|> Last Updated\n\t\t\t\t\t\t\t", " 0.0.5 12/05/2020", my_tools.PyColors.reset ) # Presents the user with a menu of options to choose from first_choice = input( "\n 1) General" "\n 2) Game of Chance" "\n 3) Release Notes" "\n 4) Quit" "\n\n Please select from one of the options listed above (1-4): " ).strip() # if first_choice == "1": while True: my_tools.print_lines() print( "\t\t\t\t\t\t\t\t ", my_tools.PyColors.bold, my_tools.PyColors.Fg.dark_green, "General Module", my_tools.PyColors.reset ) second_choice = input( "\n 1) Password Generator" "\n 2) Coin Flip" "\n 3) Random Number Generator" "\n 4) Calculator" "\n 5) Return To Main Menu" "\n\n Please select from one of the options listed above (1-5): " ).strip() # if second_choice == "1": password_generator.main() # elif second_choice == "2": coin_flip.main() # elif second_choice == "3": random_number.main() # elif second_choice == "4": calculator.main() # Returns the user to the main menu elif second_choice == "5": break # elif first_choice == "2": # while True: my_tools.print_lines() print( "\n\t\t\t ", my_tools.PyColors.Bg.light_blue, "Test 2 Module", my_tools.PyColors.reset ) second_choice = input( "\n 1) Test 1" "\n 2) Test 2" "\n 3) About Module" "\n 4) Return To Main Menu" "\n\n Please select from one of the options listed above (1-4): " ).strip() try: # if int(second_choice) in range(1, 3): # Test.Test(second_choice) pass # elif second_choice == "3": # Test.Test.about_module() pass # Returns to the previous menu elif second_choice == "4": break # Protects the program from erroneous data being entered except ValueError: continue # How to section on reporting any issues with this program elif first_choice == "3": my_tools.print_lines() print( "\n\t\t\t ", my_tools.PyColors.Bg.light_blue, "Version 0.0.0 Release Notes", my_tools.PyColors.reset, "\n\n New Features:" "\n" ) input("\n\n Press enter to continue...").strip() continue # Enables to user to exit the program without a keyboard interrupt elif first_choice == "4": print("\n\n ...Exiting program\n\n") sys.exit(0) # Gracefully ends the program when the user hits the 'control + c' keys except KeyboardInterrupt: print("\n\n ...Exiting program\n\n") sys.exit(0)
def test_multiple_parentheses(self): arg = '(3+5)*(1+2)' res = calculator.main(arg) res = float(res) self.failUnlessEqual(res, 24)
def test__3(self): #fractional case expected = -1.9 actual = calculator.main('3.0+4.5*0.2-5.8') self.assertEqual(expected, actual)
__author__ = "Caffe" import calculator arguments = calculator.parse_arguments() calculator.main(arguments)
def test__5(self): #invalid syntax case with self.assertRaisesRegex(Exception, 'Invalid syntax'): calculator.main('2+3/')
def test_subtract(self): sys.argv = "scriptname 10 - 2".split() result = calculator.main() self.assertEqual(result, 8)
def test__7(self): #invalid character case # with self.assertRaises(Exception): with self.assertRaisesRegex(Exception, 'Invalid syntax'): calculator.main('3+4-/5+1')
def test_divide(self): sys.argv = "scriptname 10 / 2".split() result = calculator.main() self.assertEqual(result, 5)
def test__1(self): #normal case expected = -2 actual = calculator.main('3-4/2*3+1') self.assertEqual(expected, actual)
def test_subtract(self): sys.argv = "scriptname 10 - 2".split() result = calculator.main() self.assertEqual(result, 8)
def test_tons_of_stuff(self): arg = '(5*(2+4)-9*5*2*(-1))+10' res = calculator.main(arg) res = float(res) self.failUnlessEqual(res, 130)
# -*- encoding: utf-8 -*- import calculator if __name__ == '__main__': calculator.main()
def test_add(self): sys.argv = "scriptname 2 + 3".split() result = calculator.main() self.assertEqual(result, 5)
def testPlus(self): arg = '1+2' res = calculator.main(arg) res = float(res) self.failUnlessEqual(res, 3)
def test_multiply(self): sys.argv = "scriptname 10 x 2".split() result = calculator.main() self.assertEqual(result, 20)
def calculator_app(): calculator.main()
def test_invalid_operator(self): sys.argv = "scriptname 10 $ 2".split() result = calculator.main() self.assertEqual(result, 'invalid input')
def test_add(self): sys.argv = "scriptname 2 + 3".split() result = calculator.main() self.assertEqual(result, 5)