Esempio n. 1
0
 def do_evaluate(self, s):
     """Jarvis will get your calculations done!"""
     tempt = s.replace(" ", "")
     if len(tempt) > 1:
         evaluator.calc(tempt, self)
     else:
         print_say("Error: Not in correct format", self, Fore.RED)
Esempio n. 2
0
 def do_evaluate(self, s):
     """Jarvis will get your calculations done!"""
     tempt = s.split(" ", 1) or ""
     if len(tempt) > 1:
         evaluator.calc(tempt[1])
     else:
         print(Fore.RED + "Error: Not in correct format" + Fore.RESET)
Esempio n. 3
0
    def test_calc(self):
        # Test a basic calculation
        calc("2 powER 7 PLUS (6.7 Minus 3) diVided BY 0.45 bY 3", self.jarvis)
        sys.stdout.seek(0)
        output = sys.stdout.read().strip()
        result = Fore.BLUE + str(2 ** 7 + (6.7 - 3) / 0.45 / 3) + Fore.RESET
        self.assertEqual(output, result)

        # And now for something a little more _complex_
        sys.stdout = StringIO()
        x = calc("(1 pluS 9.1j)^3.14129 mINUS 2.712", self.jarvis)
        sys.stdout.seek(0)
        output = sys.stdout.read().strip()
        result = Fore.BLUE + str((1+9.1j)**3.14129 - 2.712) + Fore.RESET
        self.assertEqual(output, result)