Ejemplo n.º 1
0
 def test_calculator_2(self):
     cal = Calculator()
     out = StringIO()
     with patch("sys.stdout", out) as fakeOutput:
         cal.calculate()
     output = fakeOutput.getvalue().strip()
     self.assertEqual(output, "n and p should be non-negative")
Ejemplo n.º 2
0
def displayCalculator():
    test = Calculator()
    test.welcome()
    test.calculate()
    test.history()
    test.viewHistory()
    test.clearHistory()
Ejemplo n.º 3
0
 def test_calculator_1(self):
     cal = Calculator()
     out = StringIO()
     with patch("sys.stdout", out) as fakeOutput:
         cal.calculate()
     output = fakeOutput.getvalue().strip()
     self.assertEqual(output, "81")
 def test_calculator_2(self):
     cal = Calculator()
     out = StringIO()
     with patch("sys.stdout", out) as fakeOutput:
         cal.calculate()
     output = fakeOutput.getvalue().strip()
     self.assertEqual(output, "n and p should be non-negative")
 def test_calculator_1(self):
     cal = Calculator()
     out = StringIO()
     with patch("sys.stdout", out) as fakeOutput:
         cal.calculate()
     output = fakeOutput.getvalue().strip()
     self.assertEqual(output, "81")
Ejemplo n.º 6
0
class Terminal:
    """
    A terminal for the Calculator class
    """
    def __init__(self):
        self._input = ""
        self._calc = Calculator()

    def main(self):
        while True:
            self._input = input("> ").lower()

            if self._input == "exit":
                break

            if not self._calc.is_valid_expression(self._input):
                print("Invalid input")

            else:
                try:
                    if self._input == "store":
                        self._calc.store()
                        print("Stored", self._calc.recall())

                    elif self._input == "recall":
                        print("Recalled", self._calc.recall())
                        print("> ", self._calc.recall(), sep="", end="")
                        self._input = ""  # clear input
                        self._input = str(self._calc.recall()) + input().lower(
                        )  # attach recall value, then user input

                        if not self._calc.is_valid_expression(self._input):
                            print("Invalid input")
                            continue

                        print(self._input, "=",
                              self._calc.calculate(self._input))

                    elif self._input == "clear":
                        self._calc.clear()
                        print("Cleared")

                    elif self._input == "help":
                        self._calc.help()

                    else:
                        print(self._input, "=",
                              self._calc.calculate(self._input))

                except (ZeroDivisionError, ValueError) as e:
                    print(e)
Ejemplo n.º 7
0
def main(argv=None):
	people = [
		Person("Person 1",500),
		Person("Person 2",1000),
		Person("Person 3",1500),
	]
	
	calc = Calculator()
	calc.people = people
	calc.charge = 42.95
	calc.calculate()
	
	print "Total income including all parties: ${0:03.2f}".format(calc.total_income)
	
	for p in calc.people:
		print "Amount due by {0} whose income is ${1:03.2f} is ${2:03.2f}.".format(p.name,p.income,p.due)
	
	print "Each party is paying ${0:03.2f}% of their income.".format(calc.due_percent)
Ejemplo n.º 8
0
def main(argv=None):
    people = [
        Person("Person 1", 500),
        Person("Person 2", 1000),
        Person("Person 3", 1500),
    ]

    calc = Calculator()
    calc.people = people
    calc.charge = 42.95
    calc.calculate()

    print "Total income including all parties: ${0:03.2f}".format(
        calc.total_income)

    for p in calc.people:
        print "Amount due by {0} whose income is ${1:03.2f} is ${2:03.2f}.".format(
            p.name, p.income, p.due)

    print "Each party is paying ${0:03.2f}% of their income.".format(
        calc.due_percent)
Ejemplo n.º 9
0
	def __switch_page_cb(self,assistant,page):
		if page == self.asnt_p1:
			pass
		elif page == self.asnt_p2:
			pass
		elif page == self.asnt_p3:
			charge = float(self.bill_entry.get_text())
			
			calc_people = []
			for person in self.people:
				calc_people.append(Person(person[0],person[1]))
			
			calc = Calculator()
			calc.people = calc_people
			calc.charge = charge
			calc.calculate()
			
			str = ""
			
			
			str+= "Total income including all parties: ${0:03.2f}\n\n".format(calc.total_income)
			
			for p in calc.people:
				str+= "Amount due by {0} whose income is ${1:03.2f} is ${2:03.2f}.\n".format(p.name,p.income,p.due)
			
			str+= "\nEach party is paying {0:03.2f}% of their income.".format(calc.due_percent)
			
			
			
			
			
			
			
			
			buf = self.res_tv.get_buffer()
			buf.set_text(str)
		
		print "__change_page_cb",page
 def testCalculatorReturnsCorrectResult(self):
     calculator = Calculator()
     result = calculator.calculate(1000, 1.3, 100)
     self.assertEqual(result, 3.561643835616439)
Ejemplo n.º 11
0
from Calculator import Calculator
if __name__ == "__main__":
	calc = Calculator()
	result = calc.calculate("10/4*2*3-15")
	print(result)
Ejemplo n.º 12
0
class CalculatorRESTServer:
    # All five basic operators available by default

    def __init__(self,
                 port_no,
                 valid_operators={'+', '-', '*', '/', '^'},
                 domain="localhost",
                 main_server_url='http://*****:*****@self.server.route('/api/info', methods=['GET'])
        def getinfo():
            return "Domain:{2} Port: {0} Valid operators: {1}".format(
                self.port_no, self.valid_operators, self.domain)

    @self.server.route('/api/port', methods=['GET'])
    def get_port(self):
        return self.port_no

    @self.server.route('/api/calculate', methods=['GET'])
    def calculate(self, x, y, operator):
        print("Server {0} is asked to calculate {1} and {2} with operator {3}".
              format(self.address, x, y, operator))
        if operator in self.valid_operators:
            # print("Calling calculation method.")
            return self.calculator.calculate(x, y, operator)
        else:
            return "Could not calculate {0} and {1} with operator {2}".format(
                x, y, operator)

    def start(self):
        self.server_thread.start()
        print("Started {0} ({1})".format(self.address, self.valid_operators))
        self.register_with_main()

    def register_with_main(self):
        # Set up as child to main server if not main server
        if self.main_server_url != "{0}:{1}".format(self.domain, self.port_no):
            # Register each operator:
            for operator in self.valid_operators:
                if not self.rpc_main_client.register_child_server(
                        self.address, operator):
                    print("Server {0} could not register operator {1}.".format(
                        self.address, operator))
Ejemplo n.º 13
0
def print_status():
    print(n)
    timer = Timer(60, print_status)
    timer.start()

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("first", help="first number in sequence", type=int)
    parser.add_argument("last", help="last number in sequence", type=int)
    parser.add_argument("--hidechains", help="don't print the full path from each number to 1", dest='print_chains', action='store_false')
    parser.add_argument("--showchains", help="print the full path from each number to 1", dest='print_chains', action='store_true')
    args = parser.parse_args()   
    
    collector = Collector()
    calculator = Calculator(collector, args.print_chains)
    
    n = 0
    
    if not args.print_chains:
        print_status()
    
    for n in range(args.first, args.last):
        #print('{}: {}'.format(n, calculator.calculate(n)))
        chain = calculator.calculate(n)
        if args.print_chains:
            print('{}'.format(chain))
    
    # if we made it this far, the range must be valid
    print('it looks like the conjecture holds for the range from {} to {}.'.format(args.first, args.last))
    timer.cancel()
Ejemplo n.º 14
0
contents = []
while True:
  try:
      line = input()
  except EOFError:
      break
  contents.append(line)





inputArray = contents
tokenizer = Tokenizer(inputArray)

print("Results")
print(tokenizer.getTestResult())
print("Input")
print(tokenizer.getTestInput())
print("iterationlimit")
print(tokenizer.getIterlimit())
print("iteratoramount")
print(tokenizer.getIterator())
print("fixed modifier")
print(tokenizer.getFixed())


calculator = Calculator(tokenizer)
calculator.calculate()